Minikube Local K8s

Minikube cheatsheet — start local Kubernetes, enable addons, expose services. minikube start, minikube dashboard, minikube tunnel, minikube addons enable ingress. Full reference.

6 min read

What it is

Minikube is a tool that runs a single-node Kubernetes cluster inside a virtual machine on your local machine, allowing you to develop and test Kubernetes applications locally.

Installation

Linux

curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube
rm minikube-linux-amd64

macOS

curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-darwin-amd64
sudo install minikube-darwin-amd64 /usr/local/bin/minikube
rm minikube-darwin-amd64

Homebrew:

brew install minikube

Windows

Download the appropriate binary from the Minikube releases page. Alternatively, use Chocolatey:

choco install minikube

Docker (as driver)

Ensure Docker is installed and running. Minikube can use Docker as its driver, which is often faster than a full VM.

Core Concepts

  • Node: Minikube runs a single-node Kubernetes cluster. This node is essentially a virtual machine.
  • Driver: The underlying technology used to run the Kubernetes node. Common drivers include Docker, VirtualBox, KVM, and Hyper-V. The Docker driver is often the fastest.
  • Addons: Pre-configured Kubernetes components that can be enabled to extend cluster functionality (e.g., dashboard, ingress).

Commands / Usage

Starting and Stopping Minikube

  • Start a cluster:

    minikube start
    

    Starts a Kubernetes cluster using the default driver.

    minikube start --driver=docker
    

    Starts a Kubernetes cluster using the Docker driver.

    minikube start --kubernetes-version=v1.28.0
    

    Starts a cluster with a specific Kubernetes version.

    minikube start --nodes 3 --driver=docker
    

    Starts a multi-node cluster (experimental, requires specific drivers and versions).

  • Stop the cluster:

    minikube stop
    

    Stops the Minikube VM without deleting its contents.

  • Delete the cluster:

    minikube delete
    

    Stops and deletes the Minikube VM and all its data.

  • Pause the cluster:

    minikube pause
    

    Pauses the Minikube VM.

  • Unpause the cluster:

    minikube unpause
    

    Resumes a paused Minikube VM.

  • SSH into the node:

    minikube ssh
    

    Opens an SSH session to the Minikube VM.

Cluster Information and Status

  • Check status:

    minikube status
    

    Shows the status of the Minikube node and Kubernetes.

  • Get cluster info:

    minikube cluster-info
    

    Prints the Kubernetes master endpoint.

  • Get Kubernetes version:

    minikube version
    

    Prints the Minikube version.

  • Get node IP:

    minikube ip
    

    Prints the IP address of the Minikube node.

Managing Addons

  • List available addons:

    minikube addons list
    

    Lists all available addons and their status.

  • Enable an addon:

    minikube addons enable dashboard
    

    Enables the Kubernetes dashboard addon.

  • Disable an addon:

    minikube addons disable ingress
    

    Disables the ingress addon.

  • Check addon status:

    minikube addons status
    

    Shows the status of all enabled addons.

Accessing Services and Applications

  • Open the Kubernetes dashboard:

    minikube dashboard
    

    Opens the Kubernetes dashboard in your default web browser.

  • Get the URL for a service:

    minikube service <service-name> --url
    

    Gets the URL for a specific Kubernetes service.

    minikube service my-app-service --url -n default
    

    Gets the URL for my-app-service in the default namespace.

  • Open a service in the browser:

    minikube service my-app-service
    

    Opens a specific Kubernetes service in your default web browser.

Container Management

  • Load a Docker image into Minikube:

    eval $(minikube docker-env)
    docker build -t my-custom-image .
    

    Builds an image using the Minikube Docker daemon, making it available within the Minikube cluster.

  • Get Docker environment variables:

    minikube docker-env
    

    Outputs shell commands to set environment variables so your local Docker client can connect to Minikube’s Docker daemon.

    eval $(minikube docker-env)
    

    Executes the output of minikube docker-env to configure your shell.

Configuration and Settings

  • Set Minikube configuration:

    minikube config set memory 4096
    

    Sets the memory allocated to the Minikube VM to 4096MB.

    minikube config set cpus 4
    

    Sets the number of CPUs for the Minikube VM to 4.

  • Get Minikube configuration:

    minikube config get memory
    

    Retrieves the current memory setting for Minikube.

  • Unset Minikube configuration:

    minikube config unset memory
    

    Resets the memory setting to its default.

Other Useful Commands

  • Update Minikube:

    minikube update-context
    

    Updates the kubectl context to point to the Minikube cluster.

  • Get logs:

    minikube logs
    

    Shows the logs from the Minikube node.

  • Mount a directory:

    minikube mount /local/path:/remote/path
    

    Mounts a local directory into the Minikube VM.

  • Start a tunnel:

    minikube tunnel
    

    Starts a network tunnel to allow access to services of type LoadBalancer.

Common Patterns

  • Building and deploying an image:

    eval $(minikube docker-env)
    docker build -t my-web-app:latest .
    kubectl create deployment my-web-app --image=my-web-app:latest
    kubectl expose deployment my-web-app --type=NodePort --port=80
    minikube service my-web-app
    

    Builds a Docker image using Minikube’s daemon, deploys it to Kubernetes, exposes it as a NodePort service, and opens it in the browser.

  • Using Ingress: First, ensure the ingress addon is enabled:

    minikube addons enable ingress
    

    Then, create an Ingress resource:

    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      name: my-ingress
    spec:
      rules:
      - host: myapp.local
        http:
          paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: my-app-service
                port:
                  number: 80
    

    Apply the Ingress:

    kubectl apply -f ingress.yaml
    

    Add an entry to your hosts file (/etc/hosts on Linux/macOS, C:\Windows\System32\drivers\etc\hosts on Windows):

    192.168.49.100 myapp.local
    

    (Replace 192.168.49.100 with minikube ip) Then access http://myapp.local in your browser.

  • Accessing a LoadBalancer service: Create a service of type LoadBalancer:

    apiVersion: v1
    kind: Service
    metadata:
      name: my-lb-service
    spec:
      selector:
        app: my-app
      ports:
        - protocol: TCP
          port: 80
          targetPort: 8080
      type: LoadBalancer
    

    Apply the service:

    kubectl apply -f service-lb.yaml
    

    Start the tunnel:

    minikube tunnel
    

    The tunnel will allocate an IP address for the LoadBalancer service, which you can then access.

Gotchas

  • Docker driver vs. VM driver: The Docker driver is generally faster and uses fewer resources than VM-based drivers (like VirtualBox). However, it requires Docker to be running and configured.
  • Resource allocation: If you experience slow performance, try increasing the memory and CPU allocated to Minikube using minikube config set memory <MB> and minikube config set cpus <count>. Remember to restart Minikube after changing these settings.
  • eval $(minikube docker-env): This command is crucial for using Minikube’s Docker daemon. If you forget to run it, docker build will use your local Docker daemon, and the image won’t be available inside Minikube. It only affects your current shell session.
  • Kubernetes version compatibility: Ensure your local kubectl version is compatible with the Kubernetes version running in Minikube. Minikube usually handles this well, but it’s good to be aware of.
  • Network access for LoadBalancer services: Services of type LoadBalancer typically require minikube tunnel to be running to get an external IP. Without the tunnel, the service might remain in a pending state.
  • Clearing state: If you encounter persistent issues, minikube delete followed by minikube start is often the quickest way to get a clean slate.