Kubernetes Demonstraion With 100slides
Kubernetes Demonstraion With 100slides
100 slides
Who am I?
• Developer Relations Manager at Redis Labs
• DockerLabs Incubator
2
Let’s start with an analogy..
A Cargo Ship…
Carries containers across the sea
A Cargo Ship…
Host Application as Containers ~ Worker Nodes
Overview
Worker Node-1
6
Control Ships..
Managing & Monitoring of the cargo ships
7
Control Ships..
Manage, Plan, Schedule, Monitor ~ Master
8
Overview
Worker Node-1
Master
9
Let’s talk about Master
Components..
Ship Cranes
Identifies the placement of containers
11
Ship Cranes
Identifies the right node to place a containers ~ Kube-Scheduler
12
Overview
Worker Node-1
Scheduler
Master
14
Cargo Ship Profiles
HA database ~ Which containers on which ships? When was it loaded?
15
Cargo Ship Profiles
HA database ~ Which containers on which ships? When was it loaded? ~ The ETCD Cluster
16
Overview
Worker Node-1
Scheduler
Master
ETCD
17
Offices in Dock
- Operation Team Office ~ Ship Handling, Control
- Cargo Team Office ~ verify if containers are damaged, ensure that new containers are rebuilt
- IT & Communication Office – Communication in between various ships
18
Controllers
- Node Controllers – Takes care of Nodes | Responsible for onboarding new nodes in a
cluster | Availability of Nodes
- Replicas Controller – Ensures that desired number of containers are running at all times
- Controller Manager - Manages all these controllers in place
19
Overview
Worker Node-1
Scheduler
Master
Controller
ETCD
Manager
20
How does each of these services communicate with each other?
21
Kube API Server
- A primary management component of k8s
- Responsible for orchestrating all operations within a cluster
- Exposes K8s API ,used by external users to perform management operation in
the cluster and number of controller to monitor the state of the cluster
API Server
22
Overview
kubectl
Scheduler
UI Controller
ETCD
Manager
23
In nutshell…
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
node1 Ready master 92s v1.14.2 192.168.0.18 <none> CentOS Linux 7 (Core) 4.4.0-141-generic docker://18.9.6
node2 Ready <none> 57s v1.14.2 192.168.0.17 <none> CentOS Linux 7 (Core) 4.4.0-141-generic docker://18.9.6
node3 NotReady <none> 39s v1.14.2 192.168.0.16 <none> CentOS Linux 7 (Core) 4.4.0-141-generic docker://18.9.6
node4 NotReady <none> 32s v1.14.2 192.168.0.15 <none> CentOS Linux 7 (Core) 4.4.0-141-generic docker://18.9.6
24
Let’s talk about Worker
Components..
Overview
kubectl
Scheduler
UI Controller
ETCD
Manager
Master
A Worker Node
26
Captain of the Ship
- Manages all sort of activity on the ship
- Let master ship knows they are interested to join
- Sending reports back to master about the status of the ship
- Sending reports about the status of the containers
27
Captain of the Ship ~ Kubelet
Agent which runs on each nodes of the container
28
Overview
kubectl Kubelet
Scheduler
UI Controller
ETCD
Manager
Worker Node-1
Master
29
Communication between Cargo Ships
How does two cargo ships communicate with each other?
30
Kube-proxy Service
How will web server running on one worker node reach out to DB server
on another worker node?
31
Internet
Overview Worker Node-1
Master
Kubelet Kube-proxy
Scheduler
API Server
Controller
ETCD
Manager
32
Let’s talk about Pods..
Internet
Overview Worker Node-1
Master
Kubelet Kube-proxy
Scheduler
API Server
Pod
Controller
ETCD
Manager
34
Internet
Overview Worker Node-1
Master
Kubelet Kube-proxy
Scheduler
API Server
Pod
Controller
ETCD
Manager
Container
35
Docker Containers
A popular Container Runtime
36
Internet
Overall Kubernetes Architecture
Pod
UI Controller
ETCD
Manager
Container
Master
Worker Node
37
Demo
38
Let’s Deep Dive into Pods…
Pod - Concepts
• What is Pod?
• Pod Deployment
• Multi-Container
• Pod Networking
• Inter-Pod & Intra-Pod Networking
• Pod Lifecycle
• Pod Manifest File
40
Atomic Unit of Scheduling
VM Container Pod
41
How Pods are deployed?
Scheduler
API Server
Pod
Container
Master
Cluster
42
Scaling the Pods to accommodate increasing traffic
Scheduler
API Server
Pod
Container
Master
Worker Node
43
What if node resources is getting insufficient?
Scheduler
API Server
Pod
Container
Master
Worker Node
44
What if node resources is getting insufficient?
Worker-2
Scheduler
API Server
Worker-1
Pod
Container
Master
Cluster
45
What if node resources is getting insufficient?
Worker-2
Scheduler
API Server
Worker-1
Pod
Container
Master
Cluster
46
2 Containers in a same Pod
Worker-2
Scheduler
API Server
Worker-1
Pod
Container
Master
Cluster
47
Pod Networking
Pod 1 Pod 2
10.0.30.50 10.0.30.60
48
How does these containers
inside Pods communicate with
External World?
Network Namespace
Pod 1 Pod 2
10.0.30.50 10.0.30.60
10.0.30.50:8080 10.0.30.50:3000
50
How does one Pod talk to
another Pod?
Welcome to Inter-Pod Communication..
Pod Networking
Pod 1 Pod 2
10.0.30.50 10.0.30.60
Pod Network
52
How does Intra-Pod
communication take place?
Intra-Pod Communication
Pod 1
Supporting
Main Container
Container
:8080 :3000
Localhost
10.0.30.50
:8080 :3000
54
A Look at Pod Manifest
55
Get a shell to a running Container
56
Get a shell to a running Container
57
Stages of Life Cycle of Pod
Lifecycle of a Pod
Pod
Failed
How can you ensure that there are 3 Pods instances which are always
available and running at point in time?
ReplicaSet
What is ReplicaSet all about?
Maintain a stable set of replica Pods running at any given time
a. If there are access Pods, they get killed and vice versa
b. New Pods are launched when they get failed, get deleted and terminated
Labels
#Pod-Spec
Selectors
apiVersion: v1
kind: pod
metadata:
name: nginx-Pod
labels:
app: guestbook
tier: frontend
env: dev
spec:
replicas: 5..
Equality-based Selectors Set-based Selectors
Operators: Operators:
Examples: Examples:
Commandline: Commandline:
In Manifest: In Manifest:
.. ..
selector: selector:
environment: production matchExpressions:
tier: frontend - {key:environment,operator:in,values:[prod,qa]}
.. - {key:tier,operator:Notin,values:[frontend,backend]}
..
Supports: Services, Replication Controller Supports: Job, Deployment, ReplicaSet, DaemonSet
64
65
Demo - ReplicaSet
• Manifest file
• Deploy app using RS
Display and validate RS
• Test – Node Fails
• Test – Scale Up
• Test – Scale Down
66
ReplicaSet Manifest File
67
Creating Nginx-rs Pods
$kubectl create –f nginx-rs.yaml
68
69
Scaling the Nginx Service
70
Deployment
Deployment
A Deployment controller provides declarative updates for Pods and ReplicaSets.
ReplicaSet
Do we need to create 3 different
manifest files for each on these?
Pods
• Multiple Replicas
• Upgrade
• Rollback
• Scale Up or Down
• Recreate
How it works?
Shutting down version A and then making sure, version A is turned off...
then bringing up version B.
Demerits:
• Blue/Green
Deployment Type – Rolling Updates
• RollingUpdate(Ramped or Incremental)
How it works?
Slowly rollout a version of app by replacing instances one after the other until all the instances are successfully
rolled out.
Assume that there are 10 instances of version A which is running behind the LB. Then update strategy starts with
one instance of version B is deployed When version B is ready to accept traffic, one instance of version A is
removed from the pool
Deployment Type - Canary
• Canary
- Ideal deployment method for someone who want to test newer version before it is deployed 100%.
How it works?
This method is all about gradually shifting production traffic from version A to version B.
Lets imagine that there are about 10 instances of app version A running inside a cluster. You use Canary
deployment when you dont want to upgrade all of your instances. Let's say you upgraded your 2 instances of ver A
to version B then do some testing. If test results are good, then you upgrade remaining 8 instances to version B.
Say, your version B is ready, then you completely shut down version A.
Deployment Type – Blue Green
• Blue Green
How it works?
Using this method, version B(which is GREEN) is deployed along side version A(which is BLUE) with exactly
same amount of instances.
After testing new version with all the requirement, the traffic is switched from version A to version B at the LB
level.
Demo - Deployment
- Manifest file
- Test – Scale Up
ReplicaSet
Pods
80
Deployment
81
Deployment => Pods + ReplicaSet
Deployment
ReplicaSet
Pods
82
3 Instances of same Nginx Apps running in the form
of Pods
83
3 Instances of same Nginx Apps running in the form
of Pods
Update Deployment
84
3 Instances of same Nginx Apps running in the form
of Pods
85
Scaling up
86
Listing Pods by Labels
87
Services
Services
89
Agenda
• What is Service?
• Type of Services
90
Services User
192.168.1.1
Frontend Service:
Service(frontend)
Backend Service:
Service(backend)
Node
91
Types of Services
LoadBalancer
ClusterIP NodePort
Node-1 Node-1
• Imagine you need to deploy one full fledge app which consists of
frontend app & backend app
94
User
192.168.1.1:31000
NodePort
10.210.1.1:8080
Services ClusterIP
95
Guestbook Demo
96
Thank You