Learn to deploy a Kubernetes cluster in 30 minutes using KubeAdm

Pre-Requisites: 

Create 3 VMs with 2 core 8 GB and 10-100 GB HDD

1. Docker set up in master and nodes

1a. Login into master and update your existing list of packages  


Copy to Clipboard

1b. Install the prerequisite packages which let apt to use packages over HTTPS 


Copy to Clipboard

1c. Add the GPG key for the official Docker repository to your system  

Copy to Clipboard

1d. Add the Docker repository to APT sources   

Copy to Clipboard

1e. Update the packages with the Docker packages from the newly added repo

Copy to Clipboard

1f. Make sure you are about to install from the Docker repo

Copy to Clipboard

1g. Run the following command to install Docker   

Copy to Clipboard

1h. Run the following command to check if the docker is running   

Copy to Clipboard

1i. To avoid sudo requirement in executing the docker command, add your user to docker group   

Copy to Clipboard

1j. To apply the new group membership, run the following command   

Copy to Clipboard

You will be prompted to enter your user password to continue

1k. Confirm that your user is now added to the docker group by typing  

Copy to Clipboard

Repeat the above steps for both the nodes.

2. Kubernetes master set up

2a. Login to the master and install kubelet, kubeadm and kubectl

Copy to Clipboard
Copy to Clipboard
Copy to Clipboard
Copy to Clipboard
Copy to Clipboard
Copy to Clipboard

2b. Initialise kubeadm

Copy to Clipboard

Your Kubernetes master has initialized successfully!

2c. To start using your cluster, you need to run the following command as a regular user:  

Copy to Clipboard
Copy to Clipboard
Copy to Clipboard

Copy the join command and make a note of it.

For example:

Copy to Clipboard

2d. Set up Flannel

Copy to Clipboard
Copy to Clipboard

2e. Verify the creation of the master in the cluster.

$ kubectl get nodes
NAME            STATUS   ROLES    AGE     VERSION
ip-XX-X-X-XXX   Ready    master   3m53s   v1.18.15

$ kubectl get pods --all-namespaces
NAMESPACE    NAME                                   READY STATUS  RESTART AGE
kube-system  coredns-54ff9cd656-ww6sw               1/1   Running 0       4m2s
kube-system  coredns-54ff9cd656-xlrdr               1/1   Running 0       4m2s
kube-system  etcd-ip-XX-X-X-XXX                     1/1   Running 0       2m59s
kube-system  kube-apiserver-ip-XX-X-X-XXX           1/1   Running 0       3m11s
kube-system  kube-controller-manager-ip-XX-X-X-XXX  1/1   Running 0       3m15s
kube-system  kube-flannel-ds-amd64-4rl8d            1/1   Running 0       45s
kube-system  kube-proxy-jpp7w                       1/1   Running 0       4m2s
kube-system  kube-scheduler-ip-XX-X-X-XXX           1/1   Running 0       3m23s

3. Kubernetes node set up

3a. Login into node 1 and install kubelet, kubeadm and kubectl

Copy to Clipboard
Copy to Clipboard
Copy to Clipboard
Copy to Clipboard
Copy to Clipboard
Copy to Clipboard

3b. Join cluster from the command copied above in the master.

Copy to Clipboard

This node has joined the cluster:

Repeat the steps for node 2.

4. Verify creation of nodes in cluster.
Login into master and verify the cluster

$ kubectl get nodes

NAME            STATUS     ROLES    AGE       VERSION
ip-XX-X-X-XXX   Ready               105m      v1.18.15
ip-XXX-X-X-XX   Ready      master   123m      v1.18.15
ip-XX-X-X-XX    Ready               111m      v1.18.15

4. Deploying the nginx with nodeport service

Use the following yaml for deploying nginx with nodeport service to test the cluster

Copy to Clipboard

4.Test the deployment

Copy to Clipboard
Copy to Clipboard
Copy to Clipboard

About The Author

A. Nagesh

SR Cloud Dev-Ops Engineer | Cloud Control

Senior Cloud DevOps Engineer with more than five years of experience in supporting, automating, and optimizing deployments to hybrid cloud platforms using DevOps processes, CI/CD, containers and Kubernetes in both Production and Development environments

Kubernetes