Sitemap

Kubernetes Cluster Setup using Kubeadm

4 min readNov 5, 2023
Press enter or click to view image in full size

Steps:

Open the AWS Management Console and search for the Ec2. Click on it.

Press enter or click to view image in full size

Configure the K8s-master instance as follows.

Press enter or click to view image in full size

Configure the K8s-Worker instance as follows.

Press enter or click to view image in full size

Connect the K8s-Master node as follows using ssh.

Press enter or click to view image in full size

Connect the K8s-Worker node as follows using ssh.

Press enter or click to view image in full size

Both the Master Node and worker Node

Install the below required components.

# using 'sudo su' is not a good practice.
sudo apt update
sudo apt-get install -y apt-transport-https ca-certificates curl
sudo apt install docker.io -y
sudo systemctl enable --now docker # enable and start in single command.
Press enter or click to view image in full size
Press enter or click to view image in full size
# Adding GPG keys.
curl -fsSL "https://packages.cloud.google.com/apt/doc/apt-key.gpg" | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/kubernetes-archive-keyring.gpg
# Add the repository to the sourcelist.
echo 'deb https://packages.cloud.google.com/apt kubernetes-xenial main' | sudo tee /etc/apt/sources.list.d/kubernetes.list
Press enter or click to view image in full size
Press enter or click to view image in full size
sudo apt update 
sudo apt install kubeadm=1.20.0-00 kubectl=1.20.0-00 kubelet=1.20.0-00 -y
Press enter or click to view image in full size
Press enter or click to view image in full size
Press enter or click to view image in full size

Master Node

Initialize the Kubernetes master node.

Press enter or click to view image in full size

After successfully running, your Kubernetes control plane will be initialized successfully.

Press enter or click to view image in full size

Set up local kubeconfig (both for the root user and normal user):

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
Press enter or click to view image in full size
Press enter or click to view image in full size

Apply Weave network:

kubectl apply -f https://github.com/weaveworks/weave/releases/download/v2.8.1/weave-daemonset-k8s.yaml
Press enter or click to view image in full size

Generate a token for worker nodes to join:

sudo kubeadm token create --print-join-command
Press enter or click to view image in full size

Expose port 6443 in the Security group for the Worker to connect to the Master Node

Press enter or click to view image in full size

Worker Node

Run the following commands on the worker node.

sudo kubeadm reset pre-flight checks
Press enter or click to view image in full size

Paste the join command you got from the master node and append --v=5 at the end. Make sure you are working as a sudo user or using sudo before the command

Press enter or click to view image in full size

After succesful join->

Press enter or click to view image in full size

Verify Cluster Connection

On Master Node:

kubectl get nodes
Press enter or click to view image in full size

Labeling Nodes

If you want to label worker nodes, you can use the following command:

kubectl label node <node-name> node-role.kubernetes.io/worker=worker
Press enter or click to view image in full size

Test a Demo Pod

If you want to test a demo pod, you can use the following command:

kubectl run hello-world-pod --image=busybox --restart=Never --command -- sh -c "echo 'Hello, World' && sleep 3600"
Press enter or click to view image in full size

We can see the list of events.

Press enter or click to view image in full size

Thanks for reading! I hope you found this introduction to Go helpful and informative.

I’m always happy to connect with fellow tech enthusiasts and answer any questions you may have. Don’t forget to follow me for more updates on tech, programming, and more.😄😄

--

--

No responses yet