Skip to main content

Install and Configure a Kubernetes Cluster

Hands-On Lab

 

Photo of Matthew Pearson

Matthew Pearson

Linux Training Architect II in Content

Length

01:00:00

Difficulty

Advanced

Kubernetes is an open source system that is used to orchestrate and manage containerized applications. By implementing a Kubernetes cluster, deploying and scaling applications becomes almost effortless. In this learning activity, you are tasked with installing Kubernetes and configuring a cluster for use with Docker containers. For this Kubernetes implementation, you will be using kubeadm to bootstrap the cluster.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Install and Configure a Kubernetes Cluster

Introduction

Kubernetes is an open-source system that is used to orchestrate and manage containerized applications. By implementing a Kubernetes cluster, deploying and scaling applications becomes almost effortless. In this learning activity, we are tasked with installing Kubernetes and configuring a cluster for use with Docker containers. For this Kubernetes implementation, we will be using kubeadm to bootstrap the cluster.

The Scenario

Our development department wants to move to a more scalable deployment architecture. As the system engineers, we are tasked with setting up a Kubernetes cluster that will be used to manage and deploy Docker containers. The cluster will be bootstrapped using kubeadm. The first iteration will consist of 3 nodes: a master and two workers.

  1. First, we will need to install Docker and the Kubernetes binaries on all of the cluster nodes.
  2. Then we will need to initialize the master node with a pod network of 10.244.0.0/16 and ensure that the cloud_user is able to manage the cluster.
  3. Once the master is initialized, we'll join the worker nodes to the master node.
  4. Finally, we'll install the flannel network add-on.

Important notes:

  • No ports need to be opened in the firewall.
  • The GPG key for Docker is located here.
  • The Docker repository is located here.
  • The version of Docker that needs to be installed is docker-ce 18.06.1~ce~3-0~ubuntu.
  • The GPG key for Kubernetes is located here.
  • The repository for Kubernetes is located here.
  • The version of kubeadm, kubelet, and kubectl needs to be 1.12.2-00.
  • When installing flannel use this link.

Logging In

Use the credentials and server IP information on the hands-on lab overview page to log into the server as cloud_user. Note that there are three servers here, one that will be a master, and two that will be nodes. We're probably better off just having a terminal open in each one right off the bat.

Install Docker on All of the Cluster Nodes

  1. Add the GPG key:
    cloud_user@master:~$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

  2. Add Docker repository:
    cloud_user@master:~$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

  3. Update packages:
    cloud_user@master:~$ sudo apt-get update

  4. Install Docker:
    cloud_user@master:~$ sudo apt-get install -y docker-ce=18.06.1~ce~3-0~ubuntu

Run all of these commands on the two worker nodes as well.

Install Kubernetes Binaries (kubeadm, kubelet, and kubectl) on All of the Cluster Nodes

  1. Add GPG key:
    # curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -

  2. Add Kubernetes repository:

    cloud_user@master:~$cat << EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
    deb https://apt.kubernetes.io/ kubernetes-xenial main
    EOF
  3. Resynchronize the package index:
    cloud_user@master:~$ sudo apt-get update

  4. Install the required packages:
    cloud_user@master:~$ sudo apt-get install -y kubelet=1.12.7-00 kubeadm=1.12.7-00 kubectl=1.12.7-00

  5. Prevent packages from being automatically updated:
    cloud_user@master:~$ sudo apt-mark hold kubelet kubeadm kubectl

Let's make sure we run these on the other two nodes.

Initialize the Master Node

  1. Initialize the master using kubeadm and specify the pod network:
    cloud_user@master:~$ sudo kubeadm init --pod-network-cidr=10.244.0.0/16

  2. Configure the cloud_user to be able to administer the cluster:

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

Join the Worker Nodes to the Master Node

Use kubeadm to join the worker nodes to the master node (the command is provided after kubeadm init is run on the master):

cloud_user@worker1:~$ sudo kubeadm join $controller_private_ip:6443 --token $token --discovery-token-ca-cert-hash $hash cloud_user@worker2:~$ sudo kubeadm join $controller_private_ip:6443 --token $token --discovery-token-ca-cert-hash $hash

To make sure the nodes joined the cluster, run the command to check, on the master node: cloud_user@master:~$ kubectl get nodes

We should see both workers nodes show up in the list.

Install the Flannel Network Add-On

  1. Enable net.bridge.bridge-nf-call-iptables to ensure that the the iptables proxy functions correctly.

    cloud_user@master:~$ echo "net.bridge.bridge-nf-call-iptables=1" | sudo tee -a /etc/sysctl.conf
    sudo sysctl -p

    Make sure we run this on the worker nodes too.

  2. Install flannel on the master:
    kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/bc79dd1505b0c8681ece4de4c0d86c5cd2643275/Documentation/kube-flannel.yml

  3. Check out how things are going again by running kubectl get nodes on the master again. They should all have a status of READY now.

Conclusion

We've done it. We now have a Kubernetes cluster all set up and ready to deploy some Docker containers. Congratulations!