SlideShare une entreprise Scribd logo
1  sur  76
Télécharger pour lire hors ligne
Mastering
Kubernetes
23th Feb 2024
Waqar Alamgir
wajrcs@gmail.com
@wajrcs_dk
@wajrcs-dk
1
Course Overview
Introduction to
Kubernetes
A
Basic Concepts
B
Advanced Concepts
Example Project
C
2
Source Code
https://github.com/wajrcs-dk/mastering-kubernetes 3
A. Introduction to Kubernetes
4
1. Microservices
5
1.1 Modern Infrastructure
VS
Monolithic
- Handle multiple related
tasks
- Compiling and testing the
entire platform
Microservices
- Smaller applications
deployed independently
- Encompass multiple
platforms
6
1.2 Monolithic
Easy deployment
One executable file or directory makes
deployment easier.
Scalability
There is no easy way to scale individual
components.
Reliability
If there’s an error in any module, it could
affect the entire application’s availability.
Development
When an application is built with one
code base, it is easier to develop.
7
1.3 Microservices
Multiple deployments
Teams need to add communication and
collaboration to coordinate deployments.
Flexible scaling
If reaches high load, new instances of
that service can rapidly be deployed.
High reliability
You can deploy changes for a specific
service, without the threat of bringing
down the entire application.
Development sprawl
It results in slower development speed
and poor operational performance.
8
2. Containers
9
2.1 Containers vs. Virtual Machines
10
2.2 VMs & Containers Together
11
Container Engine
Container Engine
Container Engine
2.3 Dockerfile vs Docker compose
12
2.4 Container on one Server
Single Node
New Container
13
2.5 Container on Multiple Servers
New Container
Multiple Nodes
???
14
2.6 Container Errors
15
3. Kubernetes
16
3.1 What is Kubernetes?
Kubernetes
It is pilot of a ship of
containers
For Applications
Focus on manage
applications, not
machines
Usage
For deployment,
scaling & management
of containers
Open Source
Open API container
orchestrator
Go
Fast robust, and written
in Google Go
Cloud
Supports multiple cloud
and bare-metal
environments
Mature
15 years of google
experience
17
3.2 K8s Key Features
Rollouts & Rollbacks
Auto Scaling
Self Healing
Load Balancing
Storage Orchestrator
Secrets Management
18
3.3 K8s High Level Architecture
API
Kubectl
Master01
Worker01
Worker02
Worker03
Worker04
Master02
19
Terminal
K8s Dashboard
3.4 Master Node in K8s
API Server
It validates and configures pods,
services, replicationcontrollers...
01
Controller Manager
A daemon that embeds the core
control loops shipped with
Kubernetes
03
Scheduler
It finds feasible Nodes for a
container
02
etcd
A distributed key-value store used
to hold and manage the critical
information
04
Master Node 20
3.5 Worker Node in K8s
Container Runtime
A software component that can
run containers on a host system
01
Kube proxy
A vital Kubernetes agent involves
in monitoring changes to network
03
Kubelet
A node-level agent that is in charge
of executing container requirement
02
Worker Node 21
3.6 Typical Production Setup
Master 01
Master 02
Worker 01
Worker 02
Worker 03
22
How to setup locally???
3.7 Minikube vs K0s vs K3s vs K8s
23
4. Installation
24
4.1 VM & Vagrant
25
1. vagrant up
2. vagrant status
3. vagrant ssh
4. vagrant halt
5. vagrant destroy
4.2 Vagrantfile & Vagrant CLI
26
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "bento/ubuntu-22.04"
config.vm.hostname = "master"
config.vm.network "private_network", ip: "192.168.33.70"
config.vm.synced_folder "./code", "/vagrant_data"
config.vm.provider "virtualbox" do |vb|
vb.gui = false
vb.memory = "8024"
vb.cpus = 4
vb.name = "master"
end
end
4.3 Installing K8s
1. Disable swap
sudo swapoff -a
2. Install docker
https://docs.docker.com/engine/install/ubuntu/
3. Install cri docker
https://github.com/Mirantis/cri-dockerd
4. Install kubernetes
https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/
5. Master node
https://v1-28.docs.kubernetes.io/docs/setup/production-environment/tools/kubeadm/create-cluster-kubeadm/
6. Install kubectl on master node
sudo snap install kubectl --classic
7. Worker node
kubeadm join
27
4.4 Installing MiniKube
1. Install docker
https://docs.docker.com/engine/install/ubuntu/
2. Install minikube
https://minikube.sigs.k8s.io/docs/start/
3. Start minikube
minikube start
4. Install kubectl
sudo snap install kubectl --classic
28
4.5 K8s Playground
https://labs.play-with-k8s.com
29
4.6 Killercoda Playground
https://killercoda.com/playgrounds/scenario/kubernetes
30
4.7 Killercoda Playground
https://killercoda.com/playgrounds/course/kubernetes-playgrounds
31
5. Let’s Install
32
Introduction to Kubernetes Recap
1. Modern Infrastructure: Monolithic vs Microservices
2. VMs vs Containers & Combination
3. Kubernetes
4. K8s High Level Architecture
5. Master Node
6. Worker Node
7. Typical Production Setup
8. Installation K8s & Minikube
33
B. Basic Concepts
34
Minikube Architecture
35
Host OS - 10.20.33.80
VM - 192.168.49.2
Container Runtime
Control Panel
Host OS Guest OS Minikube
X
Use GUI Instead
Guest OS - 192.168.33.80
6. Core Components
36
6.1 Pod
37
Pod as container
1. Smallest unit of K8s
2. Abstraction over container
3. Usually 1 application per Pod
4. Each Pod gets its own IP address
Node 1
6.2 Deployment
38
Pod as Deployment
1. Blueprint for my-app pods
2. You create Deployments
Node 1
6.3 MongoDB Deployment Example
39
apiVersion: apps/v1
kind: Deployment
metadata:
name: mongodb-deployment
labels:
app: mongodb
spec:
replicas: 1
selector:
matchLabels:
app: mongodb
template:
metadata:
labels:
app: mongodb
spec:
containers:
- name: mongodb
image: mongo
ports:
- containerPort: 27017
env:
- name: MONGO_INITDB_ROOT_USERNAME
valueFrom:
secretKeyRef:
name: mongodb-secret
key: mongo-root-username
- name: MONGO_INITDB_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mongodb-secret
key: mongo-root-password
6.4 ReplicaSet
Node 2
my-app-yyy
Node 1
my-app-xxx
6.5 MongoDB ReplicaSet Example
41
apiVersion: apps/v1
kind: Deployment
metadata:
name: mongodb-deployment
labels:
app: mongodb
spec:
replicas: 1
selector:
matchLabels:
app: mongodb
template:
metadata:
labels:
app: mongodb
spec:
...
6.6 Service
42
Pod 1
1. To group a set of Pod
endpoints into a single
resource
2. There are four types of
services that Kubernetes
supports:
a. ClusterIP
b. NodePort
c. LoadBalancer
d. Ingress
Node 1
Service
Pod 3
X
Pod 2
192.168.33.109 192.168.33.169 192.168.33.227
192.168.23.112
6.7 MongoDB Service Example
43
apiVersion: v1
kind: Service
metadata:
name: mongodb-service
spec:
selector:
app: mongodb
ports:
- protocol: TCP
port: 27017
targetPort: 27017
6.8 Layers of Abstraction
44
1. Container
2. Pod
3. ReplicaSet
4. Deployment
5. Service
6.9 ConfigMap & Secret
45
my-app
1. External configuration
of your application
Node 1
my-app-service
db
db-service
db-service
user
password
apiVersion: v1
kind: Secret
metadata:
name: mongodb-secret
type: Opaque
data:
username: dXNlcm5hbWU=
password: cGFzc3dvcmQ=
6.10 MongoDB ConfigMap & Secret Example
46
apiVersion: v1
kind: ConfigMap
metadata:
name: mongodb-configmap
data:
db_host: mongodb-service
6.11 Namespaces
47
Default Namespace
Kubernetes Cluster
Everything in one namespace
???
kubectl get pods -n kube-system
6.12 Namespace Example
48
apiVersion: v1
kind: ConfigMap
metadata:
name: mongodb-configmap
namespace: my-namespace
data:
db_host: mongodb-service
6.13 Ingress Controller
49
Is App accessible through browser ???
https://my-app.com:443
Secure Protocol Port
Domain name
50
1. Pod 2. Service 3. Ingress
4. Ingress Pod
5. Cloud Load Balancer
6.13 Ingress Controller
6.14 Ingress Controller Example
51
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: name
annotations:
kubernetes.io/ingress.class : "nginx"
spec:
rules:
- host: app.com
http:
paths:
- path: /
backend:
serviceName: my-service
servicePort: 8080
6.15 Kubectl Cheat Sheet
1. kubectl get nodes
2. kubectl top
3. kubectl apply -f ./yyy/xxx.yaml
4. kubectl apply -f ./yyy/
5. kubectl get secret
6. kubectl get configmap
7. kubectl get pod
8. kubectl get pod --watch
9. kubectl get deployment
10. kubectl create deployment nginx-depl --image=nginx
11. kubectl edit deployment nginx-depl
12. kubectl delete deployment nginx-depl
13. kubectl get replicaset
14. kubectl logs {pod-name}
15. kubectl describe pod nginx-depl-{pod-name}
16. kubectl exec -it {pod-name} -- bin/bash
17. kubectl get services
18. kubectl describe service nginx-service 52
7. Demo using Minikube
53
Basic Concepts Recap
1. Kubernetes
2. K8s High Level Architecture
3. Installation K8s & Minikube
4. Pod
5. Deployment
6. Service
7. ConfigMap & Secret
8. Namespaces
9. Ingress
10. Kubectl
11. Demo using Minikube
54
C. Advanced Concepts with
Example Project
55
8. Deep Dive
56
8.1 Possible Errors on Kubernetes
1. Insufficient Resource Allocation:
Error: Due to insufficient resource allocation, pods frequently crash or fail to start.
2. Problems with Network Configuration:
Error: Pods are unable to connect to external services or each other.
3. Image Pull Errors:
Error: Attempts by pods to retrieve container images from the registry are unsuccessful.
4. Incompatible Container Images:
Error: This error message indicates that incompatible container images are causing pods to fail or encounter runtime issues.
5. Incorrect Configuration:
Error: The fifth error is incorrect configuration, which results in unexpected behavior or failures.
6. Persistent Volume Problems:
Error: Issues pertaining to the storage of persistent volume claims (PVCs).
7. Errors in Pod Scheduling:
Error: Pods are not scheduled or are trapped in the pending stage.
8. Insufficient Health Checks:
Error: Neglecting to identify and manage unwell pods.
9. Inconsistent Deployments:
Error: Disparities exist between the intended and real deployment states.
10. Insufficient Logging and Monitoring:
Error: Difficulty in recognizing and diagnosing deployment difficulties due to inadequate logging and monitoring. 57
58
application pod
8.2 Volumes
database pod storage
8.3 Persistent Local Volumes
59
Kubernetes Cluster
Local Disks
1. hostPath
a. Local Disk
b. NFS Server
1. awsElasticBlockStore
2. azureDisk
3. cephfs
4. cinder
5. fibre channel
6. gcePersistentDisk
7. glusterfs
8. hostPath
8.4 Persistent Cloud Volumes
60
Kubernetes Cluster
Cloud Storage
8.5 Persistent Volumes
61
Storage Class
Persistent Volume
Persistent Volume Claim
App
8.6 Persistent Volume Example
62
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-name
spec:
capacity:
storage: 5Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy : Recycle
storageClassName : slow
mountOptions:
- hard
- nfsvers=4.0
nfs:
path: /dir/path/on/nfs/server
server: nfs-server-ip-address
63
application pod
8.7 Stateful vs Stateless Applications
database pod
persistence
storage
container volume container volume
X
64
my-app-caz6x
8.8 Deployment vs StatefulSet
my-app-x8syy my-app-cf3xz
my-app-service
mysql-0 mysql-1 mysql-2
mysql-service mysql-read-service
read+write read read
8.9 Limit Resources Example
65
...
containers:
- name: application-cpu
image: wajrcs/application-cpu:v1.0.2
imagePullPolicy: Always
ports:
- containerPort: 80
resources:
requests:
memory: "50Mi"
cpu: "500m"
limits:
memory: "500Mi"
cpu: "2000m"
8.10 Resource Utilization
66
mysql-0
Number of Replicas = Server number of cores / Pod number of cores
Example
Number of Replicas = 2 * 1000 / 500 = 4
mysql-1 mysql-2 mysql-3
memory: "50Mi"
cpu: "500m"
8.11 Horizontal Pod AutoScaling (HPA)
67
mysql-0 mysql-1 mysql-2 mysql-3
memory: "50Mi"
cpu: "500m"
# Deploy an autoscaler
# Scale the deployment to 2
kubectl scale deploy/application-cpu --replicas2
# Deploy the autoscaler
kubectl autoscale deploy/application-cpu --cpu-percent=
95 --min=1 --max=10
# Get details about hpa
kubectl describe hpa/application-cpu
8.12 Helm
1. Package manager for Kubernetes
2. The archive of yamls
3. Contains Charts.
4. Example Elastic stack for logging
5. helm search <keyword>
helm repo add <project name> <project url>
helm repo update
helm install <project name>
68
8.13 More Tools to Explore
69
8.14 Monitoring
70
1. Octant by VMWare
2. Kubernetes Dashboard
8.15 Monitoring using Prometheus
71
Prometheus is a free software application used for event monitoring and alerting.
Three components:
1. Time series database for metrics data
2. Data retrieval worker
3. HTTP Server for Web UI, Grafana etc
Matrics Pull mechanism / scraping endpoint
Programming language: Go
Developer: SoundCloud, Cloud Native Computing Foundation
Prometheus operator available using Helm chart
Used by many companies including:
DigitalOcean, Ericsson, CoreOS, Weaveworks, Red Hat, and Google.
8.15 Prometheus Installation
72
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
helm install prometheus prometheus-community/kube-prometheus-stack
kubectl port-forward deployment/prometheus-grafana3000
Visit: http://localhost:3000
9. Example Project
73
9. Example Laravel Project Architecture
74
75
Congratulation!
Thank you for joining
76
Mastering Kubernetes
https://github.com/wajrcs-dk/mastering-kubernetes/blob/main/6-books/Mastering-Kubernetes.pdf
https://www.kgay4all.com/index.php?p=Books%2FKUBERNETES
Kubernetes Tutorial for Beginners
https://www.youtube.com/watch?v=X48VuDVv0do
Introduction to kubernetes with demo
https://www.slideshare.net/opsta/introduction-to-kubernetes-with-demo-236989184
k3s vs k8s: What's the difference?
https://www.youtube.com/watch?v=FmLna7tHDRc
Setup Prometheus Monitoring on Kubernetes using Helm and Prometheus Operator
https://www.youtube.com/watch?v=QoDqxm7ybLc
Persistent Volumes on Kubernetes for beginners
https://www.youtube.com/watch?v=ZxC6FwEc9WQ
Kubernetes cluster autoscaling for beginners
https://www.youtube.com/watch?v=jM36M39MA3I
Kubernetes Projects
https://ramitsurana.github.io/awesome-kubernetes/projects/projects/
10 Possible Errors on Kubernetes Deployments and Troubleshooting Steps
https://www.linkedin.com/pulse/10-possible-errors-kubernetes-deployments-steps-naveed-abdul-sattar/
How would you handle errors in a container?
https://www.reddit.com/r/docker/comments/109i28v/how_would_you_handle_errors_in_a_container/
13 Kubernetes Tools You Should Know in 2024
https://overcast.blog/13-kubernetes-tools-your-should-know-in-2024-4e857124c176
10. Reference
Waqar Alamgir
wajrcs@gmail.com
@wajrcs_dk
@wajrcs-dk

