{"id":6008,"date":"2024-06-04T06:09:06","date_gmt":"2024-06-04T06:09:06","guid":{"rendered":"https:\/\/natsav.com\/blog\/?p=6008"},"modified":"2024-07-18T11:06:39","modified_gmt":"2024-07-18T11:06:39","slug":"how-to-install-kubernetes-cluster-on-centos-7","status":"publish","type":"post","link":"https:\/\/natsav.com\/blog\/how-to-install-kubernetes-cluster-on-centos-7\/","title":{"rendered":"How to install a Kubernetes Cluster on CentOS 7"},"content":{"rendered":"\n<p><strong>How to install a Kubernetes Cluster on CentOS 7<\/strong>, Kubernetes (k8s) is an open-source, cloud-native, container orchestration and management platform. It\u2019s the go-to way to automate the deployment, scaling, and maintenance of containerized applications across different nodes. From service discovery to auto-restarts, and from resource allocation tracking to compute utilization and scaling; a well-configured k8s cluster can manage a lot on its own.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_68_1 counter-hierarchy ez-toc-counter ez-toc-light-blue ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title \" >Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/natsav.com\/blog\/how-to-install-kubernetes-cluster-on-centos-7\/#How_to_install_a_Kubernetes_Cluster_on_CentOS_7_What_is_a_Kubernetes_Cluster\" title=\"How to install a Kubernetes Cluster on CentOS 7 What is a Kubernetes Cluster?\">How to install a Kubernetes Cluster on CentOS 7 What is a Kubernetes Cluster?<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/natsav.com\/blog\/how-to-install-kubernetes-cluster-on-centos-7\/#Prerequisites\" title=\"Prerequisites\">Prerequisites<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/natsav.com\/blog\/how-to-install-kubernetes-cluster-on-centos-7\/#How_to_Install_Kubernetes_on_CentOS_7\" title=\"How to Install Kubernetes on CentOS 7\">How to Install Kubernetes on CentOS 7<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/natsav.com\/blog\/how-to-install-kubernetes-cluster-on-centos-7\/#Step_1_Install_Docker_on_All_CentOS_7_VMs\" title=\"Step 1: Install Docker on All CentOS 7 VMs\">Step 1: Install Docker on All CentOS 7 VMs<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/natsav.com\/blog\/how-to-install-kubernetes-cluster-on-centos-7\/#Step_4_Manage_Docker_Service\" title=\"Step 4: Manage Docker Service\">Step 4: Manage Docker Service<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/natsav.com\/blog\/how-to-install-kubernetes-cluster-on-centos-7\/#Step_2_Set_up_the_Kubernetes_Repository\" title=\"Step 2: Set up the Kubernetes Repository\">Step 2: Set up the Kubernetes Repository<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/natsav.com\/blog\/how-to-install-kubernetes-cluster-on-centos-7\/#Step_3_Install_Kubelet_on_CentOS_7\" title=\"Step 3: Install Kubelet on CentOS 7\">Step 3: Install Kubelet on CentOS 7<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/natsav.com\/blog\/how-to-install-kubernetes-cluster-on-centos-7\/#Step_4_Install_kubeadm_and_kubectl_on_CentOS_7\" title=\"Step 4: Install kubeadm and kubectl on CentOS 7\">Step 4: Install kubeadm and kubectl on CentOS 7<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/natsav.com\/blog\/how-to-install-kubernetes-cluster-on-centos-7\/#Step_5_Set_Hostnames\" title=\"Step 5: Set Hostnames\">Step 5: Set Hostnames<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/natsav.com\/blog\/how-to-install-kubernetes-cluster-on-centos-7\/#Step_6_Disable_SELinux\" title=\"Step 6: Disable SELinux\">Step 6: Disable SELinux<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/natsav.com\/blog\/how-to-install-kubernetes-cluster-on-centos-7\/#Step_7_Add_Firewall_Rules\" title=\"Step 7: Add Firewall Rules\">Step 7: Add Firewall Rules<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/natsav.com\/blog\/how-to-install-kubernetes-cluster-on-centos-7\/#Step_8_Update_iptables_Config\" title=\"Step 8: Update iptables Config\">Step 8: Update iptables Config<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/natsav.com\/blog\/how-to-install-kubernetes-cluster-on-centos-7\/#Step_9_Disable_Swap\" title=\"Step 9: Disable Swap\">Step 9: Disable Swap<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/natsav.com\/blog\/how-to-install-kubernetes-cluster-on-centos-7\/#Deploying_a_Kubernetes_Cluster_on_CentOS_7\" title=\"Deploying a Kubernetes Cluster on CentOS 7\">Deploying a Kubernetes Cluster on CentOS 7<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_to_install_a_Kubernetes_Cluster_on_CentOS_7_What_is_a_Kubernetes_Cluster\"><\/span>How to install a Kubernetes Cluster on CentOS 7 What is a Kubernetes Cluster?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>How to install a Kubernetes Cluster on CentOS 7, A Kubernetes cluster consists of a Master and at least one to several worker node(s). The Master is the virtual machine (VM) that administers all activities on your cluster. A node is a VM that serves as a worker machine in your k8s cluster to host running applications. We strongly recommend you only use VMs, also known as Cloud Servers, to run Kubernetes, not system containers, or VPS, as these can cause issues with k8s.<\/p>\n\n\n\n<p>How to install a Kubernetes Cluster on CentOS 7 A node is comprised of the Kubelet, a container runtime, and the kube-proxy. The k8s installation\u2019s three core modules: Kubelet, kubeadm, and kubectl are agents that control the node and communicate with the Kubernetes Master. Once they have been installed and other configurations done, you will be able to create your first k8s cluster. You can manage this cluster from the command line on your kubemaster node.<\/p>\n\n\n\n<p>Every Kubernetes instance runs on top of a container runtime, which is software responsible for managing container operations. Containers in this case are not virtualized servers but rather a solution that packages code and dependencies to run a single application (service) in an isolated (containerized) environment, essentially disassociating applications from the host machine. <\/p>\n\n\n\n<p>How to install a Kubernetes Cluster on CentOS 7 The most popular and recommended one is Docker, and it\u2019s the one we will use for the purpose of this guide. However, if you want to install a different underlying container runtime, you can harness the power of the Container Runtime Interface and use basically any runtime you want.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"809\" height=\"672\" src=\"https:\/\/i0.wp.com\/natsav.com\/blog\/wp-content\/uploads\/2024\/07\/How-to-install-a-Kubernetes-Cluster-on-CentOS-7.png?resize=809%2C672&#038;ssl=1\" alt=\"How to install a Kubernetes Cluster on CentOS 7\" class=\"wp-image-7068\" srcset=\"https:\/\/i0.wp.com\/natsav.com\/blog\/wp-content\/uploads\/2024\/07\/How-to-install-a-Kubernetes-Cluster-on-CentOS-7.png?w=809&amp;ssl=1 809w, https:\/\/i0.wp.com\/natsav.com\/blog\/wp-content\/uploads\/2024\/07\/How-to-install-a-Kubernetes-Cluster-on-CentOS-7.png?resize=300%2C249&amp;ssl=1 300w, https:\/\/i0.wp.com\/natsav.com\/blog\/wp-content\/uploads\/2024\/07\/How-to-install-a-Kubernetes-Cluster-on-CentOS-7.png?resize=768%2C638&amp;ssl=1 768w, https:\/\/i0.wp.com\/natsav.com\/blog\/wp-content\/uploads\/2024\/07\/How-to-install-a-Kubernetes-Cluster-on-CentOS-7.png?resize=150%2C125&amp;ssl=1 150w\" sizes=\"(max-width: 809px) 100vw, 809px\" data-recalc-dims=\"1\" \/><\/figure><\/div>\n\n\n<p>Kubernetes groups containers into pods, its most basic operational unit, which are basically just groups of containers running on the same node. Pods are connected over a network and share storage resources.<\/p>\n\n\n\n<p>How to install a Kubernetes Cluster on CentOS 7 In order to connect your nodes or VMs and make them private, make sure to choose a hosting company that provides a Virtual Local Area Network (VLAN) with their VMs. We offer a VLAN add-on to our Cloud Servers for R200 per month.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Prerequisites\"><\/span>Prerequisites<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ul>\n<li class=\"has-medium-font-size\">Multiple CentOS 7 VMs (Cloud Servers) to house the Master and worker nodes.<\/li>\n\n\n\n<li class=\"has-medium-font-size\">Docker or any other container runtime.<\/li>\n\n\n\n<li class=\"has-medium-font-size\">User with sudo or root privileges on every server.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_to_Install_Kubernetes_on_CentOS_7\"><\/span>How to Install Kubernetes on CentOS 7<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>How to install a Kubernetes Cluster on CentOS 7 Installing Kubernetes on CentOS 7 involves several steps, each crucial for a successful setup. Let&#8217;s dive into the detailed process, ensuring we cover each step with necessary commands and checks.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step_1_Install_Docker_on_All_CentOS_7_VMs\"><\/span>Step 1: Install Docker on All CentOS 7 VMs<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ol>\n<li><strong><strong>Update the Package Database<\/strong> <\/strong>Begin by updating your package database:<\/li>\n<\/ol>\n\n\n\n<ol><\/ol>\n\n\n\n<p><strong>Code:-<\/strong><\/p>\n\n\n\n<p><strong>sudo yum update -y<\/strong><\/p>\n\n\n\n<p>2. <strong>Install the Dependencies<\/strong> Ensure you have the necessary dependencies installed:<\/p>\n\n\n\n<p><strong>Code:-<\/strong><\/p>\n\n\n\n<p><strong>sudo yum install -y yum-utils device-mapper-persistent-data lvm2<\/strong><\/p>\n\n\n\n<p>3. <strong>Add and Enable the Official Docker Repository to CentOS 7<\/strong> Add the Docker repository and enable it:<\/p>\n\n\n\n<p><strong>Code:-<\/strong><\/p>\n\n\n\n<p><strong>sudo yum-config-manager &#8211;add-repo https:\/\/download.docker.com\/linux\/centos\/docker-ce.repo<\/strong><\/p>\n\n\n\n<p>4. <strong>Install the Latest Docker Version on CentOS 7<\/strong> Install Docker with the following command:<\/p>\n\n\n\n<p><strong>Code:-<\/strong><\/p>\n\n\n\n<p><strong>sudo yum install -y docker-ce<\/strong><\/p>\n\n\n\n<p>5. <strong>Verify Installation<\/strong> A successful installation output will be concluded with &#8220;Complete!&#8221;.<\/p>\n\n\n\n<p>6. <strong>Accept the GPG Key<\/strong> You may be prompted to accept the GPG key to verify the fingerprint matches. The prompt will look similar to this:<\/p>\n\n\n\n<p><strong>Code:-<\/strong><\/p>\n\n\n\n<p><strong>Is this ok [y\/N]: y<\/strong><\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"538\" src=\"https:\/\/i0.wp.com\/natsav.com\/blog\/wp-content\/uploads\/2024\/07\/How-to-install-a-Kubernetes-Cluster-on-CentOS-7-natsav.com_-1024x538.png?resize=1024%2C538&#038;ssl=1\" alt=\"How to install a Kubernetes Cluster on CentOS 7\" class=\"wp-image-7070\" srcset=\"https:\/\/i0.wp.com\/natsav.com\/blog\/wp-content\/uploads\/2024\/07\/How-to-install-a-Kubernetes-Cluster-on-CentOS-7-natsav.com_.png?resize=1024%2C538&amp;ssl=1 1024w, https:\/\/i0.wp.com\/natsav.com\/blog\/wp-content\/uploads\/2024\/07\/How-to-install-a-Kubernetes-Cluster-on-CentOS-7-natsav.com_.png?resize=300%2C158&amp;ssl=1 300w, https:\/\/i0.wp.com\/natsav.com\/blog\/wp-content\/uploads\/2024\/07\/How-to-install-a-Kubernetes-Cluster-on-CentOS-7-natsav.com_.png?resize=768%2C403&amp;ssl=1 768w, https:\/\/i0.wp.com\/natsav.com\/blog\/wp-content\/uploads\/2024\/07\/How-to-install-a-Kubernetes-Cluster-on-CentOS-7-natsav.com_.png?resize=150%2C79&amp;ssl=1 150w, https:\/\/i0.wp.com\/natsav.com\/blog\/wp-content\/uploads\/2024\/07\/How-to-install-a-Kubernetes-Cluster-on-CentOS-7-natsav.com_.png?w=1070&amp;ssl=1 1070w\" sizes=\"(max-width: 1000px) 100vw, 1000px\" data-recalc-dims=\"1\" \/><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step_4_Manage_Docker_Service\"><\/span>Step 4: Manage Docker Service<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Now that Docker is installed, we need to start and enable the Docker service:<\/p>\n\n\n\n<ol>\n<li><strong>Start and Enable Docker<\/strong>bashCopy code<code>sudo systemctl start docker sudo systemctl enable docker<\/code><\/li>\n\n\n\n<li><strong>Confirm Docker is Active and Running<\/strong>bashCopy code<code>sudo systemctl status docker<\/code><\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step_2_Set_up_the_Kubernetes_Repository\"><\/span>Step 2: Set up the Kubernetes Repository<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Since Kubernetes packages aren&#8217;t available in the official CentOS 7 repositories, we&#8217;ll add a new repository file.<\/p>\n\n\n\n<ol>\n<li class=\"has-medium-font-size\"><strong>Create and Edit the Repository File<\/strong>bashCopy code<code>sudo vi \/etc\/yum.repos.d\/kubernetes.repo<\/code><\/li>\n\n\n\n<li class=\"has-medium-font-size\"><strong>Enter Insert Mode and Paste Contents<\/strong> Press <code>i<\/code> to enter insert mode, then paste the following:plaintextCopy code<code>[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<\/code><\/li>\n\n\n\n<li class=\"has-medium-font-size\"><strong>Save and Exit the File<\/strong> Press <code>Esc<\/code>, then type <code>:x<\/code> and press <code>Enter<\/code>.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step_3_Install_Kubelet_on_CentOS_7\"><\/span>Step 3: Install Kubelet on CentOS 7<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>The first core module to install is Kubelet.<\/p>\n\n\n\n<ol>\n<li class=\"has-medium-font-size\"><strong>Install Kubelet<\/strong>bashCopy code<code>sudo yum install -y kubelet<\/code><\/li>\n\n\n\n<li class=\"has-medium-font-size\"><strong>Verify Installation<\/strong> Successful installation will end with &#8220;Complete!&#8221;.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step_4_Install_kubeadm_and_kubectl_on_CentOS_7\"><\/span>Step 4: Install kubeadm and kubectl on CentOS 7<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Install kubeadm, which also installs kubectl as a dependency.<\/p>\n\n\n\n<ol>\n<li class=\"has-medium-font-size\"><strong>Install kubeadm<\/strong> bash <strong>Copy code<\/strong> <code>sudo yum install -y kubeadm<\/code><\/li>\n\n\n\n<li class=\"has-medium-font-size\"><strong>Verify Installation<\/strong> Successful installation should result in the following output:plaintextCopy code<code>Complete!<\/code><\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step_5_Set_Hostnames\"><\/span>Step 5: Set Hostnames<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Update hostnames on your master node.<\/p>\n\n\n\n<ol>\n<li class=\"has-medium-font-size\"><strong>Update Hostname<\/strong> bash <strong>Copy code<\/strong> <code>sudo hostnamectl set-hostname master-node<\/code><\/li>\n\n\n\n<li class=\"has-medium-font-size\"><strong>Edit Hostnames for Worker Nodes<\/strong> Open the <code>\/etc\/hosts<\/code> file and add\/edit the hostnames for your worker nodes.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step_6_Disable_SELinux\"><\/span>Step 6: Disable SELinux<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Set SELinux to permissive mode.<\/p>\n\n\n\n<ol>\n<li class=\"has-medium-font-size\"><strong>Disable SELinux<\/strong> bash <strong>Copy code<\/strong> <code>sudo setenforce 0 sudo sed -i 's\/^SELINUX=enforcing$\/SELINUX=permissive\/' \/etc\/selinux\/config<\/code><\/li>\n\n\n\n<li class=\"has-medium-font-size\"><strong>Reboot for Changes to Take Effect<\/strong> bash <strong>Copy code<\/strong> <code>sudo reboot<\/code><\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step_7_Add_Firewall_Rules\"><\/span>Step 7: Add Firewall Rules<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Add rules to the firewall on the master node to allow communication.<\/p>\n\n\n\n<ol>\n<li class=\"has-medium-font-size\"><strong>Add Rules<\/strong> bash <strong>Copy code<\/strong> <code>sudo firewall-cmd --permanent --add-port=6443\/tcp sudo firewall-cmd --permanent --add-port=2379-2380\/tcp sudo firewall-cmd --permanent --add-port=10250\/tcp sudo firewall-cmd --permanent --add-port=10251\/tcp sudo firewall-cmd --permanent --add-port=10252\/tcp sudo firewall-cmd --permanent --add-port=10255\/tcp sudo firewall-cmd --reload<\/code><\/li>\n\n\n\n<li class=\"has-medium-font-size\"><strong>Verify Output<\/strong> Each command should output &#8220;success&#8221;.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step_8_Update_iptables_Config\"><\/span>Step 8: Update iptables Config<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Update the sysctl file for proper packet processing.<\/p>\n\n\n\n<ol>\n<li class=\"has-medium-font-size\"><strong>Update Config<\/strong> bash <strong>Copy code<\/strong> <code>sudo modprobe br_netfilter echo '1' | sudo tee \/proc\/sys\/net\/bridge\/bridge-nf-call-iptables<\/code><\/li>\n\n\n\n<li class=\"has-medium-font-size\"><strong>Verify Output<\/strong> Ensure the output is: plain text <strong>Copy code<\/strong> <code>1<\/code><\/li>\n<\/ol>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"890\" height=\"630\" src=\"https:\/\/i0.wp.com\/natsav.com\/blog\/wp-content\/uploads\/2024\/07\/How-to-install-a-Kubernetes-Cluster-on-CentOS-7-natsav.com1_.png?resize=890%2C630&#038;ssl=1\" alt=\"How to install a Kubernetes Cluster on CentOS 7\" class=\"wp-image-7073\" srcset=\"https:\/\/i0.wp.com\/natsav.com\/blog\/wp-content\/uploads\/2024\/07\/How-to-install-a-Kubernetes-Cluster-on-CentOS-7-natsav.com1_.png?w=890&amp;ssl=1 890w, https:\/\/i0.wp.com\/natsav.com\/blog\/wp-content\/uploads\/2024\/07\/How-to-install-a-Kubernetes-Cluster-on-CentOS-7-natsav.com1_.png?resize=300%2C212&amp;ssl=1 300w, https:\/\/i0.wp.com\/natsav.com\/blog\/wp-content\/uploads\/2024\/07\/How-to-install-a-Kubernetes-Cluster-on-CentOS-7-natsav.com1_.png?resize=768%2C544&amp;ssl=1 768w, https:\/\/i0.wp.com\/natsav.com\/blog\/wp-content\/uploads\/2024\/07\/How-to-install-a-Kubernetes-Cluster-on-CentOS-7-natsav.com1_.png?resize=150%2C106&amp;ssl=1 150w\" sizes=\"(max-width: 890px) 100vw, 890px\" data-recalc-dims=\"1\" \/><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step_9_Disable_Swap\"><\/span>Step 9: Disable Swap<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Disable swap on all VMs.<\/p>\n\n\n\n<ol>\n<li class=\"has-medium-font-size\"><strong>Disable Swap<\/strong> bash <strong>Copy code<\/strong> <code>sudo swapoff -a sudo sed -i '\/ swap \/ s\/^\/#\/' \/etc\/fstab<\/code><\/li>\n<\/ol>\n\n\n\n<p>This concludes the installation and configuration of Kubernetes on CentOS 7. You can now proceed with deploying your Kubernetes cluster.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Deploying_a_Kubernetes_Cluster_on_CentOS_7\"><\/span>Deploying a Kubernetes Cluster on CentOS 7<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p><strong>Step 1: kubeadm Initialization<\/strong><\/p>\n\n\n\n<p>To launch a new Kubernetes cluster instance, you need to initialize <code>kubeadm<\/code>. Use the following command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>bash Copy code<\/strong> <code>kubeadm init<br><\/code><\/pre>\n\n\n\n<p><strong>How to install a Kubernetes Cluster on CentOS 7<\/strong> This command may take several minutes to execute. Upon success, you should get logs similar to those in this screenshot:<\/p>\n\n\n\n<p>You will also get an auto-generated command at the end of the output. Copy the text following the line &#8220;Then you can join any number of worker nodes by running the following on each as root:&#8221; as highlighted in the above screenshot and save it somewhere safe. We will use this to add worker nodes to our cluster.<\/p>\n\n\n\n<p><strong>Note:<\/strong> If you forgot to copy the command, or have misplaced it, don\u2019t worry. You can retrieve it again by entering the following command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>bash Copy code<\/strong> <code>kubeadm token create --print-join-command<br><\/code><\/pre>\n\n\n\n<p><strong>Step 2: Create Required Directories and Start Managing Kubernetes Cluster<\/strong><\/p>\n\n\n\n<p>In order to start managing your cluster, you need to create a directory and assume ownership. Run the following commands as a regular user:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>bash Copy code<\/strong> <code>mkdir -p $HOME\/.kube<br>sudo cp -i \/etc\/kubernetes\/admin.conf $HOME\/.kube\/config<br>sudo chown $(id -u):$(id -g) $HOME\/.kube\/config<br><\/code><\/pre>\n\n\n\n<p><strong>Step 3: Set Up Pod Network for the Cluster<\/strong><\/p>\n\n\n\n<p>Pods within a cluster are connected via the pod network. At this point, it\u2019s not working. This can be verified by entering the following two commands:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>bash Copy code<\/strong> <code>kubectl get nodes<br>kubectl get pods --all-namespaces<br><\/code><\/pre>\n\n\n\n<p>How to install a Kubernetes Cluster on CentOS 7 As you can see, the status of the master node is <code>NotReady<\/code>. The CoreDNS service is also not running. To fix this, run the following commands:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>bash Copy code<\/strong> <code>kubectl apply -f https:\/\/docs.projectcalico.org\/manifests\/calico.yaml<br><\/code><\/pre>\n\n\n\n<p>How to install a Kubernetes Cluster on CentOS 7 You should get the following output:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">plaintext <strong>Copy code<\/strong> <code>configmap\/calico-config created<br>customresourcedefinition.apiextensions.k8s.io\/bgpconfigurations.crd.projectcalico.org created<br>...<br><\/code><\/pre>\n\n\n\n<p>And now if you verify the statuses of your node and CoreDNS service, you should get <code>Ready<\/code> and <code>Running<\/code> like seen below:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>bash Copy code<\/strong> <code>kubectl get nodes<br>kubectl get pods --all-namespaces<br><\/code><\/pre>\n\n\n\n<p><strong>Step 4: Add Nodes to Your Cluster<\/strong><\/p>\n\n\n\n<p>How to install a Kubernetes Cluster on CentOS 7 As a final step, you need to add worker nodes to your cluster. We will use the <code>kubeadm join<\/code> auto-generated token from Step 1 here. Run your own version of the following command on all of the worker node VMs:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>bash Copy code <\/strong><code>kubeadm join &lt;master-node-ip>:6443 --token &lt;token> --discovery-token-ca-cert-hash sha256:&lt;hash><br><\/code><\/pre>\n\n\n\n<p>On successful addition, you should get the following output:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">plaintext <strong>Copy code<\/strong> <code>This node has joined the cluster:<br>...<br><\/code><\/pre>\n\n\n\n<p>Running the following command on the master node should show your newly added node:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>bash Copy code<\/strong> <code>kubectl get nodes<br><\/code><\/pre>\n\n\n\n<p>How to install a Kubernetes Cluster on CentOS 7 To set the role for your worker node, use the following command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>bash Copy code<\/strong> <code>kubectl label node &lt;node-name> node-role.kubernetes.io\/worker=worker<\/code><\/pre>\n\n\n\n<p><strong>Read More<\/strong><\/p>\n\n\n\n<p><strong><a href=\"https:\/\/natsav.com\/blog\/what-is-a-managed-vps-in-2024\/\" target=\"_blank\" rel=\"noreferrer noopener\">What is a Managed VPS? Discover Benefits &amp; Features<\/a><\/strong><\/p>\n\n\n\n<p><strong><a href=\"https:\/\/natsav.com\/blog\/how-to-backup-restore-website-using-cpanel\/\" target=\"_blank\" rel=\"noreferrer noopener\">How to Backup &amp; Restore Website Using cPanel.<\/a><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to install a Kubernetes Cluster on CentOS 7, Kubernetes (k8s) is an open-source, cloud-native, container orchestration and management platform. It\u2019s the go-to way to automate the deployment, scaling, and maintenance of containerized applications across different nodes. From service discovery to auto-restarts, and from resource allocation tracking to compute utilization and scaling; a well-configured k8s [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":5995,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[267],"tags":[],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"https:\/\/i0.wp.com\/natsav.com\/blog\/wp-content\/uploads\/2024\/03\/kubernet-e1711108902286.png?fit=641%2C350&ssl=1","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/posts\/6008"}],"collection":[{"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/comments?post=6008"}],"version-history":[{"count":10,"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/posts\/6008\/revisions"}],"predecessor-version":[{"id":7076,"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/posts\/6008\/revisions\/7076"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/media\/5995"}],"wp:attachment":[{"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/media?parent=6008"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/categories?post=6008"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/tags?post=6008"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}