Installing Kubernetes on CentOS 7 Updated on October 20, 2021 by InMotion Hosting Contributor 3 Minutes, 43 Seconds to Read 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: Installing Kubernetes Packages and DockerInitializing Kubernetes Master and Setup Default UserSetting Up Pod Network Use Kubernetes with your Dedicated Hosting server and set up a Kubernetes cluster today! Installing Kubernetes Packages and Docker 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-nodeNext, modify your hosts file to ensure connectivity to the other nodes. cat <<EOF>> /etc/hosts10.128.0.27 master-node10.128.0.29 node-1 worker-node-110.128.0.30 node-2 worker-node-2EOFTo confirm that the hosts are set properly, you can perform a ping test on each node. ping 12.345.6.79Next, you will need to disable SELinux: setenforce 0# sed -i --follow-symlinks 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux# rebootThen, 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/tcpfirewall-cmd --permanent --add-port=2379-2380/tcpfirewall-cmd --permanent --add-port=10250/tcpfirewall-cmd --permanent --add-port=10251/tcpfirewall-cmd --permanent --add-port=10252/tcpfirewall-cmd --permanent --add-port=10255/tcpfirewall-cmd –reload# modprobe br_netfilterecho '1' > /proc/sys/net/bridge/bridge-nf-call-iptablesNext, 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=Kubernetesbaseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64enabled=1gpgcheck=1repo_gpgcheck=1gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpgEOFOnce the repository has been added, you can then install Kubeadm and Docker using the following command: yum install kubeadm docker -y Once the services are installed, enable and start them with the following commands:systemctl enable kubeletsystemctl start kubeletsystemctl enable dockersystemctl start docker Initializing Kubernetes Master and Setup Default User First, disable swap using the following command:swapoff -aThen initialize Kubernetes Master with the following command:kubeadm initFrom 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 Now that kubeadm has been initialized, you will next need to set up root as the default user:mkdir -p $HOME/.kubecp -i /etc/kubernetes/admin.conf $HOME/.kube/configchown $(id -u):$(id -g) $HOME/.kube/configTo check if the kubectl service is activated, use the following command:kubectl get nodesNote: 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 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"Once done, you can check the nodes again:kubectl get nodesIf the status comes back as Ready, then that means you have set up your master-node If so, you are done! 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. 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! Share this Article 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 Related Articles How to create a basic profile in Logaholic What is Docker? Working with Docker Containers Ubuntu Server: A General Overview Installable Software Reference How to use ImageMagick How to Install Docker on CentOS 7 Creating a new user in SMF 2.0 Changing a user’s password in SMF 2.0 AbanteCart Maintenance Mode