Kubernetes Setup with kubeadm

Requirements:

  1. Kubernetes Master server (01 Nos.) – Ubuntu server 18.04 LTS with 2CPU and 4GB RAM
  2. Kubernetes Node (02 Nos) – Ubuntu server 18.04 LTS with 1CPU and 2GB RAM

Steps to configure kuberbernetes :

  • Create 1 Ubuntu machine with atleast 2 vcpu’s and 4gb ram for Kubernetes Master and 2 ubuntu machines with 1 vcpu and 1GB ram for Kubernetes nodes on Azure or AWS or Google Cloud
  • Login into the three machines and install docker using following instructions

Below commands should be run step by step with sudo permission.

make sure to run command “sudo -i ” to become root user before running below commands.

  1.  Installing Docker CE process.

(a) Below command will Set up the repository and  Install packages to allow apt to use a repository over HTTPS

apt-get update && apt-get install apt-transport-https ca-certificates curl software-properties-common

(b) Below command will Add Docker’s official GPG key

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add –

(c) below command will Add Docker apt repository.

add-apt-repository \
“deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable”

(d) below command will Install Docker CE.

apt-get update && apt-get install docker-ce=18.06.2~ce~3-0~ubuntu

(e) Below command will Setup daemon.

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

(f) need to run below commands to Restart docker service .

systemctl daemon-reload
systemctl restart docker

(g) below command will Add the current user to the docker group

sudo usermod -aG docker <yourusername>

Example sudo usermod -aG docker ubuntu    (where ubuntu is the username)

Exit and logoff and login again and run command

Docker –version

2. Steps to configure Kubernetes using kubectl 

Below commands should be run in sudo permission.

make sure to run command “sudo -i ” to become root user before running below commands.

(a) Need to run below commands on all 3 nodes to Install kubeadm, kubelet and kubectl

apt-get update && apt-get install -y apt-transport-https curl
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add –
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF
apt-get update
apt-get install -y kubelet kubeadm kubectl
apt-mark hold kubelet kubeadm kubectl

(b) Below command should be run on kubernetes server to Bootstrap the cluster on the master node using

kubeadm init –pod-network-cidr=10.244.0.0/16

(c)   make the note of join command printed out 

Example of command output. and you will be seeing  different output and this token will be valid or works only for 24 hours.

==============
kubeadm join 10.10.0.4:6443 –token 3l9arr.hzaq6swaelqs7olv \
–discovery-token-ca-cert-hash sha256:a33fd52c70aca4ca9a74b5763345b086299f9311c0c6ac65a59216a28ba0b649
==============

(d) Switch to non root user or exit from root

(e) Setup kubeconfig using the following command on the kubernetes master server

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

(f) Login into the kubernetes nodes and become root (sudo -i)

(g) Join the cluster using join command noted during kubeadm init execution. step (c)

(h) Login into the Kubernetes master and execute the below command to see list the nodes.

kubectl get nodes

(g) you will observe nodes in not ready state, So its time to setup cluster network. We will be using flannel, you can choose any from the kubernetes documentation

kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/62e44c867a2846fefb68bd5f178daf4da3095ccb/Documentation/kube-flannel.yml

(h) Execute below command to see the nodes turning into ready state

kubectl get nodes -w

(i) Execute  below command and ensure all the pods are running

kubectl get pods -A

(j) Setup Kubectl auto completion on master

source <(kubectl completion bash) echo “source <(kubectl completion bash)” >> ~/.bashrc

Now kubernetes setup is ready with kubeadm, will create POD’s, service, replication controllers, Deployments in next post.  Hope this post is informative – Thank you. 

 

 

 

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.