Debug School

Cover image for minikube
Suyash Sambhare
Suyash Sambhare

Posted on • Updated on

minikube

minikube is local Kubernetes, aiming on making it simple to learn and develop for Kubernetes.
minikube rapidly sets up a local Kubernetes cluster on macOS, Linux, and Windows.

  • Provide for the latest Kubernetes distribution (+6 previous minor versions)
  • Cross-platform (Linux, macOS, Windows)
  • Install as a VM, a container, or on bare-metal
  • Several container runtimes (CRI-O, containerd, docker)
  • Direct API endpoint for raging-fast image load and build
  • Enhanced characteristics such as LoadBalancer, filesystem mounts, FeatureGates, and network policy
  • Extras for effortlessly installed Kubernetes applications
  • Maintains common CI environments

All you require is a Docker or likewise corresponding container or a Virtual Machine environment, and Kubernetes is 1 command away: minikube start

Conditions

  • 2+ CPUs
  • 2GB+ RAM
  • 20GB+ HDD
  • 200+ GB/s Internet
  • Container or virtual machine manager, such as Docker, QEMU, Hyperkit, Hyper-V, KVM, Parallels, Podman, VirtualBox, or VMware Fusion/Workstation

Installation

Windows

To install the latest minikube stable release on x86-64 Windows using .exe download:
Download and run the installer for the latest release. - https://storage.googleapis.com/minikube/releases/latest/minikube-installer.exe

Or if using PowerShell, use this command:

New-Item -Path 'c:\' -Name 'minikube' -ItemType Directory -Force
Invoke-WebRequest -OutFile 'c:\minikube\minikube.exe' -Uri 'https://github.com/kubernetes/minikube/releases/latest/download/minikube-windows-amd64.exe' -UseBasicParsing
Enter fullscreen mode Exit fullscreen mode

Add the minikube.exe binary to your PATH.
Make sure to run PowerShell as Administrator.

$oldPath = [Environment]::GetEnvironmentVariable('Path', [EnvironmentVariableTarget]::Machine)
if ($oldPath.Split(';') -inotcontains 'C:\minikube'){
  [Environment]::SetEnvironmentVariable('Path', $('{0};C:\minikube' -f $oldPath), [EnvironmentVariableTarget]::Machine)
}
Enter fullscreen mode Exit fullscreen mode

If you used a terminal like PowerShell for the installation, please close the terminal and reopen it before running minikube.

Linux

To install the latest minikube stable release on x86-64 Linux using binary download:
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube

To install the latest minikube stable release on x86-64 Linux using RPM package:
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-latest.x86_64.rpm
sudo rpm -Uvh minikube-latest.x86_64.rpm

Start the cluster

From a terminal with administrator access (but not logged in as root), run: minikube start
If minikube fails to start, see the drivers page for help setting up a compatible container or virtual-machine manager.

Install kubectl

The Kubernetes command-line tool, kubectl, allows you to run commands against Kubernetes clusters. You can use kubectl to deploy applications, inspect and manage cluster resources, and view logs.
kubectl is installable on a variety of Linux platforms, macOS and Windows.
You must use a kubectl version that is within one minor version difference of your cluster. For example, a v1.29 client can communicate with v1.28, v1.29, and v1.30 control planes. Using the latest compatible version of kubectl helps avoid unforeseen issues.

Install kubectl binary with curl on Windows

Download the latest 1.29 patch release: kubectl 1.29.0
Or if you have curl installed, use this command:
curl.exe -LO "https://dl.k8s.io/release/v1.29.0/bin/windows/amd64/kubectl.exe"
In case you want to use the latest value, you can point to the file https://dl.k8s.io/release/stable.txt.

Validate the binary
Download the kubectl checksum file: curl.exe -LO "https://dl.k8s.io/v1.29.0/bin/windows/amd64/kubectl.exe.sha256"
Validate the kubectl binary against the checksum file
Using Command Prompt to manually compare CertUtil's output to the checksum file downloaded

CertUtil -hashfile kubectl.exe SHA256
type kubectl.exe.sha256

Test to ensure the version of kubectl is the same as download:
kubectl version --client

Or use this for a detailed view of the version:
kubectl version --client --output=yaml
Note: Docker Desktop for Windows adds its version of kubectl to PATH. If you have installed Docker Desktop before, you may need to place your PATH entry before the one added by the Docker Desktop installer or remove the Docker Desktop's kubectl.

Install on Windows using Winget

To install kubectl on Windows you can use either Chocolatey package manager, Scoop command-line installer, or Winget package manager.
winget install -e --id Kubernetes.kubectl

Test to ensure the version you installed is up-to-date:
kubectl version --client

Navigate to your home directory:
If you're using cmd.exe, run: cd %USERPROFILE%
cd ~

Create the .kube directory:
mkdir .kube

Change to the .kube directory you just created:
cd .kube

Configure kubectl to use a remote Kubernetes cluster:
New-Item config -type file

Edit the config file with a text editor of your choice, such as Notepad.

Install kubectl binary with curl on Linux

Download the latest release with the command:
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"

Validate the binary:
echo "$(cat kubectl.sha256) kubectl" | sha256sum --check

Install kubectl
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl

