21  Kubernetes setup

You can download Kubernetes to deploy a Kubernetes cluster on a local machine, into the cloud, or for your own datacenter.

We will install Kubernetes in our vdb volume using kind (Kubernetes IN Docker).

Furthermore, we use the Kubernetes command-line tool kubectl which allows you to run commands against Kubernetes clusters. You can use kubectl to deploy applications, inspect and manage cluster resources, and view logs.

21.1 Prerequisites

To create clusters with kind, you will first need to install Docker. If you haven’t already, install Docker, following these instructions.

21.2 Kind installation

kind (Kubernetes IN Docker) is a tool for running local Kubernetes clusters using Docker container “nodes”.

  • We follow the official installation guide and download the latest binary (v0.18.0 at the time of this writing).

Change directory

cd /mnt/vdb
sudo curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.18.0/kind-linux-amd64
  • Change permissions and rename it to kind:
sudo chmod +x ./kind
  • Create a symbolic link (symlink):
sudo ln -s /mnt/vdb/kind /usr/local/bin/kind

21.2.1 Creating a Cluster

  • Creating a Kubernetes cluster is as simple as kind create cluster (visit this site to learn more).
sudo kind create cluster

This will bootstrap a Kubernetes cluster using a pre-built node image. Prebuilt images are hosted at kindest/node.

21.3 kubectl installation

After creating a cluster, you can use kubectl to interact with it by using the configuration file generated by kind. We follow the official installation tutorial to install kubectl.

  • Change directory
cd /mnt/vdb
  • Create a new directory
mkdir bin
  • Download the latest release with the command:
sudo curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
  • Install kubectl
sudo install -o root -g root -m 0755 kubectl /mnt/vdb/bin/kubectl
  • Create a symbolic link (symlink):
sudo ln -s /mnt/vdb/bin/kubectl /usr/local/bin/kubectl
  • Test to ensure the version you installed is up-to-date:
kubectl version --client --output=yaml

21.4 Config file

  • Set the config file to the correct path:
export KUBECONFIG=/root/.kube/config
  • Ensure that the correct context is being used by running:
sudo kubectl config use-context kind-kind

21.5 Interacting With Your Cluster

  • Check that kubectl is properly configured by getting the cluster state:
sudo kubectl cluster-info
  • List any existing Pods
sudo kubectl get pods

This should output: “No resources found in default namespace.”

21.6 Prepare environment

In the following steps, we will use some of Nigel Poulton’s examples from “The Kubernetes Book (2022)”. Therefore, we will clone his GitHub-repo on our virtual machine.

  • Change directory to mnt/vdb
cd /mnt/vdb
  • Make a new directory:
mkdir github
  • Change into the directory:
cd github
  • Clone this GitHub-repo into the directory:
git clone https://github.com/nigelpoulton/TheK8sBook.git