Contenu connexe

Similaire à Mastering Kubernetes - Basics and Advanced Concepts using Example Project

How to Install and Use Kubernetes by Weaveworks
How to Install and Use Kubernetes by Weaveworks How to Install and Use Kubernetes by Weaveworks
How to Install and Use Kubernetes by Weaveworks Weaveworks
 
How to install and use Kubernetes
How to install and use KubernetesHow to install and use Kubernetes
How to install and use KubernetesLuke Marsden
 
Dev opsec dockerimage_patch_n_lifecyclemanagement_
Dev opsec dockerimage_patch_n_lifecyclemanagement_Dev opsec dockerimage_patch_n_lifecyclemanagement_
Dev opsec dockerimage_patch_n_lifecyclemanagement_kanedafromparis
 
IBM MQ in containers MQTC 2017
IBM MQ in containers MQTC 2017IBM MQ in containers MQTC 2017
IBM MQ in containers MQTC 2017Robert Parker
 
Develop and deploy Kubernetes applications with Docker - IBM Index 2018
Develop and deploy Kubernetes  applications with Docker - IBM Index 2018Develop and deploy Kubernetes  applications with Docker - IBM Index 2018
Develop and deploy Kubernetes applications with Docker - IBM Index 2018Patrick Chanezon
 
GCP - Continuous Integration and Delivery into Kubernetes with GitHub, Travis...
GCP - Continuous Integration and Delivery into Kubernetes with GitHub, Travis...GCP - Continuous Integration and Delivery into Kubernetes with GitHub, Travis...
GCP - Continuous Integration and Delivery into Kubernetes with GitHub, Travis...Oleg Shalygin
 
