Cluster Setup

Tutorial 1 of 4

Introduction

Goal of the Tutorial

This tutorial aims to guide you through the process of setting up a Kubernetes cluster, which includes creating a master node and several worker nodes.

Learning Outcomes

By the end of this tutorial, you will be able to:
1. Understand the basic concepts of Kubernetes and how a cluster is structured.
2. Set up a master node and worker nodes on Kubernetes.
3. Demonstrate how to connect the nodes and manage the cluster.

Prerequisites

Before starting this tutorial, you should have the following:
- Basic understanding of Docker and containerization.
- A system with Docker and Kubernetes installed.

Step-by-Step Guide

Concepts

In Kubernetes, a cluster consists of at least one cluster master and multiple worker machines called nodes. These master and node machines run the Kubernetes cluster orchestration system.

Creating the Master Node

  1. To start the Kubernetes master, use the kubeadm init command. This command initializes a Kubernetes control-plane node.
sudo kubeadm init --pod-network-cidr=10.244.0.0/16

Joining Worker Nodes to the Cluster

  1. To add a node to the cluster, use the kubeadm join command on the node machine, along with the token and the master IP address which was provided at the end of the kubeadm init command on the master node.
sudo kubeadm join --token <token> <master-ip>:<master-port> --discovery-token-ca-cert-hash <hash>

Code Examples

Example 1: Initializing the Kubernetes Master Node

Here is an example of initializing the Kubernetes master node.

sudo kubeadm init --pod-network-cidr=10.244.0.0/16

The --pod-network-cidr specifies the range of IP addresses for the pod network. If you decide to use a network plugin, ensure to use the same CIDR range.

Example 2: Joining a Node to the Kubernetes Cluster

Once you have the token and the hash, join the worker node to the cluster:

sudo kubeadm join --token <token> <master-ip>:<master-port> --discovery-token-ca-cert-hash <hash>

Replace <token>, <master-ip>, <master-port>, and <hash> with your actual token, master IP address, master port, and hash.

Summary

In this tutorial, we covered the basics of Kubernetes clusters, how to set up a master node, and how to add worker nodes to the cluster. The next step is to learn about deploying apps on your cluster and managing them using kubectl.

Practice Exercises

  1. Set up a Kubernetes cluster with 1 master and 2 worker nodes.
  2. Verify that all nodes are connected and functioning properly.
  3. Deploy a simple app on the cluster and ensure it runs successfully.

Additional Resources

  • Kubernetes official documentation: https://kubernetes.io/docs/home/
  • Learn Kubernetes Basics: https://kubernetes.io/docs/tutorials/kubernetes-basics/
  • Kubernetes Networking: How to Write a CNI Plugin from Scratch: https://www.altoros.com/blog/kubernetes-networking-writing-your-own-simple-cni-plug-in-with-bash/