Step-by-Step Guide: Setting up a Kubernetes Cluster with Kubeadm
First Install and start Docker on the master and worker nodes.
First, update the server by running the following command:
sudo apt-get update
Install Docker by running the following command:
sudo apt-get install docker.io
Add the current user to the Docker group, so you can use Docker without sudo:
sudo usermod -a -G docker $USER
Reboot the system for the changes to take effect:
sudo reboot
Congratulations, Docker is now installed on your Ubuntu system!
Install the library for Kubeadm:
sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg
https://packages.cloud.google.com/apt/doc/apt-key.gpg
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
Install Kubeadm and other necessary tools:
sudo apt-get install -y kubelet=1.20.0-00 kubectl=1.20.0-00 kubeadm=1.20.0-00
Become root user using
sudo su
and initialize Kubeadm by running the following command on the master node:kubeadm init
You will see a message indicating that your Kubernetes control-plane has initialized successfully. To start using your cluster, you need to run the following as a regular user:
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
This will set the KUBECONFIG environment variable to the location of the Kubernetes configuration file.
To verify that your cluster is up and running, run the following command:
kubectl get nodes
You should see an output listing the nodes in your cluster.
Create a network for your Kubernetes cluster by deploying the Weave Net CNI plugin. Run the following command:
kubectl apply -f
https://github.com/weaveworks/weave/releases/download/v2.8.1/weave-daemonset-k8s.yaml
This command will deploy the Weave Net daemonset, which ensures that a copy of a pod runs on every node in the cluster. The Weave Net CNI plugin provides network connectivity between pods and services within a Kubernetes cluster.
Generate a token that worker nodes can use to connect to the master. Run the following command:
kubeadm token create --print-join-command
This will output a command that you can use to join worker nodes to the cluster. Make note of the command, as you will need it when joining worker nodes.
On each worker node, become root using
sudo su
and reset Kubeadm pre-flight checks:kubeadm reset
Join the worker nodes to the cluster by running the join command that was generated in step 6. Run the following command on each worker node:
kubeadm join 172.31.20.154:6443 --token 0ehf8k.mkq70s47jh5er3tu --discovery-token-ca-cert-hash sha256:5c6d671834c7d4f36c1f1a57b1c89e90d2a9e4efe1034c632d3575dd6ec41abe --v=5
Replace the IP address with the IP address of your master node. This command will join the worker node to the cluster.
Verify that the worker nodes have joined the cluster by running the following command on the master node:
kubectl get nodes
You should see all the worker nodes listed as part of your cluster.
Congratulations! You have successfully set up a Kubernetes cluster with one master node and multiple worker nodes. Now, you can start deploying and managing containerized applications using Kubernetes.
However, keep in mind that this is just a basic setup guide, and there are many other aspects of Kubernetes that you may want to explore, such as:
Creating and managing deployments
Configuring services and load balancing
Scaling and autoscaling your applications
Configuring storage and volumes
Implementing security measures
Monitoring and logging your cluster
To learn more about these topics and more, check out the Kubernetes documentation and community resources. Happy Kubernetizing!
Subscribe to my newsletter
Read articles from Rajesh Verma directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by