<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Sai Simha Reddy</title>
    <description>The latest articles on DEV Community by Sai Simha Reddy (@simha4820).</description>
    <link>https://dev.to/simha4820</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1345694%2Ff3052503-3f21-4e8c-a887-9a3208d3c275.png</url>
      <title>DEV Community: Sai Simha Reddy</title>
      <link>https://dev.to/simha4820</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/simha4820"/>
    <language>en</language>
    <item>
      <title>Mastering On-Premise Kubernetes: A Comprehensive Guide to Setting Up Your Own Cluster</title>
      <dc:creator>Sai Simha Reddy</dc:creator>
      <pubDate>Mon, 11 Mar 2024 12:55:38 +0000</pubDate>
      <link>https://dev.to/simha4820/mastering-on-premise-kubernetes-a-comprehensive-guide-to-setting-up-your-own-cluster-5dk9</link>
      <guid>https://dev.to/simha4820/mastering-on-premise-kubernetes-a-comprehensive-guide-to-setting-up-your-own-cluster-5dk9</guid>
      <description>&lt;p&gt;Welcome to our guide on setting up a Kubernetes cluster on-premises! In this blog, we'll walk you through the process of implementing a Kubernetes cluster using one master node and three worker nodes, all running on Rocky Linux virtual servers. By following along, you'll gain the skills and knowledge needed to deploy and manage your own Kubernetes infrastructure in an on-premises environment. Let's dive in!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Before getting started&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is Kubernetes?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Before we dive into the nitty-gritty of setting up our Kubernetes cluster on-premises, let's take a moment to understand what Kubernetes is and why it's such a powerful tool for container orchestration.&lt;/p&gt;

&lt;p&gt;Kubernetes, often abbreviated as K8s, is an open-source platform designed to automate the deployment, scaling, and management of containerized applications. Originally developed by Google, Kubernetes has quickly become the de facto standard for container orchestration, offering features such as automated scaling, load balancing, and self-healing capabilities.&lt;/p&gt;

&lt;p&gt;With Kubernetes, you can abstract away the underlying infrastructure and focus on deploying your applications in a consistent and efficient manner, regardless of whether they're running on-premises, in the cloud, or in a hybrid environment.&lt;br&gt;
Now that we have a basic understanding of Kubernetes, let's roll up our sleeves and get started with setting up our on-premises cluster using Rocky Linux virtual servers.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdxgxq0ghsbvqni48206o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdxgxq0ghsbvqni48206o.png" alt="Image description" width="667" height="386"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let's get started:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pre-requisites:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;4 Rocky Linux Servers.(I am using Rocky Linux 9 flavour in this blog).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let's Start:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Set up the hostnames of all 4 servers in "/etc/hosts" file&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;10.168.100.21   master.kubernetes.com&lt;br&gt;
10.168.100.22   worker1.kubernetes.com&lt;br&gt;
10.168.100.23   worker2.kubernetes.com&lt;br&gt;
10.168.100.24   worker3.kubernetes.com&lt;/p&gt;

&lt;p&gt;(Note: Replace hostname with your original hostnames, i have used kubernetes.com just for demo purpose)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Disable firewall service in all four nodes&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if you are using firewalld service:

  systemctl stop firewalld
  systemctl disable firewalld

if you are using iptables service:

  systemctl stop iptables
  systemctl disable iptables
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;3. Add container modules to the list of kernel modules&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; sudo tee /etc/modules-load.d/containerd.conf &amp;lt;&amp;lt;EOF
 overlay
 br_netfilter
 EOF
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;4. Manually load kernel modules into the Linux kernel at &lt;br&gt;
     runtime, without needing to reboot the system&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; sudo modprobe overlay
 sudo modprobe br_netfilter
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;5. Essential Network Configuration for Kubernetes: Enabling Advanced Networking Features&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; sudo tee /etc/sysctl.d/kubernetes.conf &amp;lt;&amp;lt;EOF
 net.bridge.bridge-nf-call-ip6tables = 1
 net.bridge.bridge-nf-call-iptables = 1
 net.ipv4.ip_forward = 1
 EOF

 sudo sysctl --system
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;6. Deactivate all swap partitions or swap files that are currently in use&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; swapoff -a
 sudo sed -i '/swap/ s/^/#/' /etc/fstab
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;7. Disable SELINUX&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; sudo sed -i 's/^SELINUX=.*/SELINUX=disabled/' 
 /etc/selinux/config.bkp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;*&lt;em&gt;8. Reboot the all nodes once to apply the above changes *&lt;/em&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; reboot
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;9. Adding Docker Repository to CentOS Yum Configuration in all the nodes&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; yum-config-manager --add-repo
 https://download.docker.com/linux/centos/docker-ce.repo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;10. Download and install the container run time in all the nodes&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  yum install -y docker-ce docker-ce-cli containerd.io
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;11. Configuring Containerd to Use systemd Cgroups&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  containerd config default | sudo tee 
  /etc/containerd/config.toml &amp;gt;/dev/null 2&amp;gt;&amp;amp;1

 sudo sed -i 's/SystemdCgroup \= false/SystemdCgroup \= 
 true/g' /etc/containerd/config.toml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;12. Start and enable the container run time service&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  systemctl start containerd
  systemctl enable containerd

  systemctl start docker
  systemctl enable docker
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;13. Adding Kubernetes Repository to CentOS Yum Configuration in all the nodes&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;cat &amp;lt;&amp;lt;EOF | sudo tee /etc/yum.repos.d/kubernetes.repo&lt;br&gt;
[kubernetes]&lt;br&gt;
name=Kubernetes&lt;br&gt;
baseurl=&lt;a href="https://pkgs.k8s.io/core:/stable:/v1.29/rpm/"&gt;https://pkgs.k8s.io/core:/stable:/v1.29/rpm/&lt;/a&gt;&lt;br&gt;
enabled=1&lt;br&gt;
gpgcheck=1&lt;br&gt;
gpgkey=&lt;a href="https://pkgs.k8s.io/core:/stable:/v1.29/rpm/repodata/repomd.xml.key"&gt;https://pkgs.k8s.io/core:/stable:/v1.29/rpm/repodata/repomd.xml.key&lt;/a&gt;&lt;br&gt;
exclude=kubelet kubeadm kubectl cri-tools kubernetes-cni&lt;br&gt;
EOF&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;14. Download and install kubelet in all the nodes&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; yum install -y kubelet kubeadm kubectl -- 
 disableexcludes=kubernetes
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;15. Start and enable the kubelet service&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; systemctl start kubelet
 systemctl eanble kubelet
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;16. Initializing a Kubernetes Cluster with Custom Configurations(Run the below command in master node)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;kubeadm init --apiserver-advertise-address=10.168.100.21 -- &lt;br&gt;
 pod-network-cidr=172.100.0.0/16&lt;/p&gt;