Lessons learned and challenges faced while running Kubernetes at Scale
Lessons learned and challenges faced while running Kubernetes at ScaleLessons learned and challenges faced while running Kubernetes at Scale
Lessons learned and challenges faced while running Kubernetes at ScaleSidhartha Mani
 
Exploring MySQL Operator for Kubernetes in Python
Exploring MySQL Operator for Kubernetes in PythonExploring MySQL Operator for Kubernetes in Python
Exploring MySQL Operator for Kubernetes in PythonIvan Ma
 
Orchestrating Microservices with Kubernetes
Orchestrating Microservices with Kubernetes Orchestrating Microservices with Kubernetes
Orchestrating Microservices with Kubernetes Weaveworks
 
Learn kubernetes in 90 minutes
Learn kubernetes in 90 minutesLearn kubernetes in 90 minutes
Learn kubernetes in 90 minutesLarry Cai
 
MongoDB Ops Manager + Kubernetes
MongoDB Ops Manager + KubernetesMongoDB Ops Manager + Kubernetes
MongoDB Ops Manager + KubernetesMongoDB
 
OSS Japan 2019 service mesh bridging Kubernetes and legacy
OSS Japan 2019 service mesh bridging Kubernetes and legacyOSS Japan 2019 service mesh bridging Kubernetes and legacy
OSS Japan 2019 service mesh bridging Kubernetes and legacySteve Wong
 
