Skip to content

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
  • Labs icon Lab
  • A Cloud Guru
Google Cloud Platform icon
Labs

Creating a Kubernetes Cluster

In this hands-on lab, we will install and configure a Kubernetes cluster consisting of 1 master and 2 nodes. Once the installation and configuration are complete, we will have a 3-node Kubernetes cluster that uses Flannel as the network overlay.

Google Cloud Platform icon
Labs

Path Info

Level
Clock icon Beginner
Duration
Clock icon 1h 30m
Published
Clock icon Jan 28, 2019

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.

Table of Contents

  1. Challenge

    Install containerd and Kubernetes on All Servers

    Most commands need to be run on all nodes. Pay attention though. Commands to initialize and configure the cluster need to be run only on the master node, whereas kubeadm join commands need to be run only on node1 and node2. There are notes down there, just watch for them.

    1. Once we have logged in, we need to elevate privileges using sudo:

      sudo su  
      
    2. Create the configuration file for containerd:

      cat <<EOF | sudo tee /etc/modules-load.d/containerd.conf
      overlay
      br_netfilter
      EOF
      
    3. Load the modules:

      sudo modprobe overlay
      sudo modprobe br_netfilter
      
    4. Set the system configurations for Kubernetes networking:

      cat <<EOF | sudo tee /etc/sysctl.d/99-kubernetes-cri.conf
      net.bridge.bridge-nf-call-iptables = 1
      net.ipv4.ip_forward = 1
      net.bridge.bridge-nf-call-ip6tables = 1
      EOF
      
    5. Apply the new settings:

      sudo sysctl --system
      
    6. Add the stable Docker Community Edition repository to yum:

      yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
      
    7. Install containerd:

      sudo yum install -y containerd.io
      
    8. Create the default configuration folder for containerd:

      sudo mkdir -p /etc/containerd
      
    9. Generate the default containerd configuration, and save it to the newly created default file:

      sudo containerd config default | sudo tee /etc/containerd/config.toml
      
    10. Restart containerd to ensure the new configuration file is used:

      sudo systemctl restart containerd
      
    11. Verify that containerd is running:

      sudo systemctl status containerd
      
    12. Disable swap:

      sudo swapoff -a
      
    13. Set SELinux in permissive mode (effectively disabling it):

       sudo setenforce 0
       sudo sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
      
    14. Add the Kubernetes repository (this overwrites any existing configuration in /etc/yum.repos.d/kubernetes.repo):

      cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
      [kubernetes]
      name=Kubernetes
      baseurl=https://pkgs.k8s.io/core:/stable:/v1.29/rpm/
      enabled=1
      gpgcheck=1
      gpgkey=https://pkgs.k8s.io/core:/stable:/v1.29/rpm/repodata/repomd.xml.key
      exclude=kubelet kubeadm kubectl cri-tools kubernetes-cni
      EOF
      
    15. Install kubelet, kubeadm and kubectl:

      sudo yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
      
    16. Enable the kubelet service before running kubeadm:

      sudo systemctl enable --now kubelet
      

    Note: Complete the following section on the MASTER ONLY!

    1. Initialize the cluster using the IP range for Flannel:

      kubeadm init --pod-network-cidr=10.244.0.0/16
      
    2. Copy the kubeadmn join command that is in the output. We will need this later.

    3. Exit sudo, copy the admin.conf to your home directory, and take ownership:

      mkdir -p $HOME/.kube
      sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
      sudo chown $(id -u):$(id -g) $HOME/.kube/config
      
    4. Deploy Flannel:

      kubectl apply -f https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml
      
    5. Check the cluster state:

      kubectl get pods --all-namespaces
      

    Note: Complete the following steps on the NODES ONLY!

    1. Run the join command that you copied earlier, this requires running the command prefaced with sudo on the nodes (if we hadn't run sudo su to begin with). Then we'll check the nodes from the master.

      kubectl get nodes
      
  2. Challenge

    Create and Scale a Deployment Using kubectl

    Note: These commands will only be run on the master node.

    1. Create a simple deployment:

      kubectl create deployment nginx --image=nginx
      
    2. Inspect the pod:

      kubectl get pods
      
    3. Scale the deployment:

      kubectl scale deployment nginx --replicas=4
      
    4. Inspect the pods. We should have four now:

      kubectl get pods
      

The Cloud Content team comprises subject matter experts hyper focused on services offered by the leading cloud vendors (AWS, GCP, and Azure), as well as cloud-related technologies such as Linux and DevOps. The team is thrilled to share their knowledge to help you build modern tech solutions from the ground up, secure and optimize your environments, and so much more!

What's a lab?

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Provided environment for hands-on practice

We will provide the credentials and environment necessary for you to practice right within your browser.

Guided walkthrough

Follow along with the author’s guided walkthrough and build something new in your provided environment!

Did you know?

On average, you retain 75% more of your learning if you get time for practice.

Start learning by doing today

View Plans