0% found this document useful (0 votes)
18 views

Kubernetes

Kubernetes is an open-source platform for managing containerized workloads across clusters of hosts that facilitates both declarative configuration and automation. It provides key functions such as service discovery and load balancing, storage orchestration, deployment and scaling, and self-healing capabilities.

Uploaded by

mail.anik.sinha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Kubernetes

Kubernetes is an open-source platform for managing containerized workloads across clusters of hosts that facilitates both declarative configuration and automation. It provides key functions such as service discovery and load balancing, storage orchestration, deployment and scaling, and self-healing capabilities.

Uploaded by

mail.anik.sinha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

-

Sunbeam Infotech www.sunbeaminfo.com


What is Kubernetes ? 8 container orchestration

§ Portable, extensible, open-source platform for managing containerized workloads and services
§ Facilitates both declarative configuration and automation
§ It has a large, rapidly growing ecosystem
§ Kubernetes services, support, and tools are widely available
-
-

§ The name Kubernetes originates from Greek, meaning helmsman or pilot

dedaoahuecong.g.gg#+
§ Google open-sourced the Kubernetes project in 2014

→ ✗ MI -


→ yami →

json
→ - ✓

Sunbeam Infotech www.sunbeaminfo.com


Traditional Deployment
-

§ Early on, organizations ran applications on physical servers


-

§ There was no way to define resource boundaries for applications in a


physical server, and this caused resource allocation issues
§ For example, if multiple applications run on a physical server, there can be
instances where one application would take up most of the resources, and App App App App
as a result, the other applications would underperform
§ A solution for this would be to run each application on a different physical Bin/Library
server
Operating System
§ But this did not scale as resources were underutilized, and it was expensive
for organizations to maintain many physical servers Hardware

Sunbeam Infotech www.sunbeaminfo.com


Virtualized Deployment
-

§ It allows you to run multiple Virtual Machines (VMs) on a single


physical server’s CPU
Virtual Machine Virtual Machine &

§ Virtualization allows applications to be isolated between VMs ① ③ £ ① ② ③


and provides a level of security as the information of one App App App App App App
application cannot be freely accessed by another application
§ Virtualization allows better utilization of resources in a physical Bin/Library Bin/Library


server and allows better scalability because
Operating System Operating System
§ an application can be added or updated easily
§ reduces hardware costs
§ With virtualization you can present a set of physical resources Hypervisor
as a cluster of disposable virtual machines
Operating System
§ Each VM is a full machine running all the components,
including its own operating system, on top of the virtualized Hardware
hardware

Sunbeam Infotech www.sunbeaminfo.com


Container deployment

§ Containers are similar to VMs, but they have relaxed isolation imac
properties to share the Operating System (OS) among the
applications
Container 1 Container a
§ Therefore, containers are considered lightweight =

§ Similar to a VM, a container has its own filesystem, CPU, App App App App App App

÷
memory, process space, and more
Bin/Library Bin/Library
§ As they are decoupled from the underlying infrastructure, they
are portable across clouds and OS distributions
.
Container Runtime

Operating System

Hardware

Sunbeam Infotech www.sunbeaminfo.com


Container benefits

§ Increased ease and efficiency of container image creation compared to VM image use

=
§ Continuous development, integration, and deployment
§ Dev and Ops separation of concerns
§ Observability not only surfaces OS-level information and metrics, but also application health and other
signals
§ Cloud and OS distribution portability
§ Application-centric management:
§ Loosely coupled, distributed, elastic, liberated micro-services
§ Resource isolation: predictable application performance

Sunbeam Infotech www.sunbeaminfo.com


What Kubernetes provide?

§ Service discovery and load balancing

E-
§ Kubernetes can expose a container using the DNS name or using their own IP address
§ If traffic to a container is high, Kubernetes is able to load balance and distribute the network traffic so that the
deployment is stable
§ Storage orchestration
§ Kubernetes allows you to automatically mount a storage system of your choice, such as local storages,
public cloud providers, and more
-

§ 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
§ Automatic bin packing
§ You provide Kubernetes with a cluster of nodes that it can use to run containerized tasks
§ You tell Kubernetes how much CPU and memory (RAM) each container needs
§ Kubernetes can fit containers onto your nodes to make the best use of your resources

Sunbeam Infotech www.sunbeaminfo.com


What Kubernetes provide?

§ Self-healing
=
§ Kubernetes restarts containers that fail, replaces containers, kills containers that don’t respond to your user-
- - -

defined health check, and doesn’t advertise them to clients until they are ready to serve
=
-

§ Secret and configuration management


§ Kubernetes lets you store and manage sensitive information, such as passwords, OAuth tokens, and ssh
keys
§ You can deploy and update secrets and application configuration without rebuilding your container images,
and without exposing secrets in your stack configuration

Sunbeam Infotech www.sunbeaminfo.com


What Kubernetes is not

§ Does not limit the types of applications supported ° " "" "" "
""

t÷#
§ Does not deploy source code and does not build your application
§ Does not provide application-level services as built-in services
§ Does not dictate logging, monitoring, or alerting solutions
§ Does not provide nor mandate a configuration language/system

