Blog was initially published in “https://medium.com/goglides/kubernetes-how-it-works-bc27daf20e4c

Note: If you already know how Kubernetes works you might me interested in my previous blog post Stop using kubeconfig with admin access

Kubernetes short form k8s is an open-source tool that was originally designed by Google and is now maintained by the Cloud Native Computing Foundation (CNCF). Kubernetes combine a bunch of virtual machines or physical machines and transform them into unified API surfaces. API which is presented as JSON based API, through which developers can interact with containers and orchestrate their applications, scale it without knowing about the machine that lies below.

Kubernetes defines a set of building blocks (API endpoints). Some of the cores ones are,

  • A pod is a collection of containers co-located on a single machine.
  • Service is a load balancer that can route traffic down to a collection of pods.
  • Deployment which under the hood uses a replica set which is used for replicating a container multiple times for availability or scale.
kubernetes-how-it-works-diagrams-01
kubernetes-how-it-works-diagrams-02
k8s API combines all virtual machine or physical machine as collective groups

Besides that, there are many other objects likes

  • Volumes
  • Namespaces
  • Configmap and Secrets
  • StatefulSets
  • DaemonSets
  • Ingress
  • and others…

All of these primitives collectively work together to provides mechanisms that deploy, maintain and scale applications based on CPU, memory, labels, taint, tolerations, and other custom metrics.

Pods combine one or more than one container which is going to deploy in the same machine. We can directly create pods object using pods manifest or we can use deployment manifest to create pods.

kubernetes-how-it-works-diagrams-03
kubernetes-how-it-works-diagrams-04
POD is a logical collection of containers, Deployments represent a set of multiple, identical Pods

A Deployment runs multiple replicas of the same pods, deployment makes sure it always matches the number of replicas mentioned in deployment manifest, it also automatically replaces any instances that fail or become unresponsive.

kubernetes-how-it-works-diagrams-05
kubernetes-how-it-works-diagrams-06
Scaling pods replicas from 3 to 4

In Kubernetes, a Service is an abstraction that defines a logical set of Pods. In simple terms, it is a loadbalancer. Users or other applications can use Service objects to talk to pods.

kubernetes-how-it-works-diagrams-07
Service is an abstraction that defines a logical set of Pods

We can use external load balancer like ELB, NLB or ALB in AWS, Cloud Load Balancer in google cloud or any other load balancer. Users can use an external load balancer to connect with applications.

External load balancer route traffic to service, service route traffic to pods.