Cloud-native .NET Microservices mit Kubernetes
Cloud-native .NET Microservices mit KubernetesCloud-native .NET Microservices mit Kubernetes
Cloud-native .NET Microservices mit KubernetesQAware GmbH
 
Ultimate Guide to Microservice Architecture on Kubernetes
Ultimate Guide to Microservice Architecture on KubernetesUltimate Guide to Microservice Architecture on Kubernetes
Ultimate Guide to Microservice Architecture on Kuberneteskloia
 
Virtual Flink Forward 2020: Integrate Flink with Kubernetes natively - Yang Wang
Virtual Flink Forward 2020: Integrate Flink with Kubernetes natively - Yang WangVirtual Flink Forward 2020: Integrate Flink with Kubernetes natively - Yang Wang
Virtual Flink Forward 2020: Integrate Flink with Kubernetes natively - Yang WangFlink Forward
 
Hands-On Introduction to Kubernetes at LISA17
Hands-On Introduction to Kubernetes at LISA17Hands-On Introduction to Kubernetes at LISA17
Hands-On Introduction to Kubernetes at LISA17Ryan Jarvinen
 
Setting up a kubernetes cluster on ubuntu 18.04- loves cloud
Setting up a kubernetes cluster on ubuntu 18.04- loves cloudSetting up a kubernetes cluster on ubuntu 18.04- loves cloud
Setting up a kubernetes cluster on ubuntu 18.04- loves cloudLoves Cloud
 
K8sfor dev parisoss-summit-microsoft-5-decembre-short
K8sfor dev parisoss-summit-microsoft-5-decembre-shortK8sfor dev parisoss-summit-microsoft-5-decembre-short
K8sfor dev parisoss-summit-microsoft-5-decembre-shortGabriel Bechara
 
[Global logic] container runtimes and kubernetes
[Global logic] container runtimes and kubernetes[Global logic] container runtimes and kubernetes
[Global logic] container runtimes and kubernetesGlobalLogic Ukraine
 

Similaire à Mastering Kubernetes - Basics and Advanced Concepts using Example Project (20)

How to Install and Use Kubernetes by Weaveworks
How to Install and Use Kubernetes by Weaveworks How to Install and Use Kubernetes by Weaveworks
How to Install and Use Kubernetes by Weaveworks
 
How to install and use Kubernetes
How to install and use KubernetesHow to install and use Kubernetes
How to install and use Kubernetes
 
Dev opsec dockerimage_patch_n_lifecyclemanagement_
Dev opsec dockerimage_patch_n_lifecyclemanagement_Dev opsec dockerimage_patch_n_lifecyclemanagement_
Dev opsec dockerimage_patch_n_lifecyclemanagement_
 
IBM MQ in containers MQTC 2017
IBM MQ in containers MQTC 2017IBM MQ in containers MQTC 2017
IBM MQ in containers MQTC 2017
 
Microservices in Java
Microservices in JavaMicroservices in Java
Microservices in Java
 
