{"id":12,"date":"2022-12-31T07:28:51","date_gmt":"2022-12-31T07:28:51","guid":{"rendered":"https:\/\/cloudtechs.club\/?page_id=12"},"modified":"2024-07-03T02:36:59","modified_gmt":"2024-07-03T02:36:59","slug":"kubernetes-installation","status":"publish","type":"page","link":"https:\/\/cloudtechs.club\/index.php\/kubernetes-installation\/","title":{"rendered":"Kubernetes Installation"},"content":{"rendered":"\n<p><strong>Kubernetes Installation<\/strong><\/p>\n\n\n\n<p>Hey guys welcome back\u2026! In this blog , I will show how to setting up Kubernetes home lab setup for practice for this I will be using oracle VM virtual box manager and centos operating system to deploy one master and worker node.<\/p>\n\n\n\n<p>You need below components to setup the lab.<\/p>\n\n\n\n<ol class=\"wp-block-list\" style=\"list-style-type:1\">\n<li>Oracle VM virtual box manager : <a href=\"https:\/\/www.virtualbox.org\/wiki\/Downloads\">https:\/\/www.virtualbox.org\/wiki\/Downloads<\/a><\/li>\n\n\n\n<li>MobaXterm : <a href=\"https:\/\/mobaxterm.mobatek.net\/download.html\">https:\/\/mobaxterm.mobatek.net\/download.html<\/a><\/li>\n\n\n\n<li>Centos ISO: <a href=\"http:\/\/isoredirect.centos.org\/centos\/7\/isos\/x86_64\/\">http:\/\/isoredirect.centos.org\/centos\/7\/isos\/x86_64\/<\/a><\/li>\n<\/ol>\n\n\n\n<p><strong>Note : <\/strong>Minimum requirement master and worker nodes must have 2 virtual CPUs and 2-4 GB RAM<\/p>\n\n\n\n<p>Let&#8217;s get started to setup K8s cluster \ud83d\ude42<\/p>\n\n\n\n<p><strong>Step 1: Name first master and worker nodes:<\/strong><\/p>\n\n\n\n<p><strong>on Masternode<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># hostnamectl&nbsp;&nbsp; set-hostname&nbsp; masternode01.lab.local <\/pre>\n\n\n\n<p><strong>on Worker node<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># hostnamectl&nbsp;&nbsp; set-hostname&nbsp; workernode01.lab.local\n# hostnamectl&nbsp;&nbsp; set-hostname&nbsp; workernode02.lab.local<\/pre>\n\n\n\n<p>Now check hostname at runtime using following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># hostnamectl<\/code><\/pre>\n\n\n\n<p><strong>Step 2: Open a file on both VM&#8217;s and add hostnames (DNS Alias ). Perform ping test.<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">vi \/etc\/hosts\n10.197.163.215&nbsp;&nbsp;&nbsp; masternode01.lab.local\n10.197.163.218&nbsp;&nbsp;&nbsp; workernode01.lab.local\n10.197.163.214&nbsp;&nbsp;&nbsp; workernode02.lab.local<\/pre>\n\n\n\n<p><strong>Step 3: Disable SELinux<\/strong><\/p>\n\n\n\n<p>The containers need to access the host filesystem. SELinux needs to be set to permissive mode, which effectively disables its security functions.<\/p>\n\n\n\n<p>Use following commands to disable SELinux:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo setenforce 0\nsed -i 's\/^SELINUX=enforcing$\/SELINUX=permissive\/' \/etc\/selinux\/config<\/pre>\n\n\n\n<p><strong>Step 4: Disable SWAP<\/strong><\/p>\n\n\n\n<p>Check swap off on master and worker nodes. Reason being k8s says don&#8217;t want to store process on swap memory need to be run time memory like physical memory.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo sed -i '\/swap\/d' \/etc\/fstab\nsudo swapoff -a<\/pre>\n\n\n\n<p>To disable swap permanent, modify file \/etc\/fstab on both master and worker nodes.<\/p>\n\n\n\n<p><strong>Step 5: Update iptable settings<\/strong><\/p>\n\n\n\n<p>As a requirement for your Linux Node\u2019s iptables to correctly see bridged traffic, you should ensure net.bridge.bridge-nf-call-iptables is set to 1 in your sysctl config, e.g.<\/p>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<pre class=\"wp-block-preformatted\">cat &lt;&lt;EOF &gt; \/etc\/sysctl.d\/k8s.conf\nnet.bridge.bridge-nf-call-ip6tables = 1\nnet.bridge.bridge-nf-call-iptables = 1\nEOF<\/pre>\n<\/div><\/div>\n\n\n\n<pre class=\"wp-block-preformatted\">sysctl --system<\/pre>\n\n\n\n<p>Make sure that the br_netfilter module is loaded before this step. This can be done by running lsmod | grep br_netfilter. To load it explicitly call modprobe br_netfilter.<\/p>\n\n\n\n<p>For more details please see the Network Plugin Requirements page.<\/p>\n\n\n\n<p>Link: <a href=\"https:\/\/kubernetes.io\/docs\/concepts\/extend-kubernetes\/compute-storage-net\/network-plugins\/#network-plugin-requirements\">https:\/\/kubernetes.io\/docs\/concepts\/extend-kubernetes\/compute-storage-net\/network-plugins\/#network-plugin-requirements<\/a><\/p>\n\n\n\n<p><strong>Step 6: Configure Firewall<\/strong><\/p>\n\n\n\n<p>The nodes, containers, and pods need to be able to communicate across the cluster to perform their functions. Firewalld is enabled in CentOS by default on the front-end. Add the following ports by entering the listed commands.<\/p>\n\n\n\n<p>Please note for home lab environment , if you want just disable the firewall and don\u2019t need to add the ports to firewall.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">systemctl status firewalld\nsystemctl stop firewalld<\/pre>\n\n\n\n<p>If you are configuring this within production perform below steps as security will be primary focus while performing the installation.<\/p>\n\n\n\n<p>On the Master Node enter:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo firewall-cmd --permanent --add-port=6443\/tcp\nsudo firewall-cmd --permanent --add-port=2379-2380\/tcp\nsudo firewall-cmd --permanent --add-port=10250\/tcp\nsudo firewall-cmd --permanent --add-port=10251\/tcp\nsudo firewall-cmd --permanent --add-port=10252\/tcp\nsudo firewall-cmd --permanent --add-port=10255\/tcp\nsudo firewall-cmd \u2013reload<\/pre>\n\n\n\n<p>Each time a port is added the system confirms with a \u2018success\u2019 message.<\/p>\n\n\n\n<p>Enter the following commands on each worker node:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo firewall-cmd --permanent --add-port=10251\/tcp\nsudo firewall-cmd --permanent --add-port=10255\/tcp\nfirewall-cmd \u2013reload<\/pre>\n\n\n\n<p><strong>Step 7: Install Docker Engine on Master and worker nodes<\/strong><\/p>\n\n\n\n<p>Install using the repository<\/p>\n\n\n\n<p>Before you install Docker Engine for the first time on a new host machine, you need to set up the Docker repository. Afterward, you can install and update Docker from the repository.<\/p>\n\n\n\n<p><strong>Set up the repository<\/strong><\/p>\n\n\n\n<p>Install the yum-utils package (which provides the yum-config-manager utility) and set up the repository.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo dnf check-update\nsudo dnf upgrade\nsudo dnf config-manager --add-repo=https:\/\/download.docker.com\/linux\/centos\/docker-ce.repo<\/pre>\n\n\n\n<p><strong>Install Docker Engine<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo dnf install docker-ce --nobest --allowerasing -y<\/code><\/pre>\n\n\n\n<p>This command installs Docker, but it doesn\u2019t start Docker. It also creates a docker group, however, it doesn\u2019t add any users to the group by default.<\/p>\n\n\n\n<p><strong>Start and enable Docker Engine.<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">systemctl start docker\nsystemctl enable docker<\/pre>\n\n\n\n<p><strong>Step 8: Configure Kubernetes Repository<\/strong><\/p>\n\n\n\n<p>This step needs to be performed on the Master Node, and each Worker Node you plan on utilizing for your container setup. Enter the following command to retrieve the Kubernetes repositories.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">cat &lt;&lt;EOF &gt; \/etc\/yum.repos.d\/kubernetes.repo\n[kubernetes]\nname=Kubernetes\nbaseurl=https:\/\/packages.cloud.google.com\/yum\/repos\/kubernetes-el7-x86_64\nenabled=1\ngpgcheck=1\nrepo_gpgcheck=1\ngpgkey=https:\/\/packages.cloud.google.com\/yum\/doc\/yum-key.gpg https:\/\/packages.cloud.google.com\/yum\/doc\/rpm-package-key.gpg\nEOF<\/pre>\n\n\n\n<p><strong>Step 9: Install kubelet, kubeadm, and kubectl<\/strong><\/p>\n\n\n\n<p>These 3 basic packages are required to be able to use Kubernetes. Install the following package(s) on each node:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes \nsystemctl enable kubelet\nsystemctl start kubelet<\/pre>\n\n\n\n<p><strong>How to Deploy a Kubernetes Cluster:<\/strong><\/p>\n\n\n\n<p><strong>Step 1: Create Cluster with kubeadm<\/strong><\/p>\n\n\n\n<p>Initialize a cluster by executing the following command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo kubeadm init --pod-network-cidr=10.244.0.0\/16<\/pre>\n\n\n\n<p>The process might take several minutes to complete based on network speed. Once this command finishes, it displays a kubeadm join message. Make a note of the entry and use it to join worker nodes to the cluster at a later stage.<\/p>\n\n\n\n<p>Note: This tutorial uses the flannel virtual network add-on. The 10.244.0.0\/16 network value reflects the configuration of the kube-flannel.yml file. If you plan to use a different third-party provider, change the &#8211;pod-network-cidr value to match your provider\u2019s requirements.<\/p>\n\n\n\n<p><strong>Step 2: Manage Cluster as Regular User<\/strong><\/p>\n\n\n\n<p>To start using the cluster you need to run it as a regular user by typing:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mkdir -p $HOME\/.kube\nsudo cp -i \/etc\/kubernetes\/admin.conf $HOME\/.kube\/config\nsudo chown $(id -u):$(id -g) $HOME\/.kube\/config<\/pre>\n\n\n\n<p><strong>Step 3: Set Up Pod Network<\/strong><\/p>\n\n\n\n<p>A Pod Network allows nodes within the cluster to communicate. There are several available Kubernetes networking options. Use the following command to install the flannel pod network add-on:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo kubectl apply -f <a href=\"https:\/\/raw\">https:\/\/raw<\/a>.githubusercontent.com\/coreos\/flannel\/master\/Documentation\/kube-flannel.yml<\/pre>\n\n\n\n<p>If you decide to use flannel, edit your firewall rules to allow traffic for the flannel default port 8285.<\/p>\n\n\n\n<p><strong>Step 4: Check Status of Cluster<\/strong><\/p>\n\n\n\n<p>Check the status of the nodes by entering the following command on the master server:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo kubectl get nodes<\/pre>\n\n\n\n<p>Once a pod network has been installed, you can confirm that it is working by checking that the CoreDNS pod is running by typing:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo kubectl get pods --all-namespaces<\/pre>\n\n\n\n<p><strong>Step 5: Join Worker Node to Cluster<\/strong><\/p>\n\n\n\n<p>As indicated in Step 1, you can use the kubeadm join command on each worker node to connect it to the cluster.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">kubeadm join 10.197.163.215:6443 --token opcdjc.m6o797w9f7ft2jzl \\ --discovery-token-ca-cert-hash sha256:9fc7728940fb351311507bff3fa0970250ed309e5975f588ec702f3ba2ff0050<\/pre>\n\n\n\n<p>Replace the codes with the ones from your master server. Repeat this action for each worker node on your cluster.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Kubernetes Installation Hey guys welcome back\u2026! In this blog , I will show how to setting up Kubernetes home lab setup for practice for this I will be using oracle VM virtual box manager and cent","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-12","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/cloudtechs.club\/index.php\/wp-json\/wp\/v2\/pages\/12","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cloudtechs.club\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/cloudtechs.club\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/cloudtechs.club\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cloudtechs.club\/index.php\/wp-json\/wp\/v2\/comments?post=12"}],"version-history":[{"count":6,"href":"https:\/\/cloudtechs.club\/index.php\/wp-json\/wp\/v2\/pages\/12\/revisions"}],"predecessor-version":[{"id":396,"href":"https:\/\/cloudtechs.club\/index.php\/wp-json\/wp\/v2\/pages\/12\/revisions\/396"}],"wp:attachment":[{"href":"https:\/\/cloudtechs.club\/index.php\/wp-json\/wp\/v2\/media?parent=12"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}