Kuber Net Es

Download as pdf or txt
Download as pdf or txt
You are on page 1of 93

Kubernetes

Run Containers for Production


Node running Docker

2
Node running Docker

3
Clustering

4
Clustering

5
Container Orchestration

6
Orchestration Tools
● Docker Swarm ● Azure Container Service, AKS

● Kubernetes ● Google Kubernets Engine

● Mesosphere Marathon ● OpenShift

● AWS ECS & EKS

7
News from Past

8
Kubernetes History
● Created by Google to manage their containers AKA Borg
● Mid-2014: Google introduced Kubernetes as an open source version of Borg
● July 21-2015: Kubernetes v1.0 gets released. Along with the release, Google
partnered with the Linux Foundation to form the Cloud Native Computing
Foundation (CNCF).
● 2016: Kubernetes Goes Mainstream!
○ Kops, Minikube, kubeadm etc
○ September 29: Pokemon GO! Kubernetes Case Study Released!
● 2017: Enterprise Adoption
○ Google and IBM announce Istio
○ Github runs on Kubernetes
○ Oracle joined the Cloud Native Computing Foundation
9
Kubernetes Provides
● Service discovery and load balancing

● Storage orchestration

● Automated rollouts and rollbacks

● Automatic bin packing

● Self-healing

● Secret and configuration management


https://kubernetes.io/docs/concepts/overview/what-is-kubernetes/

10
Kubernetes Architecture

11
Master: Kube API Server
● Main Hero! Handles all the requests and enables communication
across stack services.

● Component on the master that exposes the Kubernetes API.

● It is the front-end for the Kubernetes control plane.

● Admins connects to it using Kubectl CLI

● Web Dashboard can be integrated with this API

● and many more integrations….

12
Master: ETCD Server
● Stores all the information

● Consistent and highly-available key value store used as Kubernetes’


backing store for all cluster data.

● Kube API stores retrieves info from it.

● Should be backed up regularly.

● Stores current state of everything in the cluster.

13
Master: Kube Scheduler
● watches newly created pods that have no node assigned, and
selects a node for them to run on
● Factors taken into account for scheduling decisions include
○ individual and collective resource requirements,
○ hardware/software/policy constraints,
○ affinity and anti-affinity specifications,
○ data locality,
○ inter-workload interference and deadlines

14
Master: Controller Manager
❖ Logically, each controller is a separate process,

❖ To reduce complexity, they are all compiled into a single binary and run in a
single process.

❖ These controllers include:


➢ 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 namespace
15
Node Components
● 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
○ Network Rule
■ rules allow network communication to your Pods inside or outside of your cluster

● Container Runtime: Kubernetes supports several container runtimes:


○ Docker,
○ containerd,
○ cri-o, rktlet
○ Kubernetes CRI (Container Runtime Interface)

16
Addons
● DNS

● Web UI

● Container Resource Monitoring

● Cluster Level Logging

17
Addons

18
PODS

19
PODS

20
Overlay Network

21
Kubernetes Setup Tools
● Hard Way: Manual Setup
● Minikube:
○ One Node Kubernetes cluster on your computer
● Kubeadm:
○ Multi node Kubernetes Cluster
○ Can be created on any Platforms vm’s, ec2, physical machines etc
● Kops:
○ Multi node Kubernetes Cluster on AWS

22
Setup with Minikube
● Open Powershell as Admin
● Setup Chocolaty
● Install Minikube with Chocolaty

choco install minikube kubernetes-cli

● Open PowerShell and run


minikube start

23
Setup with Kops
(Prerequisites)
● Domain for Kubernetes DNS records
○ e:g groophy.in from GoDaddy

● Create a linux VM and setup.


○ kops, kubectl, ssh keys, awscli

● Login to AWS account and setup


○ s3 bucket, IAM User for AWSCli, Route53 Hosted Zone.

24
Setup with Kops
Login to Domain Registrar(GoDaddy)
Create NS records for subdomain pointing to Routes 53 hosted zone NS servers

