Introduction

There are several ways how to set up a Kubernetes Cluster. Find an example for the basic steps to install a Kubernetes Cluster on CentOS  7 from the following chapters.

Setting up a Kubernetes Cluster

Install Docker on CentOS 7

  1. Update the package database

    sudo yum check-update



  2. Install the dependencies

    sudo yum install -y yum-utils device-mapper-persistent-data lvm2



  3. Add and enable the Docker Repository for CentOS

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



  4. Install the latest Docker version for CentOS

    sudo yum install docker-ce



  5. After successful installation the output will include the string  Complete!
    You may be prompted to accept the GPG key. This is to verify that the fingerprint matches. A fingerprint can look like this, if you consider the fingerprint being correct, accept it:

    060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35



  6. Manage Docker service
    With Docker being installed the systemd service has to be started. Start and enable Docker from systemd using the following commands:

    sudo systemctl start docker.service
    sudo systemctl enable docker.service



  7. To check that Docker is up and running use the command:

    sudo systemctl status docker.service

Set up the Kubernetes Repository

  1. Since the Kubernetes packages aren’t present in the official CentOS 7 repositories users have to add a new repository file. Use the following command to create the file and open it for editing:

    sudo vi /etc/yum.repos.d/kubernetes.repo



  2. Once the file is open, press the I key to enter insert mode and paste the following contents:

    [kubernetes]
    name=Kubernetes
    baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
    enabled=1
    gpgcheck=1
    repo_gpgcheck=1
    gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg

    Once pasted, press escape to exit insert mode. Then enter :x to save the file and exit.

Install kubelet on CentOS 7

kubelet is the first core module to be installed on every Kubernetes Cluster node. Use the following command:

sudo yum install -y kubelet

Install kubeadm and kubectl on CentOS 7

  1. kubeadm is the next core module that has to be installed. Use the following command:

    sudo yum install -y kubeadm

    Note that kubeadm automatically installs kubectl as a dependency.



  2. Disable swap by use of the below commands:

    sudo swapoff -a
    sudo sed -i '/ swap / s/^/#/' /etc/fstab

Initialize kubeadm and start the Kubernetes Cluster

  1. When initializing kubeadm directly then kubeadm might raise the error:

    Some fatal errors occurred: [ERROR CRI]: container runtime is not running Status from runtime service failed” err=”rpc error: code = Unimplemented desc = unknown service runtime.v1alpha2.RuntimeService”



  2. To resolve the above problem users should delete the config.tomal file and restart containerd using the following commands:

    sudo rm /etc/containerd/config.toml
    systemctl restart containerd



  3. Initialize kubeadm, create required directories and manage Kubernetes Cluster configuration:

    sudo kubeadm init
    mkdir $HOME/.kube
    sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
    sudo chown $(id -u):$(id -g) $HOME/.kube/config
    export KUBECONFIG=/etc/kubernetes/admin.conf



  4. Enable and restart Docker and Kubernetes services from systemd.

    sudo systemctl enable docker.service
    sudo service kubelet restart
    sudo chown -R centos:centos kubernetes/
    



  5. To initialize the CNI plugin update your CNI plugins and edit the CNI config files. Use the following command to create the file and open it for editing:

    sudo vi /etc/cni/net.d/10-containerd-net.conflist



  6. Once the file is open, press the I key to enter insert mode and paste the following contents:

    {
     "cniVersion": "1.0.0",
     "name": "containerd-net",
     "plugins": [
       {
         "type": "bridge",
         "bridge": "cni0",
         "isGateway": true,
         "ipMasq": true,
         "promiscMode": true,
         "ipam": {
           "type": "host-local",
           "ranges": [
             [{
               "subnet": "10.88.0.0/16"
             }],
             [{
               "subnet": "2001:db8:4860::/64"
             }]
           ],
           "routes": [
             { "dst": "0.0.0.0/0" },
             { "dst": "::/0" }
           ]
         }
       },
       {
         "type": "portmap",
         "capabilities": {"portMappings": true},
         "externalSetMarkChain": "KUBE-MARK-MASQ"
       }
     ]
    }

    Once pasted, press escape to exit insert mode. Then enter :x to save the file and exit.


  7. We have to taint this node. We can do this by using the kubectl taint command

    kubectl taint nodes <name-node-master> node-role.kubernetes.io/control-plane:NoSchedule-



  8. Set up Pod network for the Kubernetes Cluster.

    kubectl get nodes



With the above steps, the setup of the Kubernetes Cluster is completed. In the next step, users can create the Kubernetes YAML deployment files to deploy JS7 products to the Kubernetes Cluster.

Further Resources