How to configure Kubernetes on Linux.

Kubernetes is a tool for managing Docker containers at scale on on-premise server or across hybrid cloud environments.It is provided with Kubernetes to help users install a production ready Kubernetes cluster.In Kubernetes cluster.we needs a minimum of two nodes – a master node and a worker node.

Install Kubernetes & Contianer

vim /etc/containerd/config.toml
  • Set the following line.
plugins.cri.systemd_cgroup = true

Initialize master node

  • Check load modules.
lsmod | grep br_netfilter

Here is the command output.

[email protected]:/home/ubuntu# lsmod | grep br_netfilter
br_netfilter           28672  0
bridge                176128  1 br_netfilter

Enable kubelet service.

systemctl enable kubelet

Now initialize the system that will run the control plane components which includes the cluster database and the API Server.

Pull container images:

kubeadm config images pull

Here is the command output.

[email protected]31-19-171:/home/ubuntu# kubeadm config images pull
[config/images] Pulled k8s.gcr.io/kube-apiserver:v1.21.2
[config/images] Pulled k8s.gcr.io/kube-controller-manager:v1.21.2
[config/images] Pulled k8s.gcr.io/kube-scheduler:v1.21.2
[config/images] Pulled k8s.gcr.io/kube-proxy:v1.21.2
[config/images] Pulled k8s.gcr.io/pause:3.4.1
[config/images] Pulled k8s.gcr.io/etcd:3.4.13-0
[config/images] Pulled k8s.gcr.io/coredns/coredns:v1.8.0

Set cluster endpoint DNS name or add record.Open hosts file.

vim /etc/hosts

Provide DNS name .

Create cluster:

kubeadm init \
  --pod-network-cidr=172.18.0.0/16 \
  --control-plane-endpoint=DNS-name

Once Kubernetes control-plane has initialized.

Configure kubectl

mkdir -p $HOME/.kube
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config

Check cluster status:

kubectl cluster-info

Add Master nodes.

kubeadm join Dns-name:6443 --token sr4l2l.2kvot0pfalh5o4ik \
    --discovery-token-ca-cert-hash sha256:c692fb047e15883b575bd6710779dc2c5af8073f
7cab460abd181fd3ddb29a18 \
    --control-plane 

Install network plugin on Master.

kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml

Check all of the pods are running:

watch kubectl get pods --all-namespaces

Confirm master node is ready:

kubectl get nodes -o wide

Add worker nodes

  • Add record to /etc/hosts, If endpoint address is not in DNS.
vim /etc/hosts

Add a worker node to the cluster.

kubeadm join DNS-name:6443 \
  --token sr4l2l.2kvot0pfalh5o4ik \
  --discovery-token-ca-cert-hash sha256:c692fb047e15883b575bd6710779dc2c5af8

Check node joined the cluster.

kubectl get nodes
&
kubectl get nodes -o wide

Deploy application on cluster.

kubectl apply -f https://k8s.io/examples/pods/commands.yaml

Check pod.

kubectl get pods

 

Leave a Reply

Your email address will not be published.