&lt;p&gt;Note: apiserver-advertise-address should be the ip address of master node in our K8S cluster. You can assign your custom cidr for pod-network-cidr.&lt;/p&gt;

&lt;p&gt;The cluster will be initialized, and all control plane components, such as the kube-api server, etcd, kube-scheduler, and kube-controller-manager, will be set up.&lt;/p&gt;

&lt;p&gt;As soon as the cluster is initialized, it displays the command for worker nodes to join the cluster&lt;/p&gt;

&lt;p&gt;kubeadm join 10.168.100.21:6443 --token koyi1v.hoq6ssx0dxy6k5ji         --discovery-token-ca-cert-hash sha256:fc5066a9e04652e4e6f67fa9e49749b76c6f9873df382e9b9ac47d747877bd7d(in my case).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;17. Setting Up Kubernetes Configuration for User Access(in &lt;br&gt;
      master node)&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  mkdir -p $HOME/.kube
  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  sudo chown $(id -u):$(id -g) $HOME/.kube/config
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;*&lt;em&gt;18. Join the worker nodes to the cluster. *&lt;/em&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  kubeadm join 10.168.100.21:6443 --token koyi1v.hoq6ssx0dxy6k5ji         --discovery-token-ca-cert-hash sha256:fc5066a9e04652e4e6f67fa9e49749b76c6f9873df382e9b9ac47d747877bd7d(run it on all worker nodes)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;check the status in master node using "kubectl get nodes"&lt;br&gt;
It will show the all the worker nodes info but the status is in NotReady state since we have not set up the cluster network yet.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;19. Installing a Pod network add-on using calico network(in master node)&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  curl https://raw.githubusercontent.com/projectcalico/calico/v3.27.2/manifests/calico.yaml -O
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;If you are using pod CIDR other than 192.168.0.0/16, then uncomment the CALICO_IPV4POOL_CIDR variable in the manifest(calico.yaml) and set it to the same value as your chosen pod CIDR.(in my case i set it to 172.100.0.0/16)&lt;/p&gt;

&lt;p&gt;Apply the manifest using the following command.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   kubectl apply -f calico.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now the pod network and network policy are deployed in our cluster. The nodes use this pod network to communicate with each other.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;20. check the pods and nodes are running(in master node)&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl get pods -n kube-system
kubectl get nodes

calico-kube-controllers-68cdf756d9-fjfjp   1/1     Running   2 (11d ago)   12d
calico-node-2frrp                          1/1     Running   2 (11d ago)   12d
calico-node-4hnfk                          1/1     Running   1 (11d ago)   12d
calico-node-kf7kf                          1/1     Running   1 (11d ago)   12d
calico-node-svvlh                          1/1     Running   1 (11d ago)   12d
coredns-5dd5756b68-8cqq8                   1/1     Running   1 (11d ago)   12d
coredns-5dd5756b68-x8hrw                   1/1     Running   1 (11d ago)   12d
etcd-aekmlpcik8sm212                       1/1     Running   2 (11d ago)   12d
kube-apiserver-aekmlpcik8sm212             1/1     Running   2 (11d ago)   12d
kube-controller-manager-aekmlpcik8sm212    1/1     Running   4 (11d ago)   12d
kube-proxy-2ffxk                           1/1     Running   1 (11d ago)   12d
kube-proxy-kbfj2                           1/1     Running   1 (11d ago)   12d
kube-proxy-m42v5                           1/1     Running   2 (11d ago)   12d
kube-proxy-v5dsq                           1/1     Running   1 (11d ago)   12d
kube-scheduler-aekmlpcik8sm212             1/1     Running   5 (11d ago)   12d


aekmlpcik8sm212   Ready    control-plane   12d   v1.28.7
aekmlpcik8sw213   Ready    &amp;lt;none&amp;gt;          12d   v1.28.7
aekmlpcik8sw214   Ready    &amp;lt;none&amp;gt;          12d   v1.28.7
aekmlpcik8sw215   Ready    &amp;lt;none&amp;gt;          12d   v1.28.7
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The above output depicts that everything is good and working fine in our cluster.&lt;/p&gt;

&lt;p&gt;Bravo, Our Kubernetes cluster has been set up successfully&lt;/p&gt;

</description>
      <category>kubernetes</category>
      <category>devops</category>
    </item>
  </channel>
</rss>