Test to ensure the version you installed is up-to-date:
kubectl version --client

Or use this for a detailed view of the version:
kubectl version --client --output=yaml

Enable shell autocompletion

kubectl provides autocompletion support for Bash, Zsh, Fish, and PowerShell, which can save you a lot of typing.
Below are the procedures to set up autocompletion for PowerShell.
The kubectl completion script for PowerShell can be generated with the command kubectl completion powershell.
To do so in all your shell sessions, add the following line to your $PROFILE file:
kubectl completion powershell | Out-String | Invoke-Expression

This command will regenerate the auto-completion script on every PowerShell start-up. You can also add the generated script directly to your $PROFILE file.
To add the generated script to your $PROFILE file, run the following line in your PowerShell prompt:
kubectl completion powershell >> $PROFILE

After reloading your shell, kubectl auto-completion should be working.

MiniKube

Work on your cluster

If you already have kubectl installed, you can now use it to access your shiny new cluster:
kubectl get po -A

Alternatively, minikube can download the appropriate version of kubectl and you should be able to use it like this:
minikube kubectl -- get po -A

You can also make your life easier by adding the following to your shell config:
alias kubectl="minikube kubectl --"

Initially, some services such as the storage-provisioner, may not yet be Running. This is a normal condition during cluster bring-up and will resolve itself momentarily. For additional insight into your cluster state, minikube bundles the Kubernetes Dashboard, allowing you to get easily acclimated to your new environment:
minikube dashboard

Deploy applications

Service

Create a sample deployment and expose it on port 8080
kubectl create deployment hello-minikube --image=kicbase/echo-server:1.0
kubectl expose deployment hello-minikube --type=NodePort --port=8080

It may take a moment, but your deployment will soon show up when you run:
kubectl get services hello-minikube

The easiest way to access this service is to let minikube launch a web browser for you:
minikube service hello-minikube

Alternatively, use kubectl to forward the port:
kubectl port-forward service/hello-minikube 7080:8080

Hooray!! Your application is now available at http://localhost:7080/.
You should be able to see the request metadata in the application output. Try changing the path of the request and observe the changes. Similarly, you can do a POST request and observe the body show up in the output.

Loadbalancer

To access a LoadBalancer deployment, use the minikube tunnel command.
kubectl create deployment balanced --image=kicbase/echo-server:1.0
kubectl expose deployment balanced --type=LoadBalancer --port=8080

In another window, start the tunnel to create a routable IP for the balanced deployment:
minikube tunnel

To find the routable IP, run this command and examine the EXTERNAL-IP column:
kubectl get services balanced
Your deployment is now available at <EXTERNAL-IP>:8080

Ingress

Enable ingress addon
minikube addons enable ingress

The following example creates simple echo-server services and an Ingress object to route to these services.

kind: Pod
apiVersion: v1
metadata:
  name: foo-app
  labels:
    app: foo
spec:
  containers:
    - name: foo-app
      image: 'kicbase/echo-server:1.0'
---
kind: Service
apiVersion: v1
metadata:
  name: foo-service
spec:
  selector:
    app: foo
  ports:
    - port: 8080
---
kind: Pod
apiVersion: v1
metadata:
  name: bar-app
  labels:
    app: bar
spec:
  containers:
    - name: bar-app
      image: 'kicbase/echo-server:1.0'
---
kind: Service
apiVersion: v1
metadata:
  name: bar-service
spec:
  selector:
    app: bar
  ports:
    - port: 8080
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: example-ingress
spec:
  rules:
    - http:
        paths:
          - pathType: Prefix
            path: /foo
            backend:
              service:
                name: foo-service
                port:
                  number: 8080
          - pathType: Prefix
            path: /bar
            backend:
              service:
                name: bar-service
                port:
                  number: 8080
---
Enter fullscreen mode Exit fullscreen mode

Apply the contents
kubectl apply -f https://storage.googleapis.com/minikube-site-examples/ingress-example.yaml
Wait for the ingress address

kubectl get ingress
NAME              CLASS   HOSTS   ADDRESS          PORTS   AGE
example-ingress   nginx   *       <your_ip_here>   80      5m45s
Enter fullscreen mode Exit fullscreen mode

To get ingress to work you’ll need to open a new terminal window and run the minikube tunnel and in the following step use 127.0.0.1 in place of <ip_from_above>.
Now verify that the ingress works

$ curl <ip_from_above>/foo
Request served by foo-app
...

$ curl <ip_from_above>/bar
Request served by bar-app
...
Enter fullscreen mode Exit fullscreen mode

Manage your cluster

  • Pause Kubernetes without impacting deployed applications: minikube pause
  • Unpause a paused instance: minikube unpause
  • Halt the cluster: minikube stop
  • Change the default memory limit (requires a restart): minikube config set memory 9001
  • Browse the catalog of easily installed Kubernetes services: minikube addons list
  • Create a second cluster running an older Kubernetes release: minikube start -p aged --kubernetes-version=v1.16.1
  • Delete all of the minikube clusters: minikube delete --all

Ref: https://minikube.sigs.k8s.io/docs/start/
Ref: https://kubernetes.io/docs/tasks/tools/

Top comments (0)