Develop and deploy Kubernetes applications with Docker - IBM Index 2018
Develop and deploy Kubernetes  applications with Docker - IBM Index 2018Develop and deploy Kubernetes  applications with Docker - IBM Index 2018
Develop and deploy Kubernetes applications with Docker - IBM Index 2018
 
GCP - Continuous Integration and Delivery into Kubernetes with GitHub, Travis...
GCP - Continuous Integration and Delivery into Kubernetes with GitHub, Travis...GCP - Continuous Integration and Delivery into Kubernetes with GitHub, Travis...
GCP - Continuous Integration and Delivery into Kubernetes with GitHub, Travis...
 
Lessons learned and challenges faced while running Kubernetes at Scale
Lessons learned and challenges faced while running Kubernetes at ScaleLessons learned and challenges faced while running Kubernetes at Scale
Lessons learned and challenges faced while running Kubernetes at Scale
 
Exploring MySQL Operator for Kubernetes in Python
Exploring MySQL Operator for Kubernetes in PythonExploring MySQL Operator for Kubernetes in Python
Exploring MySQL Operator for Kubernetes in Python
 
Orchestrating Microservices with Kubernetes
Orchestrating Microservices with Kubernetes Orchestrating Microservices with Kubernetes
Orchestrating Microservices with Kubernetes
 
Learn kubernetes in 90 minutes
Learn kubernetes in 90 minutesLearn kubernetes in 90 minutes
Learn kubernetes in 90 minutes
 
MongoDB Ops Manager + Kubernetes
MongoDB Ops Manager + KubernetesMongoDB Ops Manager + Kubernetes
MongoDB Ops Manager + Kubernetes
 
OSS Japan 2019 service mesh bridging Kubernetes and legacy
OSS Japan 2019 service mesh bridging Kubernetes and legacyOSS Japan 2019 service mesh bridging Kubernetes and legacy
OSS Japan 2019 service mesh bridging Kubernetes and legacy
 
Cloud-native .NET Microservices mit Kubernetes
Cloud-native .NET Microservices mit KubernetesCloud-native .NET Microservices mit Kubernetes
Cloud-native .NET Microservices mit Kubernetes
 
Ultimate Guide to Microservice Architecture on Kubernetes
Ultimate Guide to Microservice Architecture on KubernetesUltimate Guide to Microservice Architecture on Kubernetes
Ultimate Guide to Microservice Architecture on Kubernetes
 
Virtual Flink Forward 2020: Integrate Flink with Kubernetes natively - Yang Wang
Virtual Flink Forward 2020: Integrate Flink with Kubernetes natively - Yang WangVirtual Flink Forward 2020: Integrate Flink with Kubernetes natively - Yang Wang
Virtual Flink Forward 2020: Integrate Flink with Kubernetes natively - Yang Wang
 
Hands-On Introduction to Kubernetes at LISA17
Hands-On Introduction to Kubernetes at LISA17Hands-On Introduction to Kubernetes at LISA17
Hands-On Introduction to Kubernetes at LISA17
 
Setting up a kubernetes cluster on ubuntu 18.04- loves cloud
Setting up a kubernetes cluster on ubuntu 18.04- loves cloudSetting up a kubernetes cluster on ubuntu 18.04- loves cloud
Setting up a kubernetes cluster on ubuntu 18.04- loves cloud
 
K8sfor dev parisoss-summit-microsoft-5-decembre-short
K8sfor dev parisoss-summit-microsoft-5-decembre-shortK8sfor dev parisoss-summit-microsoft-5-decembre-short
K8sfor dev parisoss-summit-microsoft-5-decembre-short
 
[Global logic] container runtimes and kubernetes
[Global logic] container runtimes and kubernetes[Global logic] container runtimes and kubernetes
[Global logic] container runtimes and kubernetes
 

Plus de wajrcs

RDF Join Query Processing with Dual Simulation Pruning
RDF Join Query Processing with Dual Simulation PruningRDF Join Query Processing with Dual Simulation Pruning
RDF Join Query Processing with Dual Simulation Pruningwajrcs
 
A Fairness-aware Machine Learning Interface for End-to-end Discrimination Dis...
A Fairness-aware Machine Learning Interface for End-to-end Discrimination Dis...A Fairness-aware Machine Learning Interface for End-to-end Discrimination Dis...
A Fairness-aware Machine Learning Interface for End-to-end Discrimination Dis...wajrcs
 
Continuous Delivery - Automate & Build Better Software with Travis CI
Continuous Delivery - Automate & Build Better Software with Travis CIContinuous Delivery - Automate & Build Better Software with Travis CI
Continuous Delivery - Automate & Build Better Software with Travis CIwajrcs
 
Infrastructure Automation with Chef & Ansible
Infrastructure Automation with Chef & AnsibleInfrastructure Automation with Chef & Ansible
Infrastructure Automation with Chef & Ansiblewajrcs
 
Hacking hhvm
Hacking hhvmHacking hhvm
Hacking hhvmwajrcs
 
Domain Driven Design using Laravel
Domain Driven Design using LaravelDomain Driven Design using Laravel
Domain Driven Design using Laravelwajrcs
 

Plus de wajrcs (6)

RDF Join Query Processing with Dual Simulation Pruning
RDF Join Query Processing with Dual Simulation PruningRDF Join Query Processing with Dual Simulation Pruning
RDF Join Query Processing with Dual Simulation Pruning
 
A Fairness-aware Machine Learning Interface for End-to-end Discrimination Dis...
A Fairness-aware Machine Learning Interface for End-to-end Discrimination Dis...A Fairness-aware Machine Learning Interface for End-to-end Discrimination Dis...
A Fairness-aware Machine Learning Interface for End-to-end Discrimination Dis...
 
