Hello,
After reading this article https://www.infoq.com/news/2022/03/lyft-cloud-local-dev/ I became curious of exploring development with local kubernetes. Until now I was proponent of using production grade kubernets like GKE or EKS. The idea being to be the closer possible from production. But it has some drawbacks:
- it is not free
- it is frustrating to spend time with credentials issues
- it takes significant time to create and destroy a cluster each time you want to play with kubernetes
So in this article I will give all the commands to execute in order to create a kubernetes cluster on local machine.
The cluster will be created with KIND (https://kind.sigs.k8s.io/) but there are other options like minikube or k3d. It is easy to change, it is just a parameter of ctlptl command (for example ctlptl create cluster k3d --registry=ctlptl-registry instead of
ctlptl create cluster kind --registry=ctlptl-registry
). To explain better, KIND is not used directly but through ctlptl which make it easier.
At first, I highly suggest to do it in a fresh installed VM. I did it with an Ubuntu 18.04.6 running on VirtualBox (can be downloaded here https://www.osboxes.org/ubuntu/)
Note:
During installation you may encounter an error about locking on dpkg frontend (it is an issue with the osboxes vm). To fix:
sudo rm /var/lib/apt/lists/lock
sudo rm /var/cache/apt/archives/lock
sudo rm /var/lib/dpkg/lock*
sudo dpkg --configure -a
Details here: https://askubuntu.com/questions/1109982/e-could-not-get-lock-var-lib-dpkg-lock-frontend-open-11-resource-temporari
1) Docker installation
sudo apt-get update
sudo apt-get install \
ca-certificates \
curl \
gnupg \
lsb-release
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
Details here: https://docs.docker.com/engine/install/ubuntu/
Check it is working: sudo docker run hello-world
2) Setup docker as a non-root user (optional)
sudo usermod -aG docker $USER
Restart the VM
Check it is working: docker run hello-world
Details here: https://docs.docker.com/engine/install/linux-postinstall/
3) Install kubectl
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
Details here: https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/
4) Install brew
Brew will be used to install kind and ctlptl
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Remark: after the installation of brew there are a few commands to run (3 at the time of writing). just follow what is displayed in the console.
Details here: https://brew.sh
5) Install kind
In order for ctlptl to create a cluster through KIND it is necessary to install the kind executable
brew install tilt-dev/tap/ctlptl
Details here: https://github.com/tilt-dev/ctlptl
6) Create the cluster
And now that all the preparation steps are done we can create the cluster and its registry.
ctlptl create registry ctlptl-registry --port=5005
ctlptl create cluster kind --registry=ctlptl-registry
It will take some time. After it is finished verify it is working:
kubectl get pods
And that's it. Now a kubernetes cluster is created and you can play with it ;-)
Next Steps
Why not create a pod and log to it?
kubectl run my-shell --rm -i --tty --image ubuntu -- bash
Or create an ingress with Kong gateway?
https://docs.konghq.com/gateway/2.8.x/install-and-run/kubernetes/
Or try Tilt (which was the reason I wanted a local cluster)
Install tilt: https://docs.tilt.dev/tutorial/1-prerequisites.html
Start up sample application: https://docs.tilt.dev/tutorial/2-tilt-up.html
My notes on github:
https://github.com/sellerin/notes/blob/main/TILT_LOCAL_KUBERNETES.md
Thank you for reading.
No comments:
Post a Comment