Deployment is a way of defining a desired state to kubernetes so we are saying we need 3 pieces of images at all times. So, here we will deploy a small app called my-dep using Nginx.
https://kubernetes.io/docs/concepts/workloads/controllers/deployment/
The Hierarchy
Deployment (my-dep)
└── ReplicaSet (my-dep-b458fdbb4)
└── Pods (my-dep-b458fdbb4-kt85r, 5lkrc, 2bl5x...)Check man pages
Check the syntax to create a deployment file
k create deployment --helpCreate the Deployment Manifest with –dry-run
Create a deployment with the specified name.
kubectl create deployment my-dep --image=nginx --replicas=10 --dry-run=client -o yaml > nginx3.yam)apiVersion: apps/v1 kind: Deployment metadata: generation: 1 labels: app: my-dep name: my-dep namespace: default spec: progressDeadlineSeconds: 600 replicas: 5 revisionHistoryLimit: 10 selector: matchLabels: app: my-dep template: metadata: labels: app: my-dep spec: containers: - image: nginx imagePullPolicy: Always name: nginx
Apply the Deployment Manifest
To apply the manifest to cluster we run
kubectl apply -f nginx3.yamlGet Deployments
k get deployments.appsNAME READY UP-TO-DATE AVAILABLE AGE
my-dep 5/5 5 5 15mDescribe Deployment
k describe deployments.apps my-depName: my-dep
Namespace: default
Replicas: 5 desired | 5 updated | 5 total | 5 available | 0 unavailable
StrategyType: RollingUpdate
RollingUpdateStrategy: 25% max unavailable, 25% max surge
Containers:
nginx:
Image: nginx
Events:
Normal ScalingReplicaSet deployment-controller Scaled up replica set my-dep-b458fdbb4 from 0 to 10
Normal ScalingReplicaSet deployment-controller Scaled down replica set my-dep-b458fdbb4 from 10 to 5Get ReplicaSets
k get replicasets.appsNAME DESIRED CURRENT READY AGE
my-dep-b458fdbb4 5 5 5 14mDescribe ReplicaSet
Replica sets are managed by k8s, its purpose is to maintain a stable set of replica Pods running at any given time
k describe replicasets.apps my-dep-b458fdbb4Name: my-dep-b458fdbb4
Controlled By: Deployment/my-dep
Replicas: 5 current / 5 desired
Pods Status: 5 Running / 0 Waiting / 0 Succeeded / 0 Failed
Events:
Normal SuccessfulCreate replicaset-controller Created pod: my-dep-b458fdbb4-kt85r
Normal SuccessfulCreate replicaset-controller Created pod: my-dep-b458fdbb4-5lkrc
Normal SuccessfulCreate replicaset-controller Created pod: my-dep-b458fdbb4-2bl5x
Normal SuccessfulCreate replicaset-controller Created pod: my-dep-b458fdbb4-lx8j4
Normal SuccessfulCreate replicaset-controller Created pod: my-dep-b458fdbb4-pcjfw
Normal SuccessfulDelete replicaset-controller Deleted pod: my-dep-b458fdbb4-58fj5
Normal SuccessfulDelete replicaset-controller Deleted pod: my-dep-b458fdbb4-x6ggtGet Pods
kubectl get podsNAME READY STATUS RESTARTS AGE
my-dep-b458fdbb4-2bl5x 1/1 Running 0 32m
my-dep-b458fdbb4-5lkrc 1/1 Running 0 32m
my-dep-b458fdbb4-kt85r 1/1 Running 0 32m
my-dep-b458fdbb4-lx8j4 1/1 Running 0 32m
my-dep-b458fdbb4-pcjfw 1/1 Running 0 32m
nginx 1/1 Running 0 38mGet Pods with Labels
kubectl get pods --show-labelsNAME READY STATUS RESTARTS AGE LABELS
my-dep-b458fdbb4-2bl5x 1/1 Running 0 32m app=my-dep,pod-template-hash=b458fdbb4
my-dep-b458fdbb4-5lkrc 1/1 Running 0 32m app=my-dep,pod-template-hash=b458fdbb4
my-dep-b458fdbb4-kt85r 1/1 Running 0 32m app=my-dep,pod-template-hash=b458fdbb4
my-dep-b458fdbb4-lx8j4 1/1 Running 0 32m app=my-dep,pod-template-hash=b458fdbb4
my-dep-b458fdbb4-pcjfw 1/1 Running 0 32m app=my-dep,pod-template-hash=b458fdbb4
nginx 1/1 Running 0 38m run=nginxGet Pods Wide (shows which node)
k get pods -o wideNAME READY STATUS IP NODE
my-dep-b458fdbb4-2bl5x 1/1 Running 10.42.1.186 k3s-worker-02
my-dep-b458fdbb4-5lkrc 1/1 Running 10.42.1.184 k3s-worker-02
my-dep-b458fdbb4-kt85r 1/1 Running 10.42.0.104 k3s-cp-01
my-dep-b458fdbb4-lx8j4 1/1 Running 10.42.0.105 k3s-cp-01
my-dep-b458fdbb4-pcjfw 1/1 Running 10.42.1.185 k3s-worker-02(Visited 3 times, 1 visits today)