Continuous Delivery - Automate & Build Better Software with Travis CI
Continuous Delivery - Automate & Build Better Software with Travis CIContinuous Delivery - Automate & Build Better Software with Travis CI
Continuous Delivery - Automate & Build Better Software with Travis CI
 
Infrastructure Automation with Chef & Ansible
Infrastructure Automation with Chef & AnsibleInfrastructure Automation with Chef & Ansible
Infrastructure Automation with Chef & Ansible
 
Hacking hhvm
Hacking hhvmHacking hhvm
Hacking hhvm
 
Domain Driven Design using Laravel
Domain Driven Design using LaravelDomain Driven Design using Laravel
Domain Driven Design using Laravel
 

Dernier

MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noidabntitsolutionsrishis
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 

Dernier (20)

MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 

Mastering Kubernetes - Basics and Advanced Concepts using Example Project

  • 1. Mastering Kubernetes 23th Feb 2024 Waqar Alamgir wajrcs@gmail.com @wajrcs_dk @wajrcs-dk 1
  • 2. Course Overview Introduction to Kubernetes A Basic Concepts B Advanced Concepts Example Project C 2
  • 4. A. Introduction to Kubernetes 4
  • 6. 1.1 Modern Infrastructure VS Monolithic - Handle multiple related tasks - Compiling and testing the entire platform Microservices - Smaller applications deployed independently - Encompass multiple platforms 6
  • 7. 1.2 Monolithic Easy deployment One executable file or directory makes deployment easier. Scalability There is no easy way to scale individual components. Reliability If there’s an error in any module, it could affect the entire application’s availability. Development When an application is built with one code base, it is easier to develop. 7
  • 8. 1.3 Microservices Multiple deployments Teams need to add communication and collaboration to coordinate deployments. Flexible scaling If reaches high load, new instances of that service can rapidly be deployed. High reliability You can deploy changes for a specific service, without the threat of bringing down the entire application. Development sprawl It results in slower development speed and poor operational performance. 8
  • 10. 2.1 Containers vs. Virtual Machines 10
  • 11. 2.2 VMs & Containers Together 11 Container Engine Container Engine Container Engine
  • 12. 2.3 Dockerfile vs Docker compose 12
  • 13. 2.4 Container on one Server Single Node New Container 13
  • 14. 2.5 Container on Multiple Servers New Container Multiple Nodes ??? 14
  • 17. 3.1 What is Kubernetes? Kubernetes It is pilot of a ship of containers For Applications Focus on manage applications, not machines Usage For deployment, scaling & management of containers Open Source Open API container orchestrator Go Fast robust, and written in Google Go Cloud Supports multiple cloud and bare-metal environments Mature 15 years of google experience 17
  • 18. 3.2 K8s Key Features Rollouts & Rollbacks Auto Scaling Self Healing Load Balancing Storage Orchestrator Secrets Management 18
  • 19. 3.3 K8s High Level Architecture API Kubectl Master01 Worker01 Worker02 Worker03 Worker04 Master02 19 Terminal K8s Dashboard
  • 20. 3.4 Master Node in K8s API Server It validates and configures pods, services, replicationcontrollers... 01 Controller Manager A daemon that embeds the core control loops shipped with Kubernetes 03 Scheduler It finds feasible Nodes for a container 02 etcd A distributed key-value store used to hold and manage the critical information 04 Master Node 20
  • 21. 3.5 Worker Node in K8s Container Runtime A software component that can run containers on a host system 01 Kube proxy A vital Kubernetes agent involves in monitoring changes to network 03 Kubelet A node-level agent that is in charge of executing container requirement 02 Worker Node 21
  • 22. 3.6 Typical Production Setup Master 01 Master 02 Worker 01 Worker 02 Worker 03 22 How to setup locally???
  • 23. 3.7 Minikube vs K0s vs K3s vs K8s 23
  • 25. 4.1 VM & Vagrant 25
  • 26. 1. vagrant up 2. vagrant status 3. vagrant ssh 4. vagrant halt 5. vagrant destroy 4.2 Vagrantfile & Vagrant CLI 26 # -*- mode: ruby -*- # vi: set ft=ruby : Vagrant.configure("2") do |config| config.vm.box = "bento/ubuntu-22.04" config.vm.hostname = "master" config.vm.network "private_network", ip: "192.168.33.70" config.vm.synced_folder "./code", "/vagrant_data" config.vm.provider "virtualbox" do |vb| vb.gui = false vb.memory = "8024" vb.cpus = 4 vb.name = "master" end end
  • 27. 4.3 Installing K8s 1. Disable swap sudo swapoff -a 2. Install docker https://docs.docker.com/engine/install/ubuntu/ 3. Install cri docker https://github.com/Mirantis/cri-dockerd 4. Install kubernetes https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/ 5. Master node https://v1-28.docs.kubernetes.io/docs/setup/production-environment/tools/kubeadm/create-cluster-kubeadm/ 6. Install kubectl on master node sudo snap install kubectl --classic 7. Worker node kubeadm join 27
  • 28. 4.4 Installing MiniKube 1. Install docker https://docs.docker.com/engine/install/ubuntu/ 2. Install minikube https://minikube.sigs.k8s.io/docs/start/ 3. Start minikube minikube start 4. Install kubectl sudo snap install kubectl --classic 28
  • 33. Introduction to Kubernetes Recap 1. Modern Infrastructure: Monolithic vs Microservices 2. VMs vs Containers & Combination 3. Kubernetes 4. K8s High Level Architecture 5. Master Node 6. Worker Node 7. Typical Production Setup 8. Installation K8s & Minikube 33
  • 35. Minikube Architecture 35 Host OS - 10.20.33.80 VM - 192.168.49.2 Container Runtime Control Panel Host OS Guest OS Minikube X Use GUI Instead Guest OS - 192.168.33.80
  • 37. 6.1 Pod 37 Pod as container 1. Smallest unit of K8s 2. Abstraction over container 3. Usually 1 application per Pod 4. Each Pod gets its own IP address Node 1
  • 38. 6.2 Deployment 38 Pod as Deployment 1. Blueprint for my-app pods 2. You create Deployments Node 1
  • 39. 6.3 MongoDB Deployment Example 39 apiVersion: apps/v1 kind: Deployment metadata: name: mongodb-deployment labels: app: mongodb spec: replicas: 1 selector: matchLabels: app: mongodb template: metadata: labels: app: mongodb spec: containers: - name: mongodb image: mongo ports: - containerPort: 27017 env: - name: MONGO_INITDB_ROOT_USERNAME valueFrom: secretKeyRef: name: mongodb-secret key: mongo-root-username - name: MONGO_INITDB_ROOT_PASSWORD valueFrom: secretKeyRef: name: mongodb-secret key: mongo-root-password
  • 41. 6.5 MongoDB ReplicaSet Example 41 apiVersion: apps/v1 kind: Deployment metadata: name: mongodb-deployment labels: app: mongodb spec: replicas: 1 selector: matchLabels: app: mongodb template: metadata: labels: app: mongodb spec: ...
  • 42. 6.6 Service 42 Pod 1 1. To group a set of Pod endpoints into a single resource 2. There are four types of services that Kubernetes supports: a. ClusterIP b. NodePort c. LoadBalancer d. Ingress Node 1 Service Pod 3 X Pod 2 192.168.33.109 192.168.33.169 192.168.33.227 192.168.23.112
  • 43. 6.7 MongoDB Service Example 43 apiVersion: v1 kind: Service metadata: name: mongodb-service spec: selector: app: mongodb ports: - protocol: TCP port: 27017 targetPort: 27017
  • 44. 6.8 Layers of Abstraction 44 1. Container 2. Pod 3. ReplicaSet 4. Deployment 5. Service
  • 45. 6.9 ConfigMap & Secret 45 my-app 1. External configuration of your application Node 1 my-app-service db db-service db-service user password
  • 46. apiVersion: v1 kind: Secret metadata: name: mongodb-secret type: Opaque data: username: dXNlcm5hbWU= password: cGFzc3dvcmQ= 6.10 MongoDB ConfigMap & Secret Example 46 apiVersion: v1 kind: ConfigMap metadata: name: mongodb-configmap data: db_host: mongodb-service
  • 47. 6.11 Namespaces 47 Default Namespace Kubernetes Cluster Everything in one namespace ???
  • 48. kubectl get pods -n kube-system 6.12 Namespace Example 48 apiVersion: v1 kind: ConfigMap metadata: name: mongodb-configmap namespace: my-namespace data: db_host: mongodb-service
  • 49. 6.13 Ingress Controller 49 Is App accessible through browser ??? https://my-app.com:443 Secure Protocol Port Domain name
  • 50. 50 1. Pod 2. Service 3. Ingress 4. Ingress Pod 5. Cloud Load Balancer 6.13 Ingress Controller
  • 51. 6.14 Ingress Controller Example 51 apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: name annotations: kubernetes.io/ingress.class : "nginx" spec: rules: - host: app.com http: paths: - path: / backend: serviceName: my-service servicePort: 8080
  • 52. 6.15 Kubectl Cheat Sheet 1. kubectl get nodes 2. kubectl top 3. kubectl apply -f ./yyy/xxx.yaml 4. kubectl apply -f ./yyy/ 5. kubectl get secret 6. kubectl get configmap 7. kubectl get pod 8. kubectl get pod --watch 9. kubectl get deployment 10. kubectl create deployment nginx-depl --image=nginx 11. kubectl edit deployment nginx-depl 12. kubectl delete deployment nginx-depl 13. kubectl get replicaset 14. kubectl logs {pod-name} 15. kubectl describe pod nginx-depl-{pod-name} 16. kubectl exec -it {pod-name} -- bin/bash 17. kubectl get services 18. kubectl describe service nginx-service 52
  • 53. 7. Demo using Minikube 53
  • 54. Basic Concepts Recap 1. Kubernetes 2. K8s High Level Architecture 3. Installation K8s & Minikube 4. Pod 5. Deployment 6. Service 7. ConfigMap & Secret 8. Namespaces 9. Ingress 10. Kubectl 11. Demo using Minikube 54
  • 55. C. Advanced Concepts with Example Project 55
  • 57. 8.1 Possible Errors on Kubernetes 1. Insufficient Resource Allocation: Error: Due to insufficient resource allocation, pods frequently crash or fail to start. 2. Problems with Network Configuration: Error: Pods are unable to connect to external services or each other. 3. Image Pull Errors: Error: Attempts by pods to retrieve container images from the registry are unsuccessful. 4. Incompatible Container Images: Error: This error message indicates that incompatible container images are causing pods to fail or encounter runtime issues. 5. Incorrect Configuration: Error: The fifth error is incorrect configuration, which results in unexpected behavior or failures. 6. Persistent Volume Problems: Error: Issues pertaining to the storage of persistent volume claims (PVCs). 7. Errors in Pod Scheduling: Error: Pods are not scheduled or are trapped in the pending stage. 8. Insufficient Health Checks: Error: Neglecting to identify and manage unwell pods. 9. Inconsistent Deployments: Error: Disparities exist between the intended and real deployment states. 10. Insufficient Logging and Monitoring: Error: Difficulty in recognizing and diagnosing deployment difficulties due to inadequate logging and monitoring. 57
  • 59. 8.3 Persistent Local Volumes 59 Kubernetes Cluster Local Disks 1. hostPath a. Local Disk b. NFS Server
  • 60. 1. awsElasticBlockStore 2. azureDisk 3. cephfs 4. cinder 5. fibre channel 6. gcePersistentDisk 7. glusterfs 8. hostPath 8.4 Persistent Cloud Volumes 60 Kubernetes Cluster Cloud Storage
  • 61. 8.5 Persistent Volumes 61 Storage Class Persistent Volume Persistent Volume Claim App
  • 62. 8.6 Persistent Volume Example 62 apiVersion: v1 kind: PersistentVolume metadata: name: pv-name spec: capacity: storage: 5Gi volumeMode: Filesystem accessModes: - ReadWriteOnce persistentVolumeReclaimPolicy : Recycle storageClassName : slow mountOptions: - hard - nfsvers=4.0 nfs: path: /dir/path/on/nfs/server server: nfs-server-ip-address
  • 63. 63 application pod 8.7 Stateful vs Stateless Applications database pod persistence storage container volume container volume X
  • 64. 64 my-app-caz6x 8.8 Deployment vs StatefulSet my-app-x8syy my-app-cf3xz my-app-service mysql-0 mysql-1 mysql-2 mysql-service mysql-read-service read+write read read
  • 65. 8.9 Limit Resources Example 65 ... containers: - name: application-cpu image: wajrcs/application-cpu:v1.0.2 imagePullPolicy: Always ports: - containerPort: 80 resources: requests: memory: "50Mi" cpu: "500m" limits: memory: "500Mi" cpu: "2000m"
  • 66. 8.10 Resource Utilization 66 mysql-0 Number of Replicas = Server number of cores / Pod number of cores Example Number of Replicas = 2 * 1000 / 500 = 4 mysql-1 mysql-2 mysql-3 memory: "50Mi" cpu: "500m"
  • 67. 8.11 Horizontal Pod AutoScaling (HPA) 67 mysql-0 mysql-1 mysql-2 mysql-3 memory: "50Mi" cpu: "500m" # Deploy an autoscaler # Scale the deployment to 2 kubectl scale deploy/application-cpu --replicas2 # Deploy the autoscaler kubectl autoscale deploy/application-cpu --cpu-percent= 95 --min=1 --max=10 # Get details about hpa kubectl describe hpa/application-cpu
  • 68. 8.12 Helm 1. Package manager for Kubernetes 2. The archive of yamls 3. Contains Charts. 4. Example Elastic stack for logging 5. helm search <keyword> helm repo add <project name> <project url> helm repo update helm install <project name> 68
  • 69. 8.13 More Tools to Explore 69
  • 70. 8.14 Monitoring 70 1. Octant by VMWare 2. Kubernetes Dashboard
  • 71. 8.15 Monitoring using Prometheus 71 Prometheus is a free software application used for event monitoring and alerting. Three components: 1. Time series database for metrics data 2. Data retrieval worker 3. HTTP Server for Web UI, Grafana etc Matrics Pull mechanism / scraping endpoint Programming language: Go Developer: SoundCloud, Cloud Native Computing Foundation Prometheus operator available using Helm chart Used by many companies including: DigitalOcean, Ericsson, CoreOS, Weaveworks, Red Hat, and Google.
  • 72. 8.15 Prometheus Installation 72 helm repo add prometheus-community https://prometheus-community.github.io/helm-charts helm repo update helm install prometheus prometheus-community/kube-prometheus-stack kubectl port-forward deployment/prometheus-grafana3000 Visit: http://localhost:3000
  • 74. 9. Example Laravel Project Architecture 74
  • 76. 76 Mastering Kubernetes https://github.com/wajrcs-dk/mastering-kubernetes/blob/main/6-books/Mastering-Kubernetes.pdf https://www.kgay4all.com/index.php?p=Books%2FKUBERNETES Kubernetes Tutorial for Beginners https://www.youtube.com/watch?v=X48VuDVv0do Introduction to kubernetes with demo https://www.slideshare.net/opsta/introduction-to-kubernetes-with-demo-236989184 k3s vs k8s: What's the difference? https://www.youtube.com/watch?v=FmLna7tHDRc Setup Prometheus Monitoring on Kubernetes using Helm and Prometheus Operator https://www.youtube.com/watch?v=QoDqxm7ybLc Persistent Volumes on Kubernetes for beginners https://www.youtube.com/watch?v=ZxC6FwEc9WQ Kubernetes cluster autoscaling for beginners https://www.youtube.com/watch?v=jM36M39MA3I Kubernetes Projects https://ramitsurana.github.io/awesome-kubernetes/projects/projects/ 10 Possible Errors on Kubernetes Deployments and Troubleshooting Steps https://www.linkedin.com/pulse/10-possible-errors-kubernetes-deployments-steps-naveed-abdul-sattar/ How would you handle errors in a container? https://www.reddit.com/r/docker/comments/109i28v/how_would_you_handle_errors_in_a_container/ 13 Kubernetes Tools You Should Know in 2024 https://overcast.blog/13-kubernetes-tools-your-should-know-in-2024-4e857124c176 10. Reference Waqar Alamgir wajrcs@gmail.com @wajrcs_dk @wajrcs-dk