Setup Kubernetes Anywhere with Single Command
In an earlier article, we have seen how to set up Kubernetes on M1 Mac. That involved spinning up a VM and installing Kubernetes1 on it. In this article, we will see how to set up Kubernetes directly on Docker so that we can use the same set-up on any operating system.
Ensure you have Docker installed on your system. If you are on a Mac or Windows, you can install Docker Desktop2.
k3s3 is a lightweight Kubernetes distribution by Rancher. It is a single binary that can be run on any Linux machine. But it doesn't work on Mac or Windows.
k3d4 is a wrapper around k3s that allows you to run k3s on Docker. It is a great option for running Kubernetes on your local machine.
k3d can be installed using the following command:
$ brew install k3d # mac $ chocolatey install k3d # windows $ curl -s https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | bash # linux
Once it is installed, we can create a cluster using the following command:
$ k3d cluster create demo
This will launch a cluster with a single node. We can also setup a multi-node cluster using the following command:
$ k3d cluster create demo --servers 3 --agents 2
We can verify the cluster is up and running using the following command:
$ kubectl get nodes
We can also use GUI tools like Lens to manage and navigate the cluster. In the above video we have used Lens to create a Jenkins deployment as well.
In this article, we have seen how to set up Kubernetes on Docker. This is a great option for running Kubernetes on your local machine. We can also use this to run production setup for small applications.