Comprehensive Guide to Kubernetes Deployment

Kubernetes Deployment Controller Object

  • Create Replicas of Pod and deploy the Pod instances to the Worker Nodes

  • Here, the Replicas are created using ReplicaSet

  • Used to Deploy the Replicas of Pods in the available WorkerNodes

  • Perform Scale-Up and Scale-Down the Pod Instances

  • Perform Upgrade and Downgrade the Pod Versions without any downtime.

  • Deployment Strategy called - Rolling Update Strategy to ensure Zero DownTime during Upgrade/Downgrade.

  • Creates :

      1. Deployment Controller

        1. Replicaset

        2. Pod Instances

Replicaset Controller Object

  • Used to Create Replicas/Copies of pods

  • Replicaset Created Automatically during the Deployment Object Creation

Let's see how deployment works.

  1. Deployment YAML file

    1.  # nginx-deploy.yaml
       apiVersion: apps/v1
       kind: Deployment
       metadata:
         name: nginx-deploy
         labels:
           app: nginx-deploy-lbl
       spec:
         replicas: 3
         template:
           metadata:
             labels:
               app: nginx-app
           spec:
             containers:
             - name: nginx-container
               image: nginx:stable-otel
               ports:
               - containerPort: 80
         selector:
           matchLabels:
             app: nginx-app
      
  2. Create and Display Deployment

    1.  kubectl create -f nginx-deploy.yaml 
       kubectl get deploy -l app=nginx-app
       kubectl get rs -l app=nginx-app
       kubectl get po -l app=nginx-app
       kubectl describe deploy nginx-deploy
      

  3. Testing: Rollback update

    1.  kubectl set image deploy nginx-deploy nginx-container=nginx:stable-pearl
       kubectl rollout status deployment/nginx-deploy
       kubectl rollout undo deployment/nginx-deploy
       kubectl rollout status deployment/nginx-deploy
       kubectl describe deploy nginx-deploy | grep -i image
      
    2. When wrong image version mentioned, then “ImagePullBackOff” Error is shown

  4. Testing: Update Version of "nginx:stable-otel" to "nginx:stable-perl"

    1.  kubectl set image deploy nginx-deploy nginx-container=nginx:stable-perl
       # or
       kubectl edit deploy nginx-deploy
      
       kubectl rollout status deployment/nginx-deploy
       kubectl get deploy
      

  5. Testing: Scale UP

    1.  kubectl scale deployment nginx-deploy --replicas=5
       kubectl get deploy
       kubectl get po -o wide
      

  6. Testing: Scale DOWN

    1.  kubectl scale deployment nginx-deploy --replicas=3
       kubectl get deploy
       kubectl get po -o wide
      

  7. Cleanup

    1.  kubectl delete -f nginx-deploy.yaml
       kubectl get deploy
       kubectl get rs
       kubectl get po
      

Kubernetes services :

NodePort Service

  • Used to Expose the pod to Internet

  • It is a special type of service, which can assign addition port ranges from 30000 to 32767.

  • Map the deployment object to NodePort Service, it will be applicable to all corresponding pods.

  • Access it thru.

    • Open Web-browser and access webapage using

      •   http://<external-nodeip>:<nodeport>