KUBERNETES

docker initialization

https://get.docker.com/

curl -fsSL https://get.docker.com -o get-docker.sh

sh get-docker.sh

–>Configure the Docker daemon

sudo mkdir /etc/docker
cat <<EOF | sudo tee /etc/docker/daemon.json
{
“exec-opts”: [“native.cgroupdriver=systemd”],
“log-driver”: “json-file”,
“log-opts”: {
“max-size”: “100m”
},
“storage-driver”: “overlay2”
}
EOF

-> restart Docker

sudo systemctl enable docker
sudo systemctl daemon-reload
sudo systemctl restart docker

kubernetes installation

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

Now initialize the kubeadm by loggin in as root user on master node

sudo -i

kubeadm init

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

Alternatively, if you are the root user, you can run:

export KUBECONFIG=/etc/kubernetes/admin.conf

You should now deploy a pod network to the cluster.
Run “kubectl apply -f [podnetwork].yaml” with one of the options listed at:
https://kubernetes.io/docs/concepts/cluster-administration/addons/

Then you can join any number of worker nodes by running the following on each as root:

kubeadm join 172.31.2.224:6443 –token wuihk5.u19ve2jvh8gxxiab \
–discovery-token-ca-cert-hash sha256:64fe91d156381180fced25e6a9576e96150db8f9500419691703b16507f562c0

—–>Now install a pod network on master node and verify if the node is in ready state by executing kubectl get nodes

kubectl apply -f “https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d ‘\n’)”

summery

Summary of installation

  • Install docker on the nodes (both) and execute the steps mentioned in Refer Here Preview
  • Install the kubeadm, kubelet and kubectl on both nodes Refer Here Preview
  • Now initialize the kubeadm by loggin in as root user on master node
kubeadm init

  • Copy the commands to configure the kubectl and join command Preview
  • Now become the non root user and execute the following Preview
  • Now install a pod network on master node and verify if the node is in ready state by executing kubectl get nodes
kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"

  • Now login into node and become root user (sudo -i) and execute the join command Preview
  • Now login into master node and execute kubectl get nodes to see the status of both nodes