HOW TO - Create a K8s cluster with KinD on Ubuntu

Overview

If you’re new to Kubernetes and don’t know where to start, follow the steps below to install and configure a Kubernetes cluster with KinD on an Ubuntu machine. Once you have a Kubernetes cluster running, you will be able to deploy K8ssandra locally.

KinD stands for “Kubernetes in Docker”. The kind tool lets you run Kubernetes on your laptop or PC. It requires Docker to be installed and configured.

In this post, we will be providing the steps for creating a KinD cluster on Ubuntu Focal 20.04.

Prerequisites

KinD can be installed on machines with minimal hardware configuration but for the purposes of running K8ssandra, the minimum specs required are:

  • 8 virtual CPUs (4 physical cores)
  • 16GB of RAM

This will allow you to allocate 4 vCPUs and 8GB of RAM to Docker.

Install Docker Engine

In order to use KinD, we need to install Docker first.

Docker is an open-source platform that allows developers to easily package/deploy/run software applications in self-contained packages called containers which can run anywhere.

Docker containers provide another level of abstraction in that the containers share the operating system. In contrast, a virtual machine (VM) has both the OS and applications on shared hardware.

STEP D1 - Remove old versions of Docker if they’ve previously been installed:

$ sudo apt-get remove docker docker-engine docker.io containerd runc

STEP D2 - Install packages that allow APT to use HTTPS:

$ sudo apt-get update
$ sudo apt-get install -y \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common

STEP D3 - Add Docker’s GPG key:

$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

STEP D4 - Add the Docker repository:

$ sudo add-apt-repository \
    "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
    $(lsb_release -cs) \
    stable"

STEP D5 - Install the Docker engine:

$ sudo apt-get update
$ sudo apt-get install -y docker-ce docker-ce-cli containerd.io

STEP D6 - Add your login to the Docker group:

$ sudo usermod -aG docker $USER

STEP D7 - Logout of your SSH session and log back in for the changes to take effect.

STEP D8 - Verify the engine is installed correctly:

$ docker run hello-world

If Docker was installed successfully, the output would look like:

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete 
Digest: sha256:f2266cbfc127c960fd30e76b7c792dc23b588c0db76233517e1891a4e357d519
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

For detailed installation info, see Install Docker Engine on Ubuntu.

Install kubectl

The Kubernetes command-line tool allows you to deploy and manage Kubernetes clusters. Without it, there’s not much you can do with a KinD cluster.

STEP T1 - Download kubectl:

$ sudo curl -L "https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl" -o /usr/local/bin/kubectl

STEP T2 - Make the app executable:

$ sudo chmod +x /usr/local/bin/kubectl

STEP T3 - Test the installation:

$ kubectl version --short --client
Client Version: v1.21.0

For detailed installation info, see Install and Set Up kubectl.

Install KinD

Now that we have Docker installed, it’s time to install the kind tool.

STEP K1 - Download KinD:

$ sudo curl -L "https://kind.sigs.k8s.io/dl/v0.8.1/kind-$(uname)-amd64" -o /usr/local/bin/kind

STEP K2 - Make the app executable:

$ sudo chmod +x /usr/local/bin/kind

STEP K3 - Test the installation:

$ kind get clusters

If kind was installed correctly, you should see the following output:

No kind clusters found.

If you got to this point, CONGRATULATIONS! Now it’s time to create a KinD cluster that’s configured for a K8ssandra deployment.

STEP K4 - Download the KinD configuration file (kind.config.yaml) from the K8ssandra repository on GitHub:

$ curl -OL https://raw.githubusercontent.com/k8ssandra/k8ssandra/main/docs/content/en/docs/topics/ingress/traefik/kind-deployment/kind.config.yaml

STEP K5 - Start your KinD cluster with:

$ kind create cluster --config ./kind.config.yaml

Note that this step will take about 4 minutes to complete. The output would look like:

Creating cluster "kind" ...
 ✓ Ensuring node image (kindest/node:v1.18.2) 🖼 
 ✓ Preparing nodes 📦 📦 📦 📦  
 ✓ Writing configuration 📜 
 ✓ Starting control-plane 🕹️ 
 ✓ Installing CNI 🔌 
 ✓ Installing StorageClass 💾 
 ✓ Joining worker nodes 🚜 
Set kubectl context to "kind-kind"
You can now use your cluster with:

kubectl cluster-info --context kind-kind

Thanks for using kind! 😊

Notice there are 4 nodes in the KinD cluster:

 ✓ Preparing nodes 📦 📦 📦 📦

This is because there are 3 worker nodes and 1 control plane defined in kind.config.yaml:

nodes:
- role: worker
- role: worker
- role: worker
- role: control-plane

We can also verify this with kubectl:

$ kubectl get nodes
NAME                 STATUS   ROLES    AGE     VERSION
kind-control-plane   Ready    master   7m13s   v1.18.2
kind-worker          Ready    <none>   6m34s   v1.18.2
kind-worker2         Ready    <none>   6m34s   v1.18.2
kind-worker3         Ready    <none>   6m34s   v1.18.2

Now that you have a KinD cluster started with worker nodes, you are now ready to install an Apache Cassandra database in Kubernetes using K8ssandra. Cheers!

Hi Erick,

Thanks for your great guide!

I found one error in the K4 step, the site response “404: Not Found”, so could you please help to correct it?

The rest steps help me very much!

Thanks,
Eric.

Hi Eric,

The URI changed to

$ curl -OL h t t p s : / / github. com/k8ssandra/k8ssandra-operator/blob/main/docs/content/en/tasks/connect/ingress/kind-deployment/kind.config.yaml

As I’m not allowed to post links, you need to remove the spaces in the link…

regards, Daniel

1 Like

Hi Eric,
Thanks for your maunual!
This uri didn’t work for me I had to copy and paste the yaml for it to work did anything change?
I am running it on an ubuntu ec2 instance.