Requirements for Kubernetes:
1. Compatible Linux Machine
2. Docker Runtime
3. Kubernetes cluster (1 Master - 1 Worker Node)
Setting up the Linux machine
I have one Kubernetes master and one slave/worker node ready.
These 2 are Linux machines with no software installed at the moment.
I will be doing all the installation as root, but if you are doing it as a user, ensure you have proper sudo permissions.
Setting up Docker Runtime (Both Servers)
The below step should be done on both the Master and Slave/Worker nodes.
Initial step - run this command to enable working with https and http:
# sudo apt install apt-transport-https ca-certificates curl software-properties-common
Step1: Set up the repository
# sudo apt-get update
Step 2: Adding the Docker's official GPG keys-
# curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Step 3: Set Up the Repository
# sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
# apt-cache policy docker-ce
Step 4: Update the packages
# sudo apt-get update
Step 5: Install Docker, conatinerd, and docker-compose with this command-
# sudo apt install docker-ce
# sudo systemctl status docker
| Master |
| Slave |
Setting up Kubernetes Cluster
Let's start, remember you need to do this installation on both servers:
Step 1: Add Kubernetes signing keys-
# curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add
Step 2: Add the repository
# echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" >> ~/kubernetes.list
# sudo mv ~/kubernetes.list /etc/apt/sources.list.d
Step 3: Update the packages-
# sudo apt update
We have installed the Kubernetes package only now. Installation of Kubernetes is a mixture of tools that we will do in the next steps:
Step 4: Install kubelet, kubectl, kubeadm, and kubernetes-cni -
# sudo apt-get install -y kubelet kubeadm kubectl kubernetes-cni
Step 4: For master and slave to communicate we need a few IP changes as follows-
Step 5 (To be done on the master node): Initialize master node
# kubeadm init --pod-network-cidr=10.244.0.0/16
Copy the kubeadm join command that you got somewhere safe:
kubeadm join 10.162.0.3:6443 --token 8mhyt2.wrt9howvs143pz98 \
--discovery-token-ca-cert-hash sha256:51e3437145285afacae15db22795a26edd65b77009976c2698b906a14ca2b849
In the same output, you must get some command to run - let's run that too
# mkdir -p $HOME/.kube
# sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
# sudo chown $(id -u):$(id -g) $HOME/.kube/config
We have just initiated the master node as of now, we need to set up some network for our master and slaves to communicate:
Kubernetes has few networks (Flannel or Calico are the two mainly used).
Step 6: Let's use a flannel network here and set it up- (make sure your 6443 port is open)
# kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
# kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/2140ac876ef134e0ed5af15c65e414cf26827915/Documentation/kube-flannel.yml
And you are done.!
Step 7: joining the slave to master using the kubeadm join command we saved earlier (to do in worker node)
Make sure you replace your token here:
# kubeadm join 10.162.0.3:6443 --token 8mhyt2.wrt9howvs143pz98 \
--discovery-token-ca-cert-hash sha256:51e3437145285afacae15db22795a26edd65b77009976c2698b906a14ca2b849
| Message on the Slave/Worker node |
To check whether your installation was successful, run the command in the master node:
You should see the below output:
| Kubectl get nodes |
Similarly, if you wish to add another node for your cluster you can just run the "kubeadm join" command there and it will be added.
Make sure you save this command as for adding the worker nodes you need this, and if you forget this you may need to do the initiation steps again.
No comments:
Post a Comment