Kubernetes Notes - (Start)
Kubernetes Notes - (Start)
Vivek Singh
Summary
The provided content serves as a comprehensive guide to understanding
Kubernetes, detailing its architecture, features, components, and objects,
while emphasizing the necessity and benefits of using Kubernetes for
container management and orchestration.
Abstract
The web content titled "Kubernetes Notes — Get Started" offers an in-
depth exploration of Kubernetes, an open-source platform designed to
automate deploying, scaling, and operating application containers. It
begins by outlining the key components of Kubernetes architecture,
including master and worker nodes, and the roles of various processes
such as kube-apiserver, kube-controller-manager, kube-scheduler, etcd,
and kubelet. The guide highlights the features of Kubernetes, such as
service discovery, load balancing, scaling, self-healing, and storage
orchestration, which collectively enable high availability and efficient
resource management. The importance of Kubernetes is underscored by
its ability to manage complex containerized applications, ensuring zero
downtime and facilitating data recovery. The content also delves into
Kubernetes objects, such as Pods, Services, Deployments, and Persistent
Volumes, and their role in defining the desired state of the cluster. The
guide concludes with practical use cases, references for further reading,
and a call to action for readers to engage with the author for discussions
or freelancing opportunities.
Opinions
The author conveys that managing containers without Kubernetes can
be challenging and inefficient, especially as the number of containers
grows.
Kubernetes is portrayed as an essential tool for running distributed
Translate to
systems resiliently, providing a framework that takes care of scaling
and failover for applications.
The guide suggests that Kubernetes enhances modularity and better
management of software deployment and updates at scale.
The author emphasizes the importance of Kubernetes' self-healing
capabilities, such as restarting failed containers and rescheduling
pods, to maintain application stability.
Content
Architecture
K8s Objects
K8s Components
References
Ending Notes
Architecture Translate to
Source
Translate to
Source
Stuff like your application code, dependent libraries, and its dependencies all
the way up to the kernel — is a container. The key concept here is isolation.
Isolate all your stuff from the rest so that you have better control of them.
There are three types of isolation provided by containers
Automated rollouts and rollbacks You can describe the desired state
for your deployed containers using Kubernetes, and it can change the
actual state to the desired state at a controlled rate. For example, you can
automate Kubernetes to create new containers for your deployment,
remove existing containers and adopt all their resources to the new
container.
Auto healing
Worker Node
Container Runtime
kubelet
kube-proxy
Translate to
Worker Node
kubelet
Within a Kubernetes cluster, the kubelet watches for PodSpecs via the
Kubernetes API server.
A PodSpec is a YAML or JSON object that describes a pod. The kubelet takes
a set of PodSpecs that are provided through various mechanisms (primarily
through the API server) and ensures that the containers described in those
PodSpecs are running and healthy.
Kube-proxy:
K8s cluster can have multiple worker nodes and each node has multiple pods
running, so if one has to access this pod, they can do so via Kube-proxy. In
order to access the pod via k8s services, there are certain network policies,
that allow network communication to your Pods from network sessions
inside or outside of your cluster. These rules are handled via kube-proxy.
kube-proxy has an intelligent algorithm to forward network traffics
required for pod access which minimizes the overhead and makes service
communication more performant
Container runtime
containerd
CRI-O
Docker
The container runtime is the software that is responsible for running
Translate to
containers (in Pods).
To run the containers, each worker node has a container runtime engine.
It pulls images from a container image registry and starts and stops
containers.
Master Node
Who manages these worker nodes, to ensure that they are always up and
running? How does the K8s cluster know which pods should be scheduled
and which one should be dropped or restarted? How does the k8s cluster
know the resource level requirements of each container app? — — — Well
the answer lies in the concept of Master Node — -
Translate to
Master Node
Every master nodes in the K8s cluster runs the following key processes
kube-apiserver
kubectl: kube-controller-manager
kube-scheduler
etcd
kube-apiserver:
It is the main gateway to access the k8s cluster and act as the main
gatekeeper for client level authentication or we can say that the kube-
apiserver is the front end for the Kubernetes control plane.
You need to make a request to the API server of the master node which in
turn validates your requests before you get access to the processes in worker
nodes. kube-apiserver is designed to scale horizontally — that is, it scales by
deploying more instances. You can run several instances of kube-apiserver
and balance traffic between those instances
Hardware/Software/Policy constraints
It is one of the critical processes in a master node that monitors the status of
any worker node level failures. It keeps a close watch over the event like ::
Crashing of any pods in the worker node and, requests the scheduler to
restart or reschedule any dead /failed pods, after detecting such event.
etcd
etcd in the master control plane is responsible to store every kind of cluster-
level change in the form of key-value pairs. It is a consistent, distributed,
and highly-available key value store. It can be part of the control plane, or, it
can be configured externally.
It can be easily seen as a brain of the k8s cluster which keeps the log of every
minute details of changes occurring in the cluster.
For example, if any pod crashes in the worker node and it has to be
Translate to
rescheduled, the same gets stored in etcd as key-value pair, also the event of
pod rescheduling on the node is also logged here.
kubelet
It makes sure that containers are running in a Pod and they are healthy.
kube-proxy
It is networking component that plays vital role in networking.
Translate to
It deals with individual host sub-netting and ensure that the services are
available to external parties.
Kubernetes Objects
Kubernetes Objects
K8s components :
Pods: Smallest unit of k8s, which is an abstraction of the container
application. Pod is a group of one or more containers, with shared storage
and network resources, and a specification for how to run the containers.
DaemonSet ensures that all (or some, matching a node selector) Nodes
run a copy of a Pod. As nodes are added to the cluster, Pods are added to
them. As nodes are removed from the cluster, those Pods are garbage
collected. Deleting a DaemonSet will clean up the Pods it created. Some
typical uses of a DaemonSet are: - Running a cluster storage daemon on
every node. - Running a logs collection daemon on every node. - Running
a node monitoring daemon on every node.
Job runs pods that perform a completable task. Job creates one or more
Pods and will continue to retry execution of the Pods until a specified
number of them successfully terminate. Deleting a Job will clean up the
Pods it created. Suspending a Job will delete its active Pods until the Job
is resumed again.
Service
Service is used to expose an application deployed on a set of pods using a
single endpoint. i.e. It maps a fixed IP address to a logical group of pods.
Service provides stable networking for pods (ephemeral pods) by bringing
Translate to
stable IP addresses and DNS names, and provide a way to Kubernetes to
configuring a proxy to forward traffic to a set of pods.
Ingress
Ingress manages external access to the services in a cluster, typically
HTTP/S.
Endpoint
Endpoint defines which pods (or other servers) are exposed through a
service.
For Kubernetes Services, Kubernetes creates a Endpoint object. This
Translate to
endpoint will have the ip address mapping of the pods. This is created
automatically for services with a defined selector.
Endpoints can also be used to connect to external services like they were
internal to the kubernetes cluster.
EndpointSlice
EndpointSlices provide a simple way to track network endpoints within a
Kubernetes cluster.
EndpointSlice
EndpointSlices provide a simple way to track network endpoints within a
Kubernetes cluster.
PVC is the request to provision persistent storage with a specific type and
configuration.
PVCs describe the storage capacity and characteristics a pod requires, and
the cluster attempts to match the request and provision the desired
persistent volume.
PVC must be in same namespace as the Pod. For each Pod, a PVC makes a
storage consumption request within a namespace.
PVC is similar to a Pod. Pods consume node resources and PVC consume
PV resources.
ConfigMaps
ConfigMap is used to store non-confidential data in key-value pairs.
Service Account
Kubernetes uses Service Accounts to authenticate and authorize requests
by pods to the Kubernetes API server.
Role
Role defines what can be done to Kubernetes Resources.
ClusterRole
ClusterRole works the same as Role, but they are applied to the cluster as
a whole.
RoleBinding
RoleBinding is used for granting permission to a Subject.
ClusterRoleBinding
ClusterRole and ClusterRoleBinding function like Role and RoleBinding,
except they have wider scope.
PDB limits the number of Pods of a replicated application that are down
simultaneously from voluntary disruptions.
PDB can temporarily halt the eviction process if the number of replicas of
an application falls below the declared threshold. Eviction process will
continue once the number of available replicas is over the threshold.
PDB defines the minimum number of pods that must remain running
when evacuating nodes.
Ingress
Source
Ingress exposes HTTP and HTTPS routes from outside the cluster to services
within the cluster. Traffic routing is controlled by rules defined on the Ingress
resource. You can configure access by creating a collection of rules that define
which inbound connections reach which services.
An Ingress controller is responsible for fulfilling the Ingress, usually with a
Translate to
load balancer, though it may also configure your edge router or additional
frontends to help handle the traffic.
The Ingress spec has all the information needed to configure a load balancer
or proxy server. It contains a list of rules matched against all incoming
requests. Ingress provides routing rules to manage external users’ access to
the services in a Kubernetes cluster, typically via HTTPS/HTTP. With
Ingress, you can easily set up rules for routing traffic without creating a
bunch of Load Balancers or exposing each service on the node. This makes it
the best option to use in production environments.
Ingress controllers
Ingress controller is an application that runs in a cluster and configures
an HTTP load balancer according to Ingress resources. The load balancer
can be a software load balancer running in the cluster or a hardware or
cloud load balancer running externally. Different load balancers require
different Ingress controller implementations.
There are many different Ingress controllers, and there’s support for
cloud-native load balancers (from GCP, AWS, and Azure). e.g. Nginx,
Ambassador, EnRoute, HAProxy, AWS ALB, AKS Application Gateway
Use Cases
Services
Source
What is a Service in Kubernetes?
Translate to
Services are a good abstraction for loose coupling for communication within
the cluster, but also from external services like a browser request coming to
the cluster.
Service automatically discovers a new pod with labels that match the selector.
This process seamlessly adds new pods to the service, and at the same time,
removes terminated pods from the cluster.
ClusterIP
NodePort
LoadBalancer
Translate to
ExternalName
Service gets single IP, DNS and Port that never change.
Service enables how pods talk to each other inside the cluster.
Service only sends traffic to healthy Pods and hide unreliable Pods.
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
selector:
app: MyApp
ports:
- protocol: TCP
port: 80
targetPort: 9376
As soon as a new pod appears in a cluster, with labels matching with Service’s
selector , the app=MyApp in the example above - Service will start sending
traffic to it.
Endpoints
Usually, we don’t see Endpoints objects when using Kubernetes Services, as
Translate to
they are working under the hood, similarly to ReplicaSets which are “hidden”
behind Kubernetes Deployments.
Container Registry
Docker Hub
References:
medium.com
medium.com
medium.com
medium.com
medium.com
medium.com
itnext.io
This article will be updated with more details theory and practical included
as I progress on my learning journey. Stay tuned. The notes is for sure
going to help you learn more and crack your next Kubernetes interview.
Ending Notes
I am active on Medium so please reach out to me in case you want to have a
Translate to
conversation. Happy to help. For any freelancing work or a healthy
conversation — reach me out at [email protected] or LinkedIn
If you enjoyed this article, consider trying out the AI service I recommend. It
provides the same performance and functions to ChatGPT Plus(GPT-4) but
more cost-effective, at just $6/month (Special offer for $1/month). Click here
to try ZAI.chat.
VenKube
6 min read
Tamer Benhassan
3 min read
Jake Page
The guide to kubectl I never had.
What kind of engineer are you? 🤔 Translate to
Can somebody guess by just looking at you? More than
likely not.
17 min read
Ammar Suhail
KUBERNETES NETWORKING
What Kubernetes networking solves
6 min read
Medha Choudhary
2 min read
Lubomir Tobek
10 min read