Minikube allows you to run a self contained, single node, Kubernetes cluster on your workstation. Once installed and configured, you may use kubectl to interact with it, just like a production Kubernetes cluster.
curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/darwin/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin
Supported hypervisors: virtualbox, vmwarefusion, kvm, xhyve
minikube start --vm-driver=virtualbox
If this is your first time starting minikube, it will perform the following:
Starting local Kubernetes cluster... Starting VM... Downloading Minikube ISO 89.24 MB / 89.24 MB [==============================================] 100.00% 0s SSH-ing files into VM... Setting up certs... Starting cluster components... Connecting to cluster... Setting up kubeconfig... Kubectl is now configured to use the cluster
Also, you should see a new VM running in VirtualBox, like this:
To verify that kubectl is configured to use minikube look at the config file (~/.kube/config).
Also try running:
- kubectl get nodes
- kubectl get services
You can also connect to the VirtualBox guest using SSH to have a look around. In my case the Minikube VM was assigned 192.168.99.100.
ssh -i ~/.minikube/machines/minikube/id_rsa firstname.lastname@example.org
You can see all the containers running with:
docker ps ps aux
Exit out, you really don't need to interact at this level
Instead we will treat Minikube as a "real" Kubernetes cluster and only use the kubectl tool.
In this example we create an echoserver cluster.
kubectl run hello-minikube --image=gcr.io/google_containers/echoserver:1.4 --port=8080
this command will create -
kubectl get deployments
kubectl get replicasets
kubectl get pods
To make the echoserver accessible externally, you need to expose the deployment, like this:
kubectl expose deployment hello-minikube --type=NodePort
The expose command creates -
kubectl get services NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes 10.0.0.1 <none> 443/TCP 2d hello-minikube 10.0.0.225 <nodes> 8080:31136/TCP 58m
To access the service, you connect to the Minikube's IP address on the exposed port.
In my case the Minikube VirtualBox IP is 192.168.99.100 and the exposed port is 31136 as listed above.
The minikube tool has a shortcut for this info, try:
minikube service hello-minikube --url http://192.168.99.100:31136
Toss this into a web browser on your local machine and it should echo back!
scale up the hello-minikube pod to 3:
kubectl scale deployment hello-minikube --replicas=3
kubectl get deployments kubectl get pods
trash this demo (delete the deployment, replicaset, pods, and service):
kubectl delete deployment hello-minikube