Nikhil Verma

Sep 2, 20232 min

Build Jenkins Pipeline Using Git, Docker Hub, Podman and Kubernetes - Part 2

In part 2 we will deploy Kubernetes cluster:

In my deployment i am using two node cluster one is Master and 2nd one is Worker.

1) Start both VMs; server, worker1 and login as root user.

2) vi /etc/yum.repos.d/kubernetes.repo

[kubernetes]
 
name=Kubernetes
 
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
 
enabled=1
 
gpgcheck=1
 
repo_gpgcheck=0
 
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg

3) Install Podman and container tools:

  • dnf install -y dnf-utils wget tree tar git curl

  • dnf module list container-tools

  • dnf module install container-tools/common

  • https://github.com/containerd/containerd/releases/download/v1.7.2/containerd-1.7.2-linux-amd64.tar.gz

  • tar -xzf containerd-1.7.2-linux-amd64.tar.gz

  • mv bin/* /usr/local/bin/

4) Create a Systemd Unit file for containerd to run it as a service.

  • vi /etc/systemd/system/containerd.service

[Unit]
 
Description=containerd container runtime
 
Documentation=https://containerd.io
 
After=network.target local-fs.target
 

 
[Service]
 
#uncomment to enable the experimental sbservice (sandboxed) version of containerd/cri integration
 
#Environment="ENABLE_CRI_SANDBOXES=sandboxed"
 
ExecStartPre=-/sbin/modprobe overlay
 
ExecStart=/usr/local/bin/containerd
 

 
Type=notify
 
Delegate=yes
 
KillMode=process
 
Restart=always
 
RestartSec=5
 
# Having non-zero Limit*s causes performance problems due to accounting overhead
 
# in the kernel. We recommend using cgroups to do container-local accounting.
 
LimitNPROC=infinity
 
LimitCORE=infinity
 
LimitNOFILE=infinity
 
# Comment TasksMax if your systemd version does not supports it.
 
# Only systemd 226 and above support this version.
 
TasksMax=infinity
 
OOMScoreAdjust=-999
 

 
[Install]
 
WantedBy=multi-user.target

  • systemctl enable --now podman.socket

  • set selinux in disabled state

Disable swap on both VMs. K8s will not work with swap on. For permanently disable swap, comment out the last line in /etc/fstab.

  • vi /etc/fstab

  • systemctl daemon-reload && systemctl enable --now containerd

Reboot VM.

4) Download CNI Plugin and move to search path. Restart the Containerd Service

  • wget https://github.com/containernetworking/plugins/releases/download/v1.3.0/cni-plugins-linux-amd64-v1.3.0.tgz

  • mkdir -p /opt/cni/bin

  • tar Cxzvf /opt/cni/bin cni-plugins-linux-amd64-v1.3.0.tgz

  • systemctl restart containerd

5) Run the package update command on both VMs; server and tester1. Note that it may take 15 to 20 Min. If the dnf package installer is busy, don’t panic and interrupt it. This might be due to auto update running.

  • dnf update -y

6) Install kubeadm and other essential packages required for Kubernetes on all VMs; server and tester1.

  • dnf install ipvsadm iproute-tc kubeadm -y

7) Enable Net packet filter with following command on both VMs.

  • modprobe br_netfilter

  • echo '1' > /proc/sys/net/bridge/bridge-nf-call-iptables

8) Edit /etc/sysctl.conf and add following lines to the file

  • vi /etc/sysctl.conf

net.bridge.bridge-nf-call-iptables=1
 
net.ipv4.ip_forward=1
 
net.bridge.bridge-nf-call-ip6tables = 1

9) Run the following command : sysctl -p

10) Reboot both VM's.

Setting Up Master Node

1) Setting Up firewall rules :

  • firewall-cmd --permanent --add-port={10248,10250-10252,10255,2379,2380,6443}/tcp

  • firewall-cmd --reload

2) Enable Kubelet service :

  • systemctl enable --now kubelet

Pull images required to initialize and setup kubernetes server:

  • kubeadm config images pull

  • kubeadm init --apiserver-advertise-address=xx.xx.xx.xx --pod-network-cidr=10.244.0.0/16

Execute the following commands to use the cluster as root user :

  • mkdir -p $HOME/.kube

  • cp -i /etc/kubernetes/admin.conf $HOME/.kube/config

  • chown $(id -u):$(id -g) $HOME/.kube/config

Take a copy of Cluster Join URL.

3) Deploy CNI network :

  • kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

Setting Up worker Nodes

1) Configure Firewall Rules :

  • firewall-cmd --permanent --add-port={10250,10255,30000-32767,6783}/tcp

  • firewall-cmd --reload

2) Enable Kubelet service :

  • systemctl enable --now kubelet

  • systemctl enable --now kubelet

3) Join worker nodes to cluster .

Verify Node status :

  • kubectl get nodes

In next part we will learn about Jenkins Configuration.

    300
    0