100 Days of DevOps — Day 72-Introduction to Kubernetes

To view the updated DevOps course(101DaysofDevOps)

Course Registration link: https://www.101daysofdevops.com/register/

Course Link: https://www.101daysofdevops.com/courses/101-days-of-devops/

YouTube link: https://www.youtube.com/user/laprashant/videos

Welcome to Day 72 of 100 Days of DevOps, Focus for today is Introduction to Kubernetes

What is Kubernetes?

Kubernetes is a portable, extensible open-source platform for managing containerized workloads and services, that facilitates both declarative configuration and automation.

  • Born in google and donated to Cloud Native Computing Foundation(CNCF) in 2014
  • Written in Go/Golang https://github.com/kubernetes/kubernetes
  • Open source under Apache license 2.0
  • Version 1.0 released in July 2015
  • Often shortened to K8s(replace 8 characters between k and s)

Kubernetes Architecture

  • Kubernetes is an orchestrator for microservice apps(application made of a lot of small and independent services)that run on a container


kube-apiserver(Brain of the cluster)

  • This is the front-end for the Kubernetes control plane
  • Exposes the API(REST) and consumes JSON(via manifest file) where we describe the desired state

Cluster store(Persistent Storage)(etcd)

  • Cluster state and config is persistently stored here.
  • Uses etcd(Opensource distributed key-value store)
  • Act as a source of truth for the cluster


  • Node controller
  • Endpoints controller
  • Namespace controller
  • Watches for changes and helps maintain the desired state


  • Watch APIserver for new pods
  • Assigns work to nodes
  • The decision is based on many factors including hardware, workloads, affinity, etc.

Nodes(The Kubernetes Workers aka Minions)(The Kubernetes Workers)


  • The main kubernetes agent on the node
  • Registers node with cluster
  • Watches apiserver
  • Instantiates pods
  • Reports back to master
  • Exposes endpoint on 10255

Container Engine

  • Does container management
  • Pulling images
  • Starting/stopping container
  • Usually Docker
  • Can be CoreOS Rocket(rkt)

Kube-proxy(Kubernetes networking)

  • Pod IP addresses
  • All containers in a pod share a single IP
  • Load balances across all pods in a service


  • Containers always run inside of pods
  • All containers in a pod share the pod environment(eg: IPC, shared memory, network)

Pod Lifecycle

  • Failed pods never brought back to life

Replication Controllers

  • Scale pods and maintains the desired state


  • Rolling updates and rollbacks


  • Stable networking and load balancing
  • To check
$ kubectl get pods  --all-namespaces  -o wideNAMESPACE     NAME                                                  READY   STATUS    RESTARTS   AGE   IP              NODE                          NOMINATED NODE   READINESS GATESkube-system   coredns-fb8b8dccf-9v6gv                               1/1     Running   0          31m      plakhera11c.mytestserver.com   <none>           <none>kube-system   coredns-fb8b8dccf-xk4jx                               1/1     Running   0          31m      plakhera11c.mytestserver.com   <none>           <none>kube-system   etcd-plakhera11c.mytestserver.com                      1/1     Running   0          30m   plakhera11c.mytestserver.com   <none>           <none>kube-system   kube-apiserver-plakhera11c.mytestserver.com            1/1     Running   0          30m   plakhera11c.mytestserver.com   <none>           <none>kube-system   kube-controller-manager-plakhera11c.mytestserver.com   1/1     Running   0          30m   plakhera11c.mytestserver.com   <none>           <none>kube-system   kube-flannel-ds-amd64-5rkbc                           1/1     Running   1          28m    plakhera12c.mytestserver.com   <none>           <none>kube-system   kube-flannel-ds-amd64-7vlwf                           1/1     Running   0          29m   plakhera11c.mytestserver.com   <none>           <none>kube-system   kube-flannel-ds-amd64-8ktdq                           1/1     Running   1          28m   plakhera13c.mytestserver.com   <none>           <none>kube-system   kube-proxy-7fmvr                                      1/1     Running   0          28m   plakhera13c.mytestserver.com   <none>           <none>kube-system   kube-proxy-rd8qq                                      1/1     Running   0          31m   plakhera11c.mytestserver.com   <none>           <none>kube-system   kube-proxy-vkl7h                                      1/1     Running   0          28m    plakhera12c.mytestserver.com   <none>           <none>kube-system   kube-scheduler-plakhera11c.mytestserver.com            1/1     Running   0          31m   plakhera11c.mytestserver.com   <none>           <none>

Kubernetes Installation

In this setup, I am going to install

1 master node
2 worker node

Step1: Disable selinux

setenforce 0
sed -i --follow-symlinks 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux

Step2: Enable the br_netfilter module for cluster communication.

modprobe br_netfilter
echo '1' > /proc/sys/net/bridge/bridge-nf-call-iptables

Step3: Disable swap to prevent memory allocation issues.

swapoff -a# Go to /etc/fstab file and comment this line
#/root/swap swap swap sw 0 0

Step4: Install the Docker prerequisites

yum install -y yum-utils device-mapper-persistent-data lvm2

Step5: Add the Docker repo and install Docker.

# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo# yum install -y docker-ce

Step6: Configure the Docker Cgroup Driver to systemd, enable and start Docker

# sed -i '/^ExecStart/ s/$/ --exec-opt native.cgroupdriver=systemd/' /usr/lib/systemd/system/docker.service # systemctl daemon-reload# systemctl enable docker --now

Step7: Add the Kubernetes repo.

cat <<EOF > /etc/yum.repos.d/kubernetes.repo

Step8: Install Kubernetes.

yum install -y kubelet kubeadm kubectl

Step9: Enable Kubernetes. The kubelet service will not start until you run kubeadm init.

# systemctl enable kubeletCreated symlink from /etc/systemd/system/multi-user.target.wants/kubelet.service to /usr/lib/systemd/system/kubelet.service.

NOTE: Up to this point all steps need to be performed on Master as well as on two workers node

  • The below steps need to perform only on Master

Initialize the cluster using the IP range for Flannel.

  • Copy the kubeadm join command
  • 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
  • Deploy Flannel.
$ kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.ymlpodsecuritypolicy.extensions/psp.flannel.unprivileged createdclusterrole.rbac.authorization.k8s.io/flannel createdclusterrolebinding.rbac.authorization.k8s.io/flannel created
  • Run kubectl get nodes
$ kubectl get nodesNAME                          STATUS     ROLES    AGE     VERSIONplakhera1.mytestserver.com   Ready      master   3m48s   v1.14.1
  • Now run the kubeadm join we copied earlier on all Worker Nodes
  • Run kubectl nodes again
$ kubectl get nodesNAME                          STATUS   ROLES    AGE     VERSIONplakhera1.mytestserver.com   Ready    master   7m53s   v1.14.1plakhera2.mytestserver.com   Ready    <none>   4m9s    v1.14.1plakhera3.mytestserver.com   Ready    <none>   4m10s   v1.14.1

Looking forward from you guys to join this journey and spend a minimum an hour every day for the next 100 days on DevOps work and post your progress using any of the below medium.




AWS Community Builder, Ex-Redhat, Author, Blogger, YouTuber, RHCA, RHCDS, RHCE, Docker Certified,4XAWS, CCNA, MCP, Certified Jenkins, Terraform Certified, 1XGCP

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Prashant Lakhera

AWS Community Builder, Ex-Redhat, Author, Blogger, YouTuber, RHCA, RHCDS, RHCE, Docker Certified,4XAWS, CCNA, MCP, Certified Jenkins, Terraform Certified, 1XGCP