KEMBAR78
Deep Dive into Kubernetes - Part 1 | PDF
Deep Dive into Kubernetes
Part 1
Imesh Gunaratne, WSO2
Agenda
● Kubernetes Architecture
● Container Orchestration:
○ Pods
○ Replica Sets
○ Deployments
● Internal Routing
○ Services
● External Routing
○ Ingresses & Ingress Controllers
Agenda Cont.
● Configuration Management
○ Config Maps
● Credentials Management
○ Secrets
● Persistent Volumes
● Rolling Out Updates
● Autoscaling
○ Horizontal Pod Autoscalers
Agenda Cont.
● Package Management
○ Helm
● Hello World Example
Kubernetes Architecture
Kubernetes Architecture
Node 1 Node 2 Node nMaster
API
Overlay Network
UI
CLI
Container Registry
API Server
Scheduler
Controller
etcd
Container Orchestration
Pods
● A pod is a group of containers that
share the file system, users, network
interfaces, etc
● By default a pod will include two
containers: one for the given docker
image and other for the network
interface
C1 C2 Cn
apiVersion: v1
kind: Pod
metadata:
name: myapp-pod
labels:
app: myapp
spec:
containers:
- name: myapp-container
image: busybox
command: ['sh', '-c', 'echo
Hello Kubernetes! && sleep 3600']
Replica Sets
● Replica Sets are used for
orchestrating pods
● They define the docker images,
resources, env. variables, ports,
etc required for creating pods
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: frontend
labels:
app: guestbook
spec:
replicas: 3
selector:
matchLabels:
tier: frontend
matchExpressions:
- {key: tier, operator: In}
template:
metadata:
labels:
...
spec:
containers:
- name: php-redis
image: foo:bar
ports:
- containerPort: 80
Replica Set
C1 C2
Deployments
● A deployment is used for
orchestrating pods via replica sets:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.7.9
ports:
- containerPort: 80
Replica Set
Deployment
C1 C2
Internal Routing
Services
kind: Service
apiVersion: v1
metadata:
name: my-service
spec:
selector:
app: MyApp
ports:
- protocol: TCP
port: 80
targetPort: 9376
Replica Set
Deployment
Service
● A service provides a layer 4 load
balancer for pods:
C1 C2
Pod to Pod Communication
Replica Set A
Deployment A
ServiceA
C1 C2
Deployment B
Replica Set B
C3 C4
ServiceB
External Routing
Ingresses
Replica Set
Deployment
Service
Ingress
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: test-ingress
annotations:
nginx.ingress.kubernetes.io/rewri
te-target: /
spec:
rules:
- http:
paths:
- path: /testpath
backend:
serviceName: test
servicePort: 80
● An ingress is used for configuring a
load balancer for external routing
C1 C2
Ingresses
Replica Set
Deployment
Service
Ingress
Ingress
Controller
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: test-ingress
annotations:
nginx.ingress.kubernetes.io/rewri
te-target: /
spec:
rules:
- http:
paths:
- path: /testpath
backend:
serviceName: test
servicePort: 80
● An ingress is used for configuring a
load balancer for external routing
C1 C2
Ingresses
Replica Set
Deployment
Service
Ingress
Ingress
Controller
LoadBalancer
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: test-ingress
annotations:
nginx.ingress.kubernetes.io/rewri
te-target: /
spec:
rules:
- http:
paths:
- path: /testpath
backend:
serviceName: test
servicePort: 80
● An ingress is used for configuring a
load balancer for external routing
C1 C2
Configuration Management
ConfigMaps
Replica Set
Deployment
Service
Ingress
Ingress
Controller
LoadBalancer
Config MapsConfig Files
● Configuration files can be injected
into pods using ConfigMaps
● A ConfigMap can be created for
key/value pairs, files and folders
Config MapsConfig Maps
C1 C2
Credentials Management
Config Maps
Secrets
Replica Set
Deployment
Service
Ingress
Ingress
Controller
LoadBalancer
Config Files
● Sensitive data such as
credentials, encryption keys can
be securely injected using
secrets
Config MapsConfig MapsConfig MapsSecrets
Config Maps
Credentials
C1 C2
Persistent Volumes
Config Maps
Persistent Volumes
Replica Set
Deployment
Config Files
Config Maps
Credentials
C1 C2
Persistent Volume ClaimPersistent Volumes
Service
● PVC defines volume size, and
type: ReadOnly, ReadWrite,
ReadWriteMany
Persistent Volume Types
● GCEPersistentDisk
● AWSElasticBlockStore
● AzureFile
● AzureDisk
● FC (Fibre Channel)**
● FlexVolume
● Flocker
● NFS
● iSCSI
● RBD (Ceph Block Device)
● CephFS
● Cinder (OpenStack block storage)
● Glusterfs
● VsphereVolume
● Quobyte Volumes
● VMware Photon
● Portworx Volumes
● ScaleIO Volumes
● StorageOS
https://kubernetes.io/docs/concepts/storage/persistent-volumes/#types-of-persistent-volumes
Rolling Out Updates
Deployment Process
Deployment V1 V1 Deploying...
Replica Set V1
Deployment V1 V1 Deploying...
Deployment Process
Replica Set V1
Deployment V1
P1 - V1 P2 - V1 Service
C1 C2
V1 Pods Starting...
Deployment Process
C1
Replica Set V1
Deployment V1
P1 - V1 P2 - V1 Service
C2
V1 Pods Activating...
Deployment Process
C1
Replica Set V1
Deployment V1
C2
P1 - V1 P2 - V1 Service
V1 Pods Healthy
Deployment Process
C1
Replica Set V1
Deployment V1
C2
P1 - V1 P2 - V1
Deployment V2
Service
Deploying V2...
Rolling Update Process
C1
Replica Set V1
Deployment V1
C2
P1 - V1 P2 - V1
Deployment V2
Replica Set V2
Service
Deploying V2...
Rolling Update Process
Replica Set V1
Deployment V1
C2
P1 - V1 P2 - V1
Deployment V2
Replica Set V2
P1 - V2Service
C3
V2 Pods Starting...
C4
P2 - V2
C1
Rolling Update Process
C1
Replica Set V1
Deployment V1
C2
P1 - V1 P2 - V1
Deployment V2
Replica Set V2
C3
P1 - V2Service
V2 Pods Activating...
P2 - V2
C4
Rolling Update Process
Replica Set V1
Deployment V1
P1 - V1 P2 - V1
Deployment V2
Replica Set V2
C3 C4
P1 - V2 P2 - V2
C1 C2
Service
V2 Pods Healthy
Rolling Update Process
Autoscaling
Horizontal Pod Autoscalers
Replica Set
Deployment
Service
● Enable autoscaling for pods based on CPU utilization
Horizontal Pod
Autoscaler
Resource Metrics API
C1 C2
Package Management
Helm
● Helm is the Kubernetes package manager.
● It uses Charts for defining, installing and upgrading
applications on Kubernetes.
● Runtime configurations can be templated and
parameterized.
● Existing Charts can be reused and added as dependencies to
new Charts.
● Helm is managed by CNCF.
https://docs.helm.sh
Helm Hello World
# templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
Name: hello-world
spec:
replicas: 1
template:
metadata:
labels:
app: hello-world
spec:
containers:
- name: hello-world
image:
gcr.io/google-samples/node-hello
:1.0
ports:
- containerPort: 8080
protocol: TCP
# chart.yaml
name: apps/v1
version:
# templates/service.yaml
kind: Service
apiVersion: v1
metadata:
name: hello-world
spec:
type: NodePort
selector:
app: hello-world
ports:
- protocol: TCP
port: 8080
targetPort: 8080
Hello World Demo
Questions & Feedback
References
References
● Kubernetes Documentation:
○ https://kubernetes.io/docs/
● An Introduction to Kubernetes:
○ https://www.slideshare.net/imesh/an-introduction-to-kubernetes
● WSO2Con US 2015 Kubernetes: a platform for automating deployment,
scaling, and operations:
○ https://www.slideshare.net/BrianGrant11/wso2con-us-2015-kube
rnetes-a-platform-for-automating-deployment-scaling-and-operati
ons
● Kubernetes: An Overview:
○ https://thenewstack.io/kubernetes-an-overview/
References Cont.
● Helm Documentation:
○ https://docs.helm.sh
● The missing CI/CD Kubernetes component: Helm package manager
○ https://medium.com/@gajus/the-missing-ci-cd-kubernetes-compon
ent-helm-package-manager-1fe002aac680
Thank You!

Deep Dive into Kubernetes - Part 1

  • 1.
    Deep Dive intoKubernetes Part 1 Imesh Gunaratne, WSO2
  • 2.
    Agenda ● Kubernetes Architecture ●Container Orchestration: ○ Pods ○ Replica Sets ○ Deployments ● Internal Routing ○ Services ● External Routing ○ Ingresses & Ingress Controllers
  • 3.
    Agenda Cont. ● ConfigurationManagement ○ Config Maps ● Credentials Management ○ Secrets ● Persistent Volumes ● Rolling Out Updates ● Autoscaling ○ Horizontal Pod Autoscalers
  • 4.
    Agenda Cont. ● PackageManagement ○ Helm ● Hello World Example
  • 5.
  • 6.
    Kubernetes Architecture Node 1Node 2 Node nMaster API Overlay Network UI CLI Container Registry API Server Scheduler Controller etcd
  • 7.
  • 8.
    Pods ● A podis a group of containers that share the file system, users, network interfaces, etc ● By default a pod will include two containers: one for the given docker image and other for the network interface C1 C2 Cn apiVersion: v1 kind: Pod metadata: name: myapp-pod labels: app: myapp spec: containers: - name: myapp-container image: busybox command: ['sh', '-c', 'echo Hello Kubernetes! && sleep 3600']
  • 9.
    Replica Sets ● ReplicaSets are used for orchestrating pods ● They define the docker images, resources, env. variables, ports, etc required for creating pods apiVersion: apps/v1 kind: ReplicaSet metadata: name: frontend labels: app: guestbook spec: replicas: 3 selector: matchLabels: tier: frontend matchExpressions: - {key: tier, operator: In} template: metadata: labels: ... spec: containers: - name: php-redis image: foo:bar ports: - containerPort: 80 Replica Set C1 C2
  • 10.
    Deployments ● A deploymentis used for orchestrating pods via replica sets: apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment spec: replicas: 3 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.7.9 ports: - containerPort: 80 Replica Set Deployment C1 C2
  • 11.
  • 12.
    Services kind: Service apiVersion: v1 metadata: name:my-service spec: selector: app: MyApp ports: - protocol: TCP port: 80 targetPort: 9376 Replica Set Deployment Service ● A service provides a layer 4 load balancer for pods: C1 C2
  • 13.
    Pod to PodCommunication Replica Set A Deployment A ServiceA C1 C2 Deployment B Replica Set B C3 C4 ServiceB
  • 14.
  • 15.
    Ingresses Replica Set Deployment Service Ingress apiVersion: extensions/v1beta1 kind:Ingress metadata: name: test-ingress annotations: nginx.ingress.kubernetes.io/rewri te-target: / spec: rules: - http: paths: - path: /testpath backend: serviceName: test servicePort: 80 ● An ingress is used for configuring a load balancer for external routing C1 C2
  • 16.
    Ingresses Replica Set Deployment Service Ingress Ingress Controller apiVersion: extensions/v1beta1 kind:Ingress metadata: name: test-ingress annotations: nginx.ingress.kubernetes.io/rewri te-target: / spec: rules: - http: paths: - path: /testpath backend: serviceName: test servicePort: 80 ● An ingress is used for configuring a load balancer for external routing C1 C2
  • 17.
    Ingresses Replica Set Deployment Service Ingress Ingress Controller LoadBalancer apiVersion: extensions/v1beta1 kind:Ingress metadata: name: test-ingress annotations: nginx.ingress.kubernetes.io/rewri te-target: / spec: rules: - http: paths: - path: /testpath backend: serviceName: test servicePort: 80 ● An ingress is used for configuring a load balancer for external routing C1 C2
  • 18.
  • 19.
    ConfigMaps Replica Set Deployment Service Ingress Ingress Controller LoadBalancer Config MapsConfigFiles ● Configuration files can be injected into pods using ConfigMaps ● A ConfigMap can be created for key/value pairs, files and folders Config MapsConfig Maps C1 C2
  • 20.
  • 21.
    Config Maps Secrets Replica Set Deployment Service Ingress Ingress Controller LoadBalancer ConfigFiles ● Sensitive data such as credentials, encryption keys can be securely injected using secrets Config MapsConfig MapsConfig MapsSecrets Config Maps Credentials C1 C2
  • 22.
  • 23.
    Config Maps Persistent Volumes ReplicaSet Deployment Config Files Config Maps Credentials C1 C2 Persistent Volume ClaimPersistent Volumes Service ● PVC defines volume size, and type: ReadOnly, ReadWrite, ReadWriteMany
  • 24.
    Persistent Volume Types ●GCEPersistentDisk ● AWSElasticBlockStore ● AzureFile ● AzureDisk ● FC (Fibre Channel)** ● FlexVolume ● Flocker ● NFS ● iSCSI ● RBD (Ceph Block Device) ● CephFS ● Cinder (OpenStack block storage) ● Glusterfs ● VsphereVolume ● Quobyte Volumes ● VMware Photon ● Portworx Volumes ● ScaleIO Volumes ● StorageOS https://kubernetes.io/docs/concepts/storage/persistent-volumes/#types-of-persistent-volumes
  • 25.
  • 26.
  • 27.
    Replica Set V1 DeploymentV1 V1 Deploying... Deployment Process
  • 28.
    Replica Set V1 DeploymentV1 P1 - V1 P2 - V1 Service C1 C2 V1 Pods Starting... Deployment Process
  • 29.
    C1 Replica Set V1 DeploymentV1 P1 - V1 P2 - V1 Service C2 V1 Pods Activating... Deployment Process
  • 30.
    C1 Replica Set V1 DeploymentV1 C2 P1 - V1 P2 - V1 Service V1 Pods Healthy Deployment Process
  • 31.
    C1 Replica Set V1 DeploymentV1 C2 P1 - V1 P2 - V1 Deployment V2 Service Deploying V2... Rolling Update Process
  • 32.
    C1 Replica Set V1 DeploymentV1 C2 P1 - V1 P2 - V1 Deployment V2 Replica Set V2 Service Deploying V2... Rolling Update Process
  • 33.
    Replica Set V1 DeploymentV1 C2 P1 - V1 P2 - V1 Deployment V2 Replica Set V2 P1 - V2Service C3 V2 Pods Starting... C4 P2 - V2 C1 Rolling Update Process
  • 34.
    C1 Replica Set V1 DeploymentV1 C2 P1 - V1 P2 - V1 Deployment V2 Replica Set V2 C3 P1 - V2Service V2 Pods Activating... P2 - V2 C4 Rolling Update Process
  • 35.
    Replica Set V1 DeploymentV1 P1 - V1 P2 - V1 Deployment V2 Replica Set V2 C3 C4 P1 - V2 P2 - V2 C1 C2 Service V2 Pods Healthy Rolling Update Process
  • 36.
  • 37.
    Horizontal Pod Autoscalers ReplicaSet Deployment Service ● Enable autoscaling for pods based on CPU utilization Horizontal Pod Autoscaler Resource Metrics API C1 C2
  • 38.
  • 39.
    Helm ● Helm isthe Kubernetes package manager. ● It uses Charts for defining, installing and upgrading applications on Kubernetes. ● Runtime configurations can be templated and parameterized. ● Existing Charts can be reused and added as dependencies to new Charts. ● Helm is managed by CNCF. https://docs.helm.sh
  • 40.
    Helm Hello World #templates/deployment.yaml apiVersion: apps/v1 kind: Deployment metadata: Name: hello-world spec: replicas: 1 template: metadata: labels: app: hello-world spec: containers: - name: hello-world image: gcr.io/google-samples/node-hello :1.0 ports: - containerPort: 8080 protocol: TCP # chart.yaml name: apps/v1 version: # templates/service.yaml kind: Service apiVersion: v1 metadata: name: hello-world spec: type: NodePort selector: app: hello-world ports: - protocol: TCP port: 8080 targetPort: 8080
  • 41.
  • 42.
  • 43.
  • 44.
    References ● Kubernetes Documentation: ○https://kubernetes.io/docs/ ● An Introduction to Kubernetes: ○ https://www.slideshare.net/imesh/an-introduction-to-kubernetes ● WSO2Con US 2015 Kubernetes: a platform for automating deployment, scaling, and operations: ○ https://www.slideshare.net/BrianGrant11/wso2con-us-2015-kube rnetes-a-platform-for-automating-deployment-scaling-and-operati ons ● Kubernetes: An Overview: ○ https://thenewstack.io/kubernetes-an-overview/
  • 45.
    References Cont. ● HelmDocumentation: ○ https://docs.helm.sh ● The missing CI/CD Kubernetes component: Helm package manager ○ https://medium.com/@gajus/the-missing-ci-cd-kubernetes-compon ent-helm-package-manager-1fe002aac680
  • 46.