Difficulty: Basic Understanding of Kubernetes
Estimated Time: Takes minute or two for the cluster to spin up

Objective

The objective of this scenario is to demonstrate how to create implement node affinity in a Kubernetes cluster using Kubernetes in Docker and then run a simple multi-pod application in the cluster dedicated to the identified node.

What is node affinity?

Node affinity it the technique of making it so that a particular Kubernetes pod run on a predetermined node.

The way that node affinity works is that a node is given a label and then pods are configured to label assigned to the given node. Once a pod is assigned a node label, that pod(s) will deploy to the node with the corresponding label.

What you need to know to start

In order to get full benefit from taking this scenario, you need to have basic understanding of following Kubernetetes concepts:

This video describes the basics of Kubernetes you need to know:

What is KinD?

Typically a Kubernetes cluster is a collection of computers in which each computer is usually a virtual machine (VM). In Kubernetes's parlance, a machine is called a node.

While clusters based on VMs are commonplace in staging and production environments, for developers using VM based clusters can be a hindrance. It takes time to configure and deploy the VMs. And, if something goes wrong, replenishing them can take time too.

Instead of using VMs, KinD allows developers to create a cluster in which each node is a Linux container. Thus, developers can enjoy the benefit of working with a fully functional multiple node cluster without having to go through the pain of creating a number of VMs and then configuring them for the cluster. If something goes wrong, all the developer needs to do is destroy the cluster and create a new one. The ease and time-savings is significant.

What you'll be doing

This scenario is divided into the following steps.

  • Step 1 - Verify the cluster
  • Step 2 - Label a node
  • Step 3 - Create the deployment manifest file
  • Step 4 - Apply the deployment manifest
  • Step 5 - View the results

Executing command line instructions

This scenario is completely interactive. The instructions you'll be given will be executed directly in the terminal window that is embedded directly in the Katacoda interactive learning environment. In the steps to come, when you see a command line instruction with a black background and check mark at the end, like so:

Katacoda command line

just click on it and the command will execute in the interative terminal window.

Congratulations! You've completed the scenario, Implementing Node Affinity under Kubernetes in Docker.

In this scenario you:

  • Verified that the KinD cluster is running
  • Applied a label to a node
  • Created the deployment manifest file that supports affinity to the labeled node
  • Applied the deployment manifest
  • Viewed the results

You can read more about node affinity on the Kubernetes web site.

Immplementing Node Affinity Using Kubernetes in Docker (KinD)

Step 1 of 5

Verify the cluster is running

Objective

The objective of this lesson is to verify that the Kubernetes cluster installed automatically at the onset of the scenario is up and running.

Confiming the KinD cluster is running

When you start out you might see the cluster spinning up in the teminal pane like so:

Creating cluster "kind" ...
 ✓ Ensuring node image (kindest/node:v1.19.1) 🖼
 ✓ 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

Have a nice day! 👋

Be patient. It might take a few minutes for the cluster to spin up.

Once you see a command prompt, to confirm the cluster is up and running click the following command:

kubectl get node -o wide

You'll see output similar to the following:

NAME                 STATUS   ROLES    AGE     VERSION   INTERNAL-IP   EXTERNAL-IP   OS-IMAGE                                     KERNEL-VERSION      CONTAINER-RUNTIME
kind-control-plane   Ready    master   2m59s   v1.19.1   172.19.0.3    <none>        Ubuntu Groovy Gorilla (development branch)   4.4.0-185-generic   containerd://1.4.0
kind-worker          Ready    <none>   2m23s   v1.19.1   172.19.0.2    <none>        Ubuntu Groovy Gorilla (development branch)   4.4.0-185-generic   containerd://1.4.0
kind-worker2         Ready    <none>   2m23s   v1.19.1   172.19.0.4    <none>        Ubuntu Groovy Gorilla (development branch)   4.4.0-185-generic   containerd://1.4.0

Once the cluster is up and running take it for a spin and enjoy!


Next: Label a node for affinity assigment