25
1

PODS
Run your apps Isolated
PODS
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.

● Pods that run a single container.


○ The “one-container-per-Pod” model is the most common Kubernetes use case.
○ Pod as a wrapper around a single container,
○ Kubernetes manages the Pods rather than the containers directly.

● Multi Container POD


○ Tightly coupled and need to share resources
○ One Main container and other as a sidecar or init container
○ Each Pod is meant to run a single instance of a given application
○ Should use multiple Pods to scale horizantally.

.https://kubernetes.io/docs/concepts/workloads/pods/pod-overview/

27
Definitions file in YAML

28
Definitions file in YAML
pod-setup.yml

Kind Version

POD v1

Service v1

Deployment apps/v1

Ingress networking.../v1beta1

29
Definitions file in YAML
pod-setup.yml

30
Definitions file in YAML
pod-setup.yml

31
pod-setup.yml

32
pod-setup.yml

33
Create and get POD Info

34
Deatailed POD Info

35
Get & EDIT POD

36
2

Service
Connect with or To your POD
SERVICE
Way to expose an application running on a
set of Pods as a network service.
Similar to Load Balancers

38
SERVICE

39
SERVICE

40
SERVICE

41
Setup with Kops

42
Service | NodePort

43
Service | NodePort

44
SERVICE
NODEPort

45
SERVICE
NODEPort

46
Service | ClusterIP
Service | ClusterIP
NodePort & ClusterIP

NODEPort

ClusterIP

ClusterIP

49
Service | LoadBalancer
LoadBalancer & ClusterIP
3

Replication Controller
Keep your running all the TIME
Replication Controller
● Pods maintained by a ReplicationController are automatically replaced if
they fail, are deleted, or are terminated

● If there are too many pods, the ReplicationController terminates the extra
pods.

● If there are too few, the ReplicationController starts more pods.

53
POD without Replication Controller
POD without Replication Controller
POD without Replication Controller
POD with Replication Controller
Scaling with Replication Controller
Replication Controller Definition
Replication Controller Definition
Create & View RC
Edit & Scale RC
ReplicaSet
Maintain Pod Replica
Replicaset
● A ReplicaSet's purpose is to maintain a stable set of replica Pods
running at any given time

64
Deployment
Upgrade, RollBack, Changes Gracefully
Deployment
● A Deployment controller provides declarative updates for Pods and

ReplicaSets.

● Define desired state in a Deployment, and the Deployment controller

changes the actual state to the desired state at a controlled rate.

● Deployment creates ReplicaSet to manage number of PODS

66
Deployment

67
Deployment
Deployment
Deployment | Replication Controller
Create & View Deployment

71
View & Edit Deployment

72
Edit Deployment

73
Namespaces
Group your resources
Connect SVC in Namespaces

Web Pod db.service DB Service

Web Pod db-service.dev.svc.cluster.local DB Service

78
Use Namespace

79
Command & Arguments
Pass Command & Args to your POD
Command & Entrypoint
FROM ubuntu
docker run printer
CMD [“echo hi”]

FROM ubuntu docker run printer hi


ENTRYPOINT[“echo”]

docker run printer


FROM ubuntu
ENTRYPOINT[echo]
CMD [“hi”]
docker run printer hello

81
Command & Entrypoint
FROM ubuntu
ENTRYPOINT[sleep]
CMD [“5”]

docker run ubuntu-halt 15

ENTRYPOINT[sleep]
CMD [“5”]

82
Environment Variables
Assign Variable Values
Environment Variables

84
Config Maps
Set & Inject Variables/files in POD
Create Config Maps | Imperative

86
Create Config Maps | Declarative

87
POD Reading Config Maps

88
Secrets
Share encoded/encrypted variables to POD
Store and manage sensitive information, such as passwords
Create Secrets | Imperative

90
Create Secrets | Declarative

91
POD Reading Secret

92
Secret as a Volume

93

You might also like