It’s been a while since I started playing with AKS for my book - I’ve used various container solutions in the past, but not spent a whole lot of time with Kubernetes. In this post, I’ll be talking through a local Kubernetes setup, and discussing what you can try out locally, and how that works.
Set-up
Before starting, you’ll need to install a few things locally. I’m running on a Windows machine, but I’m fairly sure the exact same set-up would be required on a Mac.
Docker Desktop
The first thing that you’ll need locally is Docker Desktop. This will allow you to run docker containers on your local machine.
MiniKube
MiniKube allows you to run a Kubernetes cluster locally.
KubeCtl
To interact with Kubernetes, you’ll need to use KubeCtl - pronounced, for reasons I’ve never quite mastered, “Kube Cuddle”.
Start MiniKube
Once you’re set-up and installed, launch a Powershell shell as admin, and start the cluster:
minikube start
You can now look at the nodes in your cluster:
kubectl get nodes
And you’ll see the nodes that you’re currently running (on your local machine):
NAME STATUS ROLES AGE VERSION
minikube Ready control-plane 10m v1.31.0
You can also see the pods that are running:
kubectl get pods -A
This lists the running pods across all namespaces:
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system coredns-6f6b679f8f-d89ql 1/1 Running 0 11m
kube-system etcd-minikube 1/1 Running 0 11m
kube-system kube-apiserver-minikube 1/1 Running 0 11m
kube-system kube-controller-manager-minikube 1/1 Running 0 11m
kube-system kube-proxy-cvkmk 1/1 Running 0 11m
kube-system kube-scheduler-minikube 1/1 Running 0 11m
kube-system storage-provisioner 1/1 Running 1 (10m ago) 11m
As a very coarse rule of thumb, a pod is equatable to a container - that’s not strictly true, but it’s broadly and usually true.
Deploy to the Cluster
If you visit the Kubernetes site, you’ll see an example for setting up nginx.
Create a file somewhere and call it deployment.yaml
and copy the script from the above site.
Then apply the script:
kubectl apply -f deployment.yaml
Obviously, run this in the same directory as the file you’ve created, or give it the path. If you now run get pods
again, you’ll see that Kubernetes has created three new containers, as defined in the script.
That’s it - you now have a Kubernetes cluster running locally on your machine.
Conclusion
This is great for trying new things with Kubernetes without the risk or cost of resorting to a cloud service.
References
https://kubernetes.io/docs/concepts/workloads/controllers/deployment/
https://www.docker.com/products/docker-desktop
https://minikube.sigs.k8s.io/docs/start/?arch=%2Fwindows%2Fx86-64%2Fstable%2F.exe+download
https://kubernetes.io/docs/tasks/tools/install-kubectl-windows#install-nonstandard-package-tools