Working with Kubernetes Deployment with example

Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now
  • Replication + Controller = ReplicasSets
  • versioning
  • rollout = V1 to V2 of the POD without downtime
  • rollback = V2 to V1 of the POD without downtime

This is a MOST popular Api Resources used to Deploy Stateless POD.

Deployment == Managed by ==> ReplicasSets == Control ==> PODS

ReplicasSets = replicationcontroller+++++++

  # Create a deployment named my-dep that runs the busybox image.
  kubectl create deployment my-dep --image=busybox

  # Create a deployment with command
  kubectl create deployment my-dep --image=busybox -- date

  # Create a deployment named my-dep that runs the nginx image with 3 replicas.
  kubectl create deployment my-dep --image=nginx --replicas=3

  # Create a deployment named my-dep that runs the busybox image and expose port 5701.
  kubectl create deployment my-dep --image=busybox --port=5701



  291  kubectl create -h
  292  clear
  293  kubectl create deployment  -h
  294  clear
  295  kubectl get deploy
  296  kubectl create deployment my-dep --image=scmgalaxy/nginx-devopsschoolv1 --replicas=3
  297  kubectl get deploy
  298  kubectl get rc
  299  kubectl delete rc replicationcontroller-example
  300  clear
  301  kubectl get deploy
  302  kubectl get pods
  303  kubectl edit deploy my-dep
  304  kubectl get pods
  305  clear
  306  kubectl get pods
  307  kubectl scale --replicas=10 deploy/my-dep
  308  kubectl get pods
  309  clear
  310  kubectl get deploy
  311  kubectl get pod
  312  kubectl delete pod my-dep-747b4ffb56-4b4c5 my-dep-747b4ffb56-6t2nc my-dep-747b4ffb56-cd9ws my-dep-747b4ffb56-d6xfw
  313  kubectl get pod
  314  clear
  315  ls
  316  kubectl get deploy
  317  kubectl describe deploy my-dep
  318  kubectl get rs
  319  kubectl describe rs my-dep-747b4ffb56
  320  clear
  321  kubectl get pods
  322  kubectl describe pods my-dep-747b4ffb56-flqjn


Rollout

$ kubectl create deployment my-dep --image=scmgalaxy/nginx-devopsschoolv1 --replicas=15
$ kubectl rollout history deploy/my-dep
$ kubectl rollout status deploy/my-dep
$ kubectl get pods -o wide
$ curl http://ip-of-pod
$ kubectl edit deploy/my-dep # Change image to scmgalaxy/nginx-devopsschoolv2
$ kubectl rollout history deploy/my-dep
$ kubectl rollout status deploy/my-dep
$ kubectl get pods -o wide
$ curl http://ip-of-pod

Rollback

$ kubectl rollout history deploy/my-dep
$ kubectl rollout undo deploy/my-dep --to-revision=1
$ kubectl rollout status deploy/my-dep
$ kubectl get pods -o wide
$ curl http://ip-of-pod