How To Setup Kubernetes Cluster Using Kubeadm

 

What is Kubeadm?

Kubeadm is a tool to set up a minimum viable Kubernetes cluster without much complex configuration. Also, Kubeadm makes the whole process easy by running a series of prechecks to ensure that the server has all the essential components and configs to run Kubernetes.

It is developed and maintained by the official Kubernetes community. There are other options like minikube, kind, etc., that are pretty easy to set up.

  • Install docker fallow the link check for different flavours 
       
Platformx86_64 / amd64arm64 / aarch64arm (32-bit)s390x
CentOSyesyes  
Debianyesyesyes 
Fedorayesyes  
Raspbian  yes 
RHEL   yes
SLES   yes
Ubuntuyesyesyesyes
Binariesyesyesyes 

  • Install kubelet kubeadm kubectl 
Debian Family 
  1. Update the apt package index and install packages needed to use the Kubernetes apt repository:

    sudo apt-get update
    sudo apt-get install -y apt-transport-https ca-certificates curl
    
  2. Download the Google Cloud public signing key:

    sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg
    
  3. Add the Kubernetes apt repository:

    echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
    
  4. Update apt package index, install kubelet, kubeadm and kubectl, and pin their version:

    sudo apt-get update
    sudo apt-get install -y kubelet kubeadm kubectl
    sudo apt-mark hold kubelet kubeadm kubectl

Redhat Family (Redhat,Centos,AWS linux ...)

cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-\$basearch
enabled=1
gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
exclude=kubelet kubeadm kubectl
EOF

# Set SELinux in permissive mode (effectively disabling it)
sudo setenforce 0
sudo sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config

sudo yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes

sudo systemctl enable --now kubelet








On Master Node:

  1. Initialize Kubernetes Cluster

    kubeadm init 
  2. Create a user for kubernetes administration and copy kube config file.

      mkdir -p $HOME/.kube
      sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
      sudo chown $(id -u):$(id -g) $HOME/.kube/config
  3. Deploy Calico network as a kubeadmin user.

    This should be executed as a user (heare as a kubeadmin )

    curl https://docs.projectcalico.org/manifests/calico-typha.yaml -o calico.yaml
    kubectl apply -f calico.yaml
  4. Cluster join command

    kubeadm token create --print-join-command

On Worker Node:

  1. Add worker nodes to cluster

    Use the output from kubeadm token create command in previous step from the master server and run here.

    look like this 

    kubeadm join 172.31.24.89:6443 ....

  2. Verifying the cluster To Get Nodes status

    kubectl get nodes

    To Get component status

    kubectl get cs
Check The kubernets cluster using sample webapp

[root@ip-172-31-24-89 ec2-user]# kubectl create deployment nginx --image=gudditi/myresume
deployment.apps/nginx created
[root@ip-172-31-24-89 ec2-user]# kubectl expose deployment nginx --type=NodePort --port=80 --target-port=80 --name=nginxsvc
service/nginxsvc exposed
[root@ip-172-31-24-89 ec2-user]# kubectl get svc
NAME         TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE
kubernetes   ClusterIP   10.96.0.1      <none>        443/TCP        8m19s
nginxsvc     NodePort    10.96.88.173   <none>        80:32599/TCP   5s


browse application using

http://<master/workernode ipaddress>:<port>


Comments

Popular posts from this blog

Remote Friendly Companies

Docker Image Vulnerabilities and Scanner Guide: A Quick Overview

Introduction to Istio, Kiali, Jaeger, Grafana, and Prometheus