Lecture 07: Kubernetes

IIT Kanpur July 201
20 followers
2 Video Views·Feb 6, 2024
[Music]
kubernetes I am Dr rajim Mishra
Professor Department of computer science
and engineering at Indian Institute of
Technology Patna content of this
lecture in this lecture we are going to
introduce kubernetes then we will see
why is kubernetes required then
components of kubernetes and finally
deploying applications with
kubernetes so let us begin with the
introduction to
kubernetes so
kubernetes is the Greek
word
for hman or a captain of a
ship now the symbol Sy which is
used is drawn
from
that wheel to drive the ship by the
captain so kubernetes is also known as
k8s so k8s is an abbreviation which
results from counting the eight letters
between K and S this becomes it has
kubernetes now
kubernetes is was built by the Google
based on the experience of running
containers in the production cluster
kubernetes is an open-source
container orchestration platform given
by Google and that was outsourced or
sorry that was open sourced in
2014 so what is container
orchestration when we say that
kubernetes is an open source container
orchestration platform so container
orchestration means that overall process
of managing the life cycle of
containers that usually run in a
production environment
requires a method that is called
container
orchestration now the question is why
this
separate container orchestration is
required to manage the life cycle of
containers in a production
environment so container orchestration
is required due to the rise in
microservice architecture and the use of
containerization which is increased
tremendously in recent times so
therefore the large applications which
are spanning across multiple containers
need to be managed not manually but
automatically and that management of a
life cycle of a container is very much
needed due to the large
scale deployment and therefore container
orchestration becomes an essential
component which is very much
needed so these containers for example
may be deployed by an
organization to host its application
such as web servers email servers
business servers which earlier used to
host on Virtual machines or a dedicated
server now therefore the modern
application development heavily favors
microservice architecture and due to
this rise of microservice
architecture the use of conization has
increased tremendously now this micros
service
are now being
provided in a containerized form since
it becomes easy to develop deploy manage
them
independently so the containers provide
greater benefit over hosting
applications on Virtual
machines eventually this results in a
large scale applications to grow and
span multiple containers deployed across
multiple servers or the notes so the
operating them become so complex so to
manage this complexity a orchestration
is required and therefore this becomes
the answer to the question why is
container container orchestration is
required now coming to more details
about the kubernetes is that kubernetes
takes this approach of clustering notes
and orchestrating containers on a
cluster level therefore kubernetes if
you understand is that not only it
manages the
physical
infrastructure that is the servers which
are networked
across but also it manages the
containers which are running on this
particular cluster level so
kubernetes has to do both the tasks so
container arest
to be more focusing on this aspect of
kubernetes includes a range of functions
including not limited to
provisioning
organizational Primitives sheduling
automated health checks
autoscaling upgrade strategies and
service Discovery let us understand
these terms in more details so
provisioning that instock calling or
upgrading the local operating system on
a node or setting up the container
runtime there organizational Primitives
such as labels in kubernetes quering the
containers grouping the containers and
so on scheduling of containers to run on
the host that is on the nodes of a
cluster automated health checks is to
determine if the container is alive and
ready to serve the traffic and to
relaunch it if necessary
autoscaling that is increasing or
decreasing the number of containers
based on utilization or a higher level
metric upgrade strategies
providing rolling updates and roll back
mechanisms service Discovery to
determine which host is a scheduled
container entered upon you usually
including the DNS support so therefore
these are some of the aspects of
container orchestration which cuberes is
required to
manage now let us see the
working
of our understanding of kubernetes is in
in more details so there in the figure
shows the C is architecture which
follows the master worker model so you
can see set of the nodes are termed as
master and similarly on the right side
the set of nodes they are termed as the
worker
nodes so this becomes an architecture
cuber
netus
so
kubernetes where the master known as the
control plane
here so this is called control
plane and this
master manages
so this master is also known as the
control plane which
manages the worker
nodes now on the other hand the
containers are deployed and executed on
the worker nodes here in the worker
nodes the
containers are
deployed
and executed in the container in the
worker nodes so these nodes have the
virtual machines on premise or on the
cloud or on the physical
servers they have the virtual
machines now this kubernetes cluster in
this particular
figure is a collection of the nodes that
are divided into two
groups
that is the master and the worker
know so these are divided into two
groups so therefore it is the master it
is the master
node and the other one is the worker
nodes now the master nodes will run the
cuber net is control
plane so the master will run the
kubernetes control plane which control
the
cluster while the worker node will run
the application and therefore we'll
represent the work workload plane the
workload plane is also sometimes called
a data plane now the control plane is
responsible
for
managing the state of the cluster
here in the production environment the
control plane May span across multiple
nodes or even multiple data centers the
workload plane or a data plane contains
the worker note that run in a cized
application workloads the cized
application run in a pod now kubernetes
parts so parts are the smallest
Deployable unit in
kubernetes pod is POD is the
smallest
Deployable units
they are the basic building blocks of
kubernetes application so the a pod
hosts one or more containers and
provide the shared storage
networking for those
containers so you can see here the Pod
hosts the
containers and once it host the
container then it has it has to provide
a
shared
storage across these
containers and
networking for these containers
therefore the parts represent the set of
running containers in a
cluster that is it becomes the the
running clusters
therefore the parts are created and
managed by the kubernetes control
plane now going to more detail about the
kubernetes control
plane now control plane consist of the
number of core components they are the
API server
etcd then
scheduler and the controller
manager now coming to this API
server so API server is primary
interface between the control plane and
the rest of this
particular
cluster now it exposes a restful API
that allows the client to interact
with the control plane and submit the
request to
manage the cluster for
example Cube
CTL is a command line interface that can
be used to manage the kubernetes cluster
it uses sttp rest API to talk to the API
server now edcd
here it is is a
distributed key value
store that is a database it is used by
the API server and other components of
the control plane to store and retrieve
information about the cluster it stores
the Clusters persistent state which
includes object
data what are the kubernetes objects so
they are the entities to represents the
state of the cluster for example they
can describe what cized applications are
running on and on which notes the
resources available to those
applications the policies around
how those applications behave such as
restart policies upgrades fall tolerance
now coming to the scheduler so scheduler
is
responsible for scheduling Parts onto
the worker
nodes Parts onto the worker nodes in the
cluster it uses the information about
resource required by the
parts and the available resources on the
worker
nodes to make the cluster to make the
container placement
decisions the controller manager
is responsible for running
controllers
that manage the state of the
cluster in
kubernetes controllers are the control
loops that watch the state of the
cluster and then make or request changes
wherever needed it is similar to the
control Loop like in robotics and
automation that is non-terminating Loop
that regulates the state of the system
now each control controller tries to
move the current
state the cluster state closer to the
desired state so controllers can also be
created by the
users Engineers using kubernetes
apis the core component of kubernetes
that run on worker nodes
includes
cuets
so here you can see
cuets so cubet is a
dam and
container cuet and a container
runtime and Cube proxy there are three
different
components of kubernetes that run on the
worker node so we are talking about the
worker node
now of a cuberes
cluster so coming to the first first
component that is cubet of a worker node
so cuet is a dum that run on each worker
node and it is responsible for
communicating with the control
plane it receives the instruction from
the control plane about which parts to
run on the nodes and ensure that the
desired state of the parts are
maintained then next is the container
runtime of a worker node so container
runtime runs the container on the worker
nodes it is responsible for pulling the
container images from the registry
starting and stopping the containers and
managing the containers
resources the next is Q
proxy in a worker node so Q proxy is a
network proxy that runs on each worker
node and it is responsible for routing
traffic to the correct
pod it also provides load balancing for
parts and ensures that traffic is
distributed evenly across the parts so
covering more details of a kubernetes
cluster now regardless of the number of
worker notes in a kubernetes
cluster they all become a single place
to deploy the application using
kubernetes API hence
instead of deploying an application to a
server or virtual machine it deploy in a
uh into a cluster instead a very
important component of a kubernetes
which enables these
notes which enables those notes worker
notes and master notes to talk to each
other in a virtual Network that spans
all the notes that are part of the
cluster in in a simple
words a virtual Network turns all the
nodes inside of a cluster into one
powerful machine that can be seen as the
sum of all the resources of individual
nodes so the kubernetes API server
exposes restful
API the client
using the cluster and other kubernetes
component can create objects via API so
API server has the following function
provides a consistent way of storing
objects in EC in
etcd perform validation of those objects
so the client can't store improperly
configured objects provides an API to
create update modify delete resource a
kubernetes resource is an end point in
the kubernetes API that stores a
collection of objects of certain kind
for example the buil-in Parts resource
type contains the collection of pod
objects Now API server also
performs authentication and
authorization of request that the client
sends and is responsible for admission
control if the request is trying to
create modify or delete a
resource it should be noted that only
component that talks to etcd is API
server that is shown or the component
read and write data to Etc D indirectly
through API server
therefore the etcd also implements the
watch feature which provides an event
based interface for asynchronously
monitoring the
changes stored data in the form of the
keys now when a key
changes its Watchers get notified the
API server component relies
on this notification to Monitor and move
the current state of the etcd towards
the desired state in kubernetes
controllers are
components responsible for managing and
maintaining a desired state for various
resources they help ensure that the
current state of the system matches the
desired State almost every kubernetes
object includes two nested objects
fields that govern the object's
configuration the object specs and the
object status so espcs describe the
desired state of the objects the status
describes the current state of the
object supplied and updated by the kuber
system and its components in
cuberes controllers are the
components responsible for managing and
maintaining the desired state for
various resources they help ensure that
the current state of the system matches
the desired State a controller can track
one or more kubernetes resource type
examples of some controllers such as
replica
set replicas at controller ensures a
specified number of replicas of the Pod
are running at all times deployment
controller provide a declarative way to
manage
applications they
use replica sets under the hood but
offer additional features such as
rolling updates roll back deployment are
commonly used for managing application
life cycle
changes stateful sets controller are
used to manage stateful applications
providing guarantees that ordering and
uniqueness of parts they are useful for
applications that require stable Network
identities and persistent storage name
is space
controller of a
kubernetes is a way to divide the
cluster resources between multiple users
teams or projects it provides a scope
for the names ensuring that the names of
resources within a name space are unique
the name space controller is responsible
for for managing these name spaces
within the kubernetes
cluster a node controller a node
controller is one of the core component
in the kubernetes control plane and its
primary responsibility is to manage the
life cycle of the nodes within the
cluster service controller that is the
end point the service controller is
responsible for managing the life cycle
of service resources in
kubernetes now when you create or modify
y a service the service controller
ensures that the corresponding end
points are created or
updated so what are the services and
point service a kuber service provides a
stable IP address and the port for a set
of Parts allowing other applications
within or outside the cluster to access
them the service controller manages the
creation and maintenance of the services
and points resources in the kubernetes
represents a set of addresses
corresponding to the parts backing a
service so when a pod are created or
modified the service controller updates
the end points to reflect the current
state of a healthy pod
addresses now demon
set ensure that all of or some nodes run
copy of the parts they are often used
for cluster level operations such as
running a monitoring agent on every node
job or and Crown jobs manage one or more
parts to perform a
particular uh task and ensure completion
Crown jobs are similar but allow you to
run the job periodically based on the
schedule scheduler is responsible for
assigning parts to the notes schedular
process works as follows the shular
watches for a newly created parts that
have no notes assigned for every part
that the sh discovers the Sher becomes
responsible for finding the best Note
for that part to run on the notes that
meet the scheduling requirement for the
part
gets called feasible notes if none of
the notes are suitable the part remains
unscheduled until the scheder placed it
once it finds a feasible it runs a set
of functions to score the notes and the
notes with the highest score gets
selected it then notifies the API server
about the selected node it is called the
process binding now coming to the
workload plane or a data plane side the
cubet that is the D that runs on each
worker node it is responsible for
communicating with the control plane it
talks to the API server and manages the
application running on its note it
receives the instruction from the
control plane about
which part to run on the Node and Ensure
that the desired state of the part is
maintained it reports the
status of application the node via API
the main function of Cu blade services
are register the node is running on by
creating the node resource in API server
continuously monitoring API server for
the part that got scheduled on that note
start the parts containers by using
configured container runtime
continuously monitor running containers
and Report their status events and
resource consumption to the API server
run the container liveness
proofs when the
proofs fails and termate the container
when the Pod gets deleted from the API
server the container runtime which can
be the docker or any other runtime
compatible with the containers run
application in a container as instructed
by CU blets there are two categories of
container run times the lower level
container run times
these focus on running the containers
and setting up name space and c groups
for the containers higher level
container run times these focus on the
formats unpacking manage management
sharing of images and providing apis for
developers container runtime can perform
tasks such as pulling the required
container image from an image registry
if it's not available locally prepare a
container Mount Point alert the kernel
to assign some resource limits like CPU
or the memory limit pass system call to
The Container to start the container now
kubernetes service proxy load balances
the network traffic between applications
the service proxy runs on the nodes and
ensure that one pod can talk to the
another pod one node can talk to another
node and container can talk to another
container it is responsible for watching
the API server for changes on the
service and part definitions to maintain
the entire network configuration up to
date now when a service gets backed by
more than one part the proxy performs
load balancing across the parts now let
us take this
kubernetes components from the Viewpoint
of an application deployment Now setup
includes suppose we have an application
that requires multiple container each
hosting a micros service although we can
run all the application container in
side a single pod it may be prone to the
note failure since the Pod runs on a
single so instead we can group
applications to run on a separate parts
that can be spread across multiple nodes
in this case the part must be able to
communicate with each other as per the
requirement of the application to
facilitate communication between the
Parts kubernetes offer cluster Network
which assigns IP address to each
part cluster network is a set of links
that facilitate communication within the
cluster note that this IP
address is assigned to each pod and not
to The
Container each pod can communicate with
the other using this IP address which is
an internal IP address how however parts
are ephemeral which means that they can
die very easily for example application
micros service is running inside the
container might crash and when that
happens the Pod will die and the new one
will be created in its
place consequently it will be
assigned a new IP address which may
become inconvenient for our applications
are directly using IP address to
communicate to address this issue
another component of communities called
a service is used so the service API is
an abstraction to expose the groups of
of Parts over the network these each
service object defines a logical set of
end points along with a policy about how
to make these those parts
accessible for example consider a
stateless image processing background
back end which is running with three
replicas those replicas
are funable that is frontend do not care
which back ends they
use while the actual parts that had
composed the back
end set may change the front end client
should
not need to be aware of that nor should
they need to keep track of the set of
backends themselves so the service
abstraction enables this decoupling it
should be noted that the life cycle of
the service and the parts are not
connected this means that the service
will stay the same even when the parts
die so the parts communicate with each
other using the
service so config map is an API object
used to store non-confidential data in
key value pairs Parts can consume config
Maps as environmental as environment
variable command line arguments or as
configuration files stored in volume
that is data storage a config map allows
to decouple environment specific
configuration from container images so
that your applications are easily
portable for example we can specify the
same application to run with the
different command line arguments in
different containers or the
parts so a secret is an object that
contains a small amount of sensitive
data such as password token key such
information might otherwise be put in a
pod specification or in a container
image using a secret means that you
don't need to include a confidential
data in your application code now
because Secrets can be created
independently of the parts that use them
there is less risk of secret being
exposed during the workflow of creating
viewing and editing
Parts secrets are similar to The config
Maps but are specifically intended to
hold confidential data Now secrets can
be used for for various purposes such as
the following setting up environment
variable for container providing
credentials such as
SSH keys or passwords to the parts allow
the cuet to pull container images from
private Registries using login
credentials persistent data storage in
kubernetes so kubernetes provides
volumes to persist the data generated by
containers to permanent storage by
default containers have no way to store
the data
persistently since all the data
associated with the container is removed
when the container is stops running so
volumes abstracts an external storage
and
presents it to the containers running
inside the partt so that the data can be
permanently stored replication now
kubernetes allow the parts to be
replicated this is useful for two major
reasons availability that is fa
tolerance uh in casee the node on a
cluster fails the second is due to the
load balancing it splits the workload
across multiple replicas of the same
applications now here the servic is are
common to all the replicas of a pod that
is to say that replicated Parts have the
same network address usually the
deployment process of an
application requires creating a
deployment configuration called
deployment in the in the kubernetes
given that an application may be
composed of multiple Parts the
application the replication factor that
is the number of replicas is usually
defined for the set of parts that the
application
uses the application Factor can be
defined in the deployment configuration
so deployment in the kubernetes also
allows for scaling of applications as
well
some parts are stateful for example
database application container in such a
case we cannot use the deployment in
instead we should use stateful set
stateful set in the kubernetes manages
the deployment and scaling of the set of
parts and provides guarantees about the
ordering and uniqueness of these parts
like deployment stateful set manages
parts that are based on identically
specs unlike deployment a stateful set
maintains ATI a sticky identity for each
of its parts these parts are created
from same spec but are not
interchangeable that is each part has a
persistent identifier that it
maintains across any schedule
scheduling stateful sets are useful for
the application that require one or more
of the following stable that is unique
Network identifiers stable that is
persistent storage order that is
graceful deployment and is scaling
ordered means automated roll rolling
updates so the concepts discussed so far
we can deploy the applications on a
kubernetes
cluster so the power of kubernetes to
deploy the software on the edge devices
now with a general overview of
components that make
kubernetes we can understand how to
deploy an application in the kubernetes
an application consist of several of the
objects one type represents the
application deployment as a whole
another represents a running instance of
your application another represents the
service provided by the set of these
instances and allow reaching them at a
single IP addresses and there are many
others these objects are usually defined
in one or more manifest files in either
yl or Json format so these actions take
place when we deploy an application on a
kubernetes uh cluster submits the
application manifest to the kubernetes
API the API server writes the objects
defined in the Manifest to the
etcd and the controller notices the
newly created objects and creates
several new objects one for each
application instance the schedular
assigns are mode to each instance fourth
is fourth step is the kubernetes notices
that an instance is assigned to the
cubelets notes it runs an application
instance VI the container runtime the
cube proxy notices that the application
instance is ready to accept the
connection from the client and
configures the load balancer for them
the cuets and the controllers monitor
the system and keep application running
for example in the figure you can see
deploying an application in the the iot
cloud Edge system so the architecture
diagram shows the workflow from the
cloud through the virtual cubet through
the edge provider down to all of the
edge devices first the virtual cuet
project lets you create a virtual node
in your C kubernetes cluster a virtual
node is not a VM like most of most other
nodes in the kubernetes cluster inry it
is an abstraction of a kubernetes node
that is provided by
virtual CU backing it is an iot Hub it
can schedule workloads to it and treat
it like any other kubernetes
nodes so when the workloads are
scheduled to this virtual node the Eds
provide provider comes in as depicted so
the edge connector and Edge
provider which are working in tandem
with the virtual cubet it takes the
workload specification that comes from
the kubernetes and converts it in it
into an iot S deployment then iot s
deployment is shipped back to the
backing
iot hub for its virtual node lastly the
iot Hub in turn pushes this deployment
down to all the targeted
devices so let us see the bfits
of using kubernetes the benefits of
kubernetes that you have
learned why many organization across the
world have have welcomed
kubernetes into their data center now
let's take a closer look at specific
benefits it brings to both the de the
development and it operation team first
is called Self Service deployment of an
application because kubernetes presents
all its worker notes as a a single
deployment surface it no longer matters
which node you deploy your application
to this means that the developers can
now deploy application on their
own even if they don't know anything
about the number of notes or the
characteristics of of each note in the
past the system administrator were the
one who decides who decided where each
application should be placed this task
is now left to the kubernetes this
allows a developer to deploy the
application without having to rely on
other people to do so when developer
deploy an application kubernetes chooses
the best node on which to run the
application based on the resource
requirement of the application and the
resources available in the each
node second benefit is reducing the cost
via better infrastructure
utilization so if you don't care which
node your application lands on
it also means that it can be moved to
any other node at any time without you
having to worry about it kubernetes may
need to do this to make the room for the
larger application that some one wants
to deploy this ability to move the
application allows the applications to
be packed tightly together so the
resources of the node can be utilized in
a best possible
way next benefit is automatically
adjusting to the changing
load now using kubernetes to manage your
deployed applications also means that
the operating operations team doesn't uh
have to constantly monitor the load of
each application to respond to the
certain load Peaks kubernetes takes care
of this also it can monitor the resource
consumed by each application and other
metrics and add adjust the number of
running instances of each applications
to cope with increased load and resource
Usage Now when you run kubernetes on the
cloud infrastructure it can even
increase the size of your cluster by
provisioning additional nodes through
the cloud providers API this way you
never run out of the space to run
additional instances of your
applications next benefit is keeping
applications running smoothly kubernetes
also makes every effort to ensure that
your applications running smoothly if
your applications crashes kubernetes
will restart automatically so even if
you have a broken application that runs
out of the memory after running for more
than a few hours kubernetes will ensure
that your application continues to
provide the service to its user by
automatically restarting it in this case
kubernetes is self-healing system in
that it deals with the software errors
like one just described but it also
handles Hardware failures as the
Clusters grow in size the frequency of
the node play also increases for example
in a cluster with one 100 nodes and a
empty BF that is meantime between
failure of 100 days for each node you
can expect one node to fail every day
now when a note fails kubernetes
automatically moves the application to
the remaining healthy nodes the
operation teams no longer need to be
manually moving the applications and can
inad focus on repairing the node itself
and returning it to the pool of the
available Hardware resources now if your
infrastructure has enough free resources
to allow the normal system operation
without the field nodes the operation
teams doesn't even have to react
immediately to the failure if it occurs
in the middle of the night no one from
the operation team even has to wake up
uh they can sleep peacefully and deal
with the Fai node during the regular
working
hours now
finally the last benefit is simplifying
application
development the Improvement described in
the in this
way mainly concern application
deployment but what about the process of
application development does the
communities bring anything to this to
their table it definitely does as
mentioned previously kubernetes offers
in infrastructure related services that
would otherwise have to be implemented
in your application this includes
discovery of
services and are peers in a distributed
application leader
election centralized application
configuration and others kubernetes
provides this while keeping the
application uh kubernetes agnostic but
when required the application can also
query kubernetes API to obtain detailed
information about their environment they
can also use the API to change the
environment
M conclusion in this lecture we
discussed about the overview of
kubernetes a container orchestration
tool the need for using the kubernetes
and its benefits component of the
kubernetes control plane and the worker
notes deployment of the application
using the
kubernetes thank
[Music]
you
[Music]
[Music]
[Music]
