Menu

Virtual Geek

Tales from real IT system administrators world and non-production environment

Mastering Kind Kubernetes Installation on Ubuntu for Development & Testing

I do Kubernetes administration on daily basis a lot. For demo and POC testing purpose, I use local Kubernetes infrastructure implementation called KIND. KIND is a very helpful tool for me, which runs local Kubernetes clusters on my laptop. Kind's long form is Kubernetes in docker. It uses docker containers as nodes and it doesn't require VM. It is very lightweight and capable of running multi nodes cluster.

This is a step by step procedure to install KIND (Kubernetes cluster) on Ubuntu. Make sure you have minimum dual core CPU and 4 GB Ram, Recommended minimum is 2 CPU and 8 GB RAM. Use below commands to download kind binary executable matching to OS installed, change executable permission of kind binary and move it to /usr/local/bin directory.

# For AMD64 / x86_64
[ $(uname -m) = x86_64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.29.0/kind-linux-amd64
# For ARM64
#[ $(uname -m) = aarch64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.29.0/kind-linux-arm64
chmod +x ./kind
sudo mv ./kind /usr/local/bin/kind

Before start make sure you have installed docker on Ubuntu. You can refer this article How to install Docker on Ubuntu. For other OS and different version use this article https://kind.sigs.k8s.io/docs/user/quick-start/#installing-from-release-binaries

Screenshot of a terminal on Ubuntu showing commands to install kind Kubernetes: curl command to download the kind binary, chmod +x to make it executable, and sudo mv to move it to /usr/local/bin.

After successful installation of kind application, check the version and install one node Kubernetes cluster using following command.

kind version
sudo kind create cluster --name=singlenodecluter 

Screenshot of a terminal on Ubuntu showing 'kind version' output (v0.29.0) and the successful creation of a single-node Kubernetes cluster named 'singlenodecluster' using 'kind create cluster' command.

Verify kind has deployed single node cluster successfully by get clusters command. To connect Kubernetes cluster you will need to install kubectl client first. Download kubectl binary and move it to /usr/local/bin folder with correct executable permissions, Confirm kubectl is installed correctly by checking its version. 

sudo kind get clusters
curl -LO https://dl.k8s.io/release/v1.33.0/bin/linux/amd64/kubectl
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
sudo kubectl version

Check other kubectl installation options here: https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/.

Screenshot of a terminal on Ubuntu showing the 'sudo kind get clusters' command listing 'singlenodecluster', followed by curl command to download kubectl, then sudo install command to move kubectl to /usr/local/bin, and finally 'sudo kubectl version' showing Client Version v1.33.0 and Server Version v1.33.1.

Next verify you are able to connect Kubernetes cluster using kubectl command. Try to list nodes, there will be only one node which is hosted on docker as container (you can confirm it by running docker ps command as well). Next deploy a test deployment pod in Kubernetes cluster using kubectl command. Verify pods inside deployment is deployed properly.

sudo kubectl get nodes
sudo kubectl create deployment nginx --image nginx
sudo kubectl get pods

Screenshot of a terminal on Ubuntu showing Kubernetes commands: 'sudo kubectl get nodes' listing 'singlenodecluster-control-plane' as Ready, followed by 'sudo kubectl create deployment nginx --image nginx' creating an Nginx deployment, and then 'sudo kubectl get pods -w' showing the Nginx pod running.

KIND is using docker containers as nodes in the background, make sure your account has enough permissions over docker. Make your user account to the member of docker group and reboot system. After reboot sudo will not be required every time when you are running kubectl or docker commands and they will not fail.

sudo groupadd docker
sudo usermod -aG docker $USER
reboot -f
docker ps

Official KBs: 
https://docs.docker.com/engine/install/linux-postinstall/#manage-docker-as-a-non-root-user 
https://kind.sigs.k8s.io/docs/user/known-issues#docker-permission-denied

Screenshot of a terminal on Ubuntu showing 'sudo groupadd docker' (group already exists), then 'sudo usermod -aG docker $USER' to add the user to the docker group, followed by a reboot, and finally 'docker ps' command successfully listing a running kind Docker container.

To install multi node cluster, make swapoff enabled, create yaml file with kind cluster meta information, multiple control-plane and worker. configure inotify so it can support multi node cluster (https://kind.sigs.k8s.io/docs/user/known-issues#pod-errors-due-to-too-many-open-files). To make the inotify changes persistent, edit the file /etc/sysctl.conf and add lines fs.inotify.max_user_watches = 524288 and fs.inotify.max_user_instances = 512. Inotify can be used to monitor individual files, or to monitor directories

In the last execute kind with multi node cluster configuration yaml file to create multi node cluster in Kubernetes.

sudo swapoff -a

cat multinodecluster.yaml

kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
  - role: control-plane
  - role: control-plane
  - role: control-plane
  - role: worker
  - role: worker
  - role: worker

sudo sysctl fs.inotify.max_user_watches=524288
sudo sysctl fs_inotify.max_user_instances=512

kind create cluster --name multinodecluster --config multinodecluster.yaml

Screenshot of a terminal on Ubuntu showing commands to disable swap ('sudo swapoff -a'), view and edit the multinodecluster.yaml kind configuration file with 3 control-plane and 3 worker nodes, set fs.inotify.max_user_watches and fs.inotify.max_user_instances limits, and finally the successful creation of the 'mutlinodecluster' kind Kubernetes cluster.

Everything is good so far, check the current cluster information using kubectl and deploy pod in it. Once deployment is successful, for testing purpose I am using port forwarding to connect nginx web server on pod from browser. which can be accessed locally for testing.

kubectl cluster-info --context kind-multinodecluster
kubectl get nodes
kubectl create deployment nginx --image=nginx
kubectl get pods
kubectl port-forward pod/nginx-5869d7778c-grl95 8080:80

Screenshot of a code block showing kubectl commands: 'kubectl cluster-info', 'kubectl get nodes', 'kubectl create pod nginx', 'kubectl create deployment nginx --image=nginx', 'kubectl get pods', and 'kubectl port-forward pod/nginx-5869d7778c-grl95 8080:80'.

Screenshot of a web browser displaying the 'Welcome to nginx!' default page, accessed via http://localhost:8080, confirming a successful Nginx web server deployment in a Kubernetes cluster.

In the last use below command to delete/destroy and cleanup kind Kubernetes cluster.

kind delete cluster --name=multinodecluster

Screenshot of a terminal on Ubuntu showing the 'kind delete cluster --name mutlinodecluster' command successfully deleting the specified Kubernetes cluster, listing all deleted nodes including control-planes, workers, and the external load balancer.

Useful Articles
Part 1 Git version control integration in Visual Studio Code
Part 2 Git master branch source control integration in Visual Studio Code
Part 3 Git clone version control integration in Visual Studio Code
Remote: Permission to UserName/repo.git denied to OtherUserName fatal: unable to access 'https://github.com/UserName/repo.git/': The requested URL returned error: 403
Step by Step guide to push your first project to github.com
Access credential parameters stored in Ansible Tower within a playbook
Part 1 Inject and install VMware Tools During Install by modifying Microsoft Windows ISO
Part 2: Configure IIS server to allow download .ISO files
Part 3: Using HashiCorp Packer to build a Windows Server VM template for VMware vSphere
Terraform clone virtual machine template in VMware vSphere vCenter from CSV file
Terraform error retrieving storage account failure responding to request StatusCode 404 StorageAccountNotFound The storage account was not found

Go Back

Comment

Blog Search

Page Views

13509487

Follow me on Blogarama