DEV Community

Cover image for CKA Full Course 2024: Day 5/40 Multi-Node Cluster Setup: Step by Step
Lloyd Rivers
Lloyd Rivers

Posted on

CKA Full Course 2024: Day 5/40 Multi-Node Cluster Setup: Step by Step

Setting up a Kubernetes cluster is a foundational step for managing containerized applications at scale. In this post, we’ll guide you through installing kubectl, creating a Kubernetes cluster using kind, and configuring a multi-node setup with a step-by-step approach. We’ll also highlight five essential kubectl commands that will give you a solid start in managing your Kubernetes cluster.

What You’ll Learn:

  1. Installing kubectl
  2. Installing and configuring kind
  3. Creating and managing a Kubernetes cluster
  4. Understanding and using key kubectl commands

Let’s dive in!


Step 1: Installing kubectl

kubectl is the command-line tool that allows you to interact with your Kubernetes cluster. You’ll need this to manage and configure the cluster once it’s up and running.

How to Install kubectl:

  1. On macOS:
   brew install kubectl
Enter fullscreen mode Exit fullscreen mode

For more installation options and in-depth instructions, refer to the official Kubernetes documentation.


Step 2: Installing kind

kind is a tool for running local Kubernetes clusters using Docker. It’s great for development, testing, and learning Kubernetes concepts before moving to a production environment.

How to Install kind:

  1. On macOS & Linux:
   brew install kind
Enter fullscreen mode Exit fullscreen mode
  1. On Windows (using Chocolatey):
   choco install kind
Enter fullscreen mode Exit fullscreen mode

For more detailed installation instructions, refer to the official kind documentation.


Step 3: Creating a Kubernetes Cluster

With both kubectl and kind installed, you can now create your Kubernetes cluster.

Basic Cluster Creation:

To create a basic single-node cluster, use the following command:

kind create cluster
Enter fullscreen mode Exit fullscreen mode

Understanding the Cluster Creation Process:

  • kind will bootstrap a Kubernetes cluster using a pre-built node image. These images are hosted at kindest/node.
  • By default, the cluster will use the latest stable image for the Kubernetes version. If you want a different version, specify it using the --image flag like this:
kind create cluster --image=kindest/node:v1.22.2
Enter fullscreen mode Exit fullscreen mode

Check the kind release notes to find images for specific Kubernetes versions. You can also build your own custom images if needed (this is more advanced, but worth exploring).

Multi-Node Cluster Configuration:

To create a multi-node cluster, you’ll need a configuration YAML file. Here’s a sample configuration:

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

Save this configuration to a file, for example kind-config.yaml, and then create your multi-node cluster:

kind create cluster --config=kind-config.yaml
Enter fullscreen mode Exit fullscreen mode

This command will create a cluster with one control-plane node and two worker nodes.

Check Your Cluster Status:

Once your cluster is created, you can check its status with the following kubectl command:

kubectl cluster-info --context kind-<cluster-name>
Enter fullscreen mode Exit fullscreen mode

Replace <cluster-name> with the name of your cluster (e.g., kind-kind if you used the default).


Step 4: Key kubectl Commands

Here are some essential kubectl commands to help you manage your cluster effectively:

  • Check the Nodes:
   kubectl get nodes
Enter fullscreen mode Exit fullscreen mode

This command lists all nodes (control-plane and worker nodes) in your cluster.

  • List All Pods:
   kubectl get pods --all-namespaces
Enter fullscreen mode Exit fullscreen mode

This shows the status of all pods running in all namespaces in your cluster.

  • Get Detailed Information About a Pod:
   kubectl describe pod <pod-name>
Enter fullscreen mode Exit fullscreen mode

Replace <pod-name> with the name of your pod to get detailed information about it.

  • Create a Resource from a YAML File:
   kubectl apply -f <your-app.yaml>
Enter fullscreen mode Exit fullscreen mode

Use this to deploy an application from a YAML configuration file.

  • Delete a Resource:
   kubectl delete <resource-type> <resource-name>
Enter fullscreen mode Exit fullscreen mode

This command deletes a specific resource, like a pod or deployment.

For more commands, check out the official Kubernetes Cheat Sheet.


Changing the Cluster Context

To ensure that you are interacting with the correct cluster, use the following command:

kubectl config use-context kind-<cluster-name>
Enter fullscreen mode Exit fullscreen mode

Replace <cluster-name> with the name of your cluster (e.g., kind-kind).


Coming Soon: A Peek at K9s

While kubectl gives you control over your Kubernetes clusters, there's an amazing tool that takes cluster management to the next level — K9s. We won’t unpack it fully here, but here's a teaser: imagine navigating and managing your cluster with a slick, terminal-based UI. Stay tuned for more details, and we’ll dive deeper into the awesomeness of K9s in an upcoming post!

Image description


Conclusion

In this guide, we’ve walked through the process of setting up a multi-node Kubernetes cluster using kind, configuring kubectl, and managing your cluster with essential commands. By following these steps, you’re well on your way to understanding and managing Kubernetes clusters effectively.


Tags and Mentions

@piyushsachdeva
Day 6 video

Top comments (0)