Sub topic 4
Creating a Cluster with minikube
This chapter assumes you have a container runtime such as Docker installed and that you can read basic kubectl output. You should also know what a node and a context are, at a high level. The previous chapter created a cluster with kind. Here you create one with minikube.
What minikube does
minikube starts a single-node Kubernetes cluster on your machine. It supports several drivers, which are the back ends that provide the node. The docker driver runs the node as a container. Other drivers run it as a virtual machine, for example with VirtualBox, KVM, Hyper-V or QEMU. If you don't pass a driver, minikube picks one that it finds on your system.
Create a cluster
A profile is a named cluster. The -p flag selects the profile, and it also becomes the kubectl context name.
minikube start -p dev
kubectl config get-contexts
kubectl get nodesminikube start downloads the Kubernetes images on first use, creates the node, and writes a context named dev into your kubeconfig. It also switches your current context to dev. The node name in kubectl get nodes is dev, and its status should be Ready.
To choose the driver yourself, add the --driver flag:
minikube start -p dev --driver=dockerWhat happens during start
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| `Exiting due to PROVIDER_DOCKER_NOT_RUNNING` | The Docker daemon is not running | Start Docker, then run `minikube start -p dev` again |
| Start hangs or times out on first run | Slow image download or too little memory | Check your network and give the container runtime more memory |
| `kubectl` talks to the wrong cluster | A different context is active | Run `kubectl config current-context` and switch with `kubectl config use-context dev` |
| Driver mismatch error on restart | The profile was created with another driver | Delete the profile and recreate it |
Compared with kind
Both tools produce a working cluster and a kubectl context. The kind context is named kind-<name>, while the minikube context is named after the profile. minikube also offers addons and VM-based drivers, which later chapters cover.
Exercise
You ran minikube start -p dev and then kubectl get nodes shows a node. What is the name of the kubectl context that minikube created, and how can you confirm that it is the active one?
Show answer
The context is named dev, the same as the profile. Run kubectl config current-context, which should print dev. kubectl config get-contexts also marks the active context with an asterisk.
Exercise
You started a profile with the default driver and now want to use --driver=docker instead. What must you do?
Show answer
The driver cannot be changed on an existing profile. Delete it with minikube delete -p dev, then run minikube start -p dev --driver=docker.