E-
§ Does not provide nor adopt any comprehensive machine configuration, maintenance, management,
or self-healing systems

Sunbeam Infotech www.sunbeaminfo.com


Kubernetes Cluster

..÷ ÷:
§ When you deploy Kubernetes, you get a
cluster.
§ A cluster is a set of machines (nodes), that Master
run containerized applications managed by
Kubernetes
§ A cluster has at least one worker node and
at least one master node
§ The worker node(s) host the pods that are service
the components of the application
§ The master node(s) manages the worker worker I
worker -2
# - __

nodes and the pods in the cluster


§ Multiple master nodes are used to provide a
cluster with failover and high availability

Sunbeam Infotech www.sunbeaminfo.com


Kubernetes Architecture

I Eid -
-1 →

Fo
⑧⑤

cluster

N
RE
/
/ →

↳ client
ˢe↳%% services master

Sunbeam Infotech www.sunbeaminfo.com


?⃝
?⃝
l☒.li?:5F-a.nase
container Kabelet

kabeiet
master
women l☒☒

p?•f
¥¥÷±
÷÷÷t
sÉ ÑI
l☒l☒

V
"" "
Kubernetes Components
-

( master & worker)


Master Node

=kube-apiserver

etcd kubelet

E-
kube-scheduler

kube-controller-manager
= kube-proxy

Container Runtime

cloud-controller-manager

Sunbeam Infotech www.sunbeaminfo.com


Master Components

==-
§ Master components make global decisions about the and they detect and respond to cluster events
§ Master components can be run on any machine in the cluster
①§ kube-apiserver
§ The API server is a component that exposes the Kubernetes API
§ The API server is the front end for the Kubernetes
②§ etcd
=

- %n
§ Consistent and highly-available key value store used as Kubernetes’ backing store for all cluster data

③§ kube-scheduler
§ Component on the master that watches newly created pods that have no node assigned, -
and selects a node
for them to run on

☐ €
÷÷ ÷÷
Sunbeam Infotech www.sunbeaminfo.com
Master Components

④§ kube-controller-manager
§ Component on the master that runs controllers
§ Logically, each controller is a separate process, but to reduce complexity, they are all compiled into a single
-

binary and run in a single process


_

§ Types
§ Node Controller: Responsible for noticing and responding when nodes go down.
§ Replication Controller: Responsible for maintaining the correct number of pods for every replication
controller object in the system
§ Endpoints Controller: Populates the Endpoints object (that is, joins Services & Pods)
§ Service Account & Token Controllers: Create default accounts and API access tokens for new
namespaces
§ cloud-controller-manager
§ Runs controllers that interact with the underlying cloud providers
§ The cloud-controller-manager binary is an alpha feature introduced in Kubernetes release 1.6

Sunbeam Infotech www.sunbeaminfo.com


Node Components

§ Node components run on every node, maintaining running pods and providing the Kubernetes runtime
=

dingmastFN-I-a.FI
environment
§ kubelet
§ An agent that runs on each node in the cluster
§ It makes sure that containers are running in a pod
§ kube-proxy
§ Network proxy that runs on each node in your cluster, implementing part of the Kubernetes service concept
§ kube-proxy maintains network rules on nodes
§ These network rules allow network communication to your Pods from network sessions inside or outside of
your cluster
§ Container Runtime [ ]
docker

§ The container runtime is the software that is responsible for running containers
a-
§ Kubernetes supports several container runtimes: Docker, containerd, rktlet, cri-o etc.

Sunbeam Infotech www.sunbeaminfo.com


Create Cluster

§ Use following commands on both master and worker nodes

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

Sunbeam Infotech www.sunbeaminfo.com


Initialize Cluster Master Node

§ Execute following commands on master node

> kubeadm init --apiserver-advertise-address=<ip-address> --pod-network-cidr=10.244.0.0/16


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

§ Install pod network add-on

> kubectl apply -f


https://raw.githubusercontent.com/coreos/flannel/2140ac876ef134e0ed5af15c65e414cf26827915/Docu
mentation/kube-flannel.yml

Sunbeam Infotech www.sunbeaminfo.com


Add worker nodes

§ Execute following command on every worker node

> kubeadm join --token <token> <control-plane-host>:<control-plane-port> --discovery-token-ca-cert-


hash sha256:<hash>

Sunbeam Infotech www.sunbeaminfo.com


Steps to install Kubernetes

5 join join

4 POD Network

3 initialize

2 kubeadm kubeadm kubeadm

1 docker docker docker

Master Worker Node 1 Worker Node 2

Sunbeam Infotech www.sunbeaminfo.com


Kubernetes Objects

ÉÉ
§ The basic Kubernetes objects include
§ Pod
§ Service
§ Volume
§ Namespace
§ Kubernetes also contains higher-level abstractions build upon the basic objects
§ Deployment
§ DaemonSet
§ StatefulSet
§ ReplicaSet
§ Job

Sunbeam Infotech www.sunbeaminfo.com


Pod

§ A Pod is the basic execution unit of a Kubernetes application


-

§ The smallest and simplest unit in the Kubernetes object model that you create or deploy
-

§ A Pod represents processes running on your Cluster


-

§ Pod represents a unit of deployment

E-
§ A Pod encapsulates
§ application’s container (or, in some cases, multiple containers)
§ storage resources
/ app code

Libra
,

§ a unique network IP binary ,

§ F-
options that govern how the container(s) should run

our one OR
a pod may
more containers within it .

Sunbeam Infotech www.sunbeaminfo.com


fapioveos.TT#apiueosion to be used

/kind '" "


" """ " .

eg pod / service

→ more information about


object

→ Specification of object
YAML to create Pod

apiVersion: v1
kind: Pod
metadata:
name: myapp-pod

E-
labels:
app: myapp
spec:
containers:

E-=
- name: myapp-container
image: httpd

Sunbeam Infotech www.sunbeaminfo.com


☒±fE H÷÷É÷÷:
client
÷÷i÷i÷÷¥i t ↑
.
t
.

↓ ↑

↓ ↑

cluster
Service
=

§ An abstract way to expose an application running on a set of Pods as

=
a network service
§ Service is an abstraction which defines a logical set of Pods and a
policy by which to access them (sometimes this pattern is called a apiVersion: v1
micro-service) kind: Service
metadata:
§ Service Types name: my-service
§ ClusterIP spec:

⇐"÷÷
§ Exposes the Service on a cluster-internal IP selector:
§ Choosing this value makes the Service only reachable from within app: MyApp
the cluster ports:
§ LoadBalancer - protocol: TCP
§ Used for load balancing the containers port: 80
§ NodePort targetPort: 9376

Sunbeam Infotech www.sunbeaminfo.com



tF]
1T¥
mini tube

consumes

☐÷÷÷÷÷ii !÷ ÷:i:÷i: ÷i÷÷


cool http
'

p
which Pod
port on

gop
used by consumer

"
,

cuz I http:// 10 - o - o 't


curl http://io.o.o.3

¥±o¥÷:¥!÷:
÷i÷÷÷¥÷±E
http://192.168#T:G446
r
tunnel seoi
°
/

v01
client services
-
-

192.168-1-20
Service Type: NodePort

§ Exposes the Service on each Node’s IP at a static port (the NodePort)


§ You’ll be able to contact the NodePort Service, from outside the cluster, by
requesting <NodeIP>:<NodePort>
= =
Node 192.168.156g

:#

10.100.2.45
A- E-
Port TargetPort
Service

if

80
32000
80
10.30.4.6

http://#85-3L
NodePort
client =
POD
-

Sunbeam Infotech www.sunbeaminfo.com


Replication Controller

§ A ReplicationController ensures that a specified number of pod apiVersion: v1


replicas are running at any one time kind: ReplicationController
metadata:
§ In other words, a ReplicationController makes sure that a pod or name: nginx
a homogeneous set of pods is always up and available spec:
§ If there are too many pods, the ReplicationController terminates replicas: 3
selector:
the extra pods app: nginx
§ If there are too few, the ReplicationController starts more pods template:
metadata:
§ Unlike manually created pods, the pods maintained by a name: nginx
ReplicationController are automatically replaced if they fail, are labels:
deleted, or are terminated app: nginx
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80

Sunbeam Infotech www.sunbeaminfo.com


Deployment

§ A Deployment provides declarative updates for Pods and apiVersion: apps/v1


kind: Deployment
ReplicaSets metadata:
§ You describe a desired state in a Deployment, and the name: website-deployment
Deployment Controller changes the actual state to the spec:
desired state at a controlled rate selector:
matchLabels:
§ You can use deployment for app: website
§ Rolling out ReplicaSet replicas: 10
template:
§ Declaring new state of Pods metadata:
§ Rolling back to earlier deployment version name: website-pod
§ Scaling up deployment policies labels:
§ Cleaning up existing ReplicaSet app: website
spec:
containers:
- name: website-container
image: pythoncpp/test_website
ports:
- containerPort: 80

Sunbeam Infotech www.sunbeaminfo.com


Volume

§ On-disk files in a Container are ephemeral, which presents some problems for non-trivial applications
when running in Containers
§ Problems
§ When a Container crashes, kubelet will restart it, but the files will be lost
§ When running Containers together in a Pod it is often necessary to share files between those Containers
§ The Kubernetes Volume abstraction solves both of these problems
§ A volume outlives any Containers that run within the Pod, and data is preserved across Container
restarts

Sunbeam Infotech www.sunbeaminfo.com


Namespace

§ Namespaces are intended for use in environments with many users spread across multiple teams, or
projects
§ Namespaces provide a scope for names
§ Names of resources need to be unique within a namespace, but not across namespaces
§ Namespaces can not be nested inside one another and each Kubernetes resource can only be in one
namespace
§ Namespaces are a way to divide cluster resources between multiple users

Sunbeam Infotech www.sunbeaminfo.com

You might also like