Installing Kubernetes on CentOS 7

Kubernetes is a popular open-source solution for automated software deployments that uses containerized applications. Originally designed by Google, Kubernetes is compatible with most Linux distributions, including CentOS 7 and Ubuntu. When Kubernetes is installed and configured, it is then referred to as a Kubernetes cluster. A Kubernetes cluster involves 2 or more machines that are networked together for application deployment, such as deploying NGINX. These machines can either be physical servers or multiple virtual machines. In this guide, we will outline how to install Kubernetes on CentOS 7 and configure the Kubernetes cluster. Before proceeding with this, you will first want to set up the servers that will act as your master node and worker nodes. Before performing the steps in this guide, you will first need root SSH access to your server(s).

Topics Include:

Use Kubernetes with your Dedicated Hosting server and set up a Kubernetes cluster today!

Installing Kubernetes Packages and Docker

  1. First, you will need to set the hostname for your node. In this example, we are setting up the master node, referred to as master-node. These same steps will need to be repeated on any worker nodes you want to add to the Kubernetes cluster. To set the hostname, use the following command:

    hostnamectl set-hostname master-node

  2. Next, modify your hosts file to ensure connectivity to the other nodes. 

    cat <<EOF>> /etc/hosts
    10.128.0.27 master-node
    10.128.0.29 node-1 worker-node-1
    10.128.0.30 node-2 worker-node-2
    EOF
  3. To confirm that the hosts are set properly, you can perform a ping test on each node. 

    ping 12.345.6.79

  4. Next, you will need to disable SELinux:

    setenforce 0
    # sed -i --follow-symlinks 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux
    # reboot

  5. Then, you will need to update your Firewall Rules to allow traffic between nodes with the following series of commands:

    firewall-cmd --permanent --add-port=6443/tcp

    firewall-cmd --permanent --add-port=2379-2380/tcp

    firewall-cmd --permanent --add-port=10250/tcp

    firewall-cmd --permanent --add-port=10251/tcp

    firewall-cmd --permanent --add-port=10252/tcp

    firewall-cmd --permanent --add-port=10255/tcp

    firewall-cmd –reload
    # modprobe br_netfilter

    echo '1' > /proc/sys/net/bridge/bridge-nf-call-iptables

  6. Next, you will need to add the Kubernetes repository to the server using the following command:

    cat <<EOF > /etc/yum.repos.d/kubernetes.repo
    [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
    EOF

  7. Once the repository has been added, you can then install Kubeadm and Docker using the following command:

     yum install kubeadm docker -y 

  8. Once the services are installed, enable and start them with the following commands:

    systemctl enable kubelet

    systemctl start kubelet

    systemctl enable docker

    systemctl start docker

Initializing Kubernetes Master and Setup Default User

  1. First, disable swap using the following command:

    swapoff -a

  2. Then initialize Kubernetes Master with the following command:

    kubeadm init

  3. From that output, save the last line in your notes, we will need it in a later step. The line will look something like this:

    kubeadm join 10.128.0.27:6443 --token nu06lu.xrsux0ss0ixtnms5  \ --discovery-token-ca-cert-hash sha256:f996ea3564e6a07fdea2997a1cf8caeddafd6d4360d606dbc82314688425cd41 

  4. Now that kubeadm has been initialized, you will next need to set up root as the default user:

    mkdir -p $HOME/.kube

    cp -i /etc/kubernetes/admin.conf $HOME/.kube/config

    chown $(id -u):$(id -g) $HOME/.kube/config

  5. To check if the kubectl service is activated, use the following command:

    kubectl get nodes

    Note: Status will show Not Ready since we still need to add the pod network to the cluster. The pod network allows connectivity between nodes. Please proceed to the next section for further instructions. 

Setting Up Pod Network

  1. To set up the pod network, you will first need to install software that will establish the network between your master and worker nodes. In this example, we are using a networking plugin called cloudweaver:

    export kubever=$(kubectl version | base64 | tr -d '\n')

    kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$kubever"

  2. Once done, you can check the nodes again:

    kubectl get nodes

  3. If the status comes back as Ready, then that means you have set up your master-node If so, you are done! 
  4. To set up worker nodes, perform steps 1-8 on each node, then use the line from step 12 to add the worker nodes to the cluster. 
  5. Congratulations, you now have an operational Kubernetes cluster!

Now that you have your cluster set up, you can use your server to start deploying software containers!

InMotion Hosting Contributor
InMotion Hosting Contributor Content Writer

InMotion Hosting contributors are highly knowledgeable individuals who create relevant content on new trends and troubleshooting techniques to help you achieve your online goals!

More Articles by InMotion Hosting

Was this article helpful? Join the conversation!

Questions about our MailChannels Deployment? We have answers and are here to help!Learn More
+