Skip to content

Kubernetes - Deployment


  1. Create Deployment
  2. Scale the Deployment
  3. Expose Deployment as a Service
  4. Update Deployment
  5. Rollback Deployment
  6. Rolling Restarts
  7. Pause & Resume Deployments
  8. Canary Deployments (Will be covered at Declarative section of Deployments)

Step-01: Introduction to Deployments

  • What is a Deployment?
  • What all we can do using Deployment?
  • Create a Deployment
  • Scale the Deployment
  • Expose the Deployment as a Service

Step-02: Create Deployment

  • Create Deployment to rollout a ReplicaSet
  • Verify Deployment, ReplicaSet & Pods
  • Docker Image Location:
    # Create Deployment
    kubectl create deployment <Deplyment-Name> --image=<Container-Image>
    kubectl create deployment my-first-deployment --image=stacksimplify/kubenginx:1.0.0 
    # Verify Deployment
    kubectl get deployments
    kubectl get deploy 
    # Describe Deployment
    kubectl describe deployment <deployment-name>
    kubectl describe deployment my-first-deployment
    # Verify ReplicaSet
    kubectl get rs
    # Verify Pod
    kubectl get po

Step-03: Scaling a Deployment

  • Scale the deployment to increase the number of replicas (pods)
    # Scale Up the Deployment
    kubectl scale --replicas=20 deployment/<Deployment-Name>
    kubectl scale --replicas=20 deployment/my-first-deployment 
    # Verify Deployment
    kubectl get deploy
    # Verify ReplicaSet
    kubectl get rs
    # Verify Pods
    kubectl get po
    # Scale Down the Deployment
    kubectl scale --replicas=10 deployment/my-first-deployment 
    kubectl get deploy

AWS EKS - Elastic Kubernetes Service - Masterclass


Step-04: Expose Deployment as a Service

  • Expose Deployment with a service (NodePort Service) to access the application externally (from internet)
    # Expose Deployment as a Service
    kubectl expose deployment <Deployment-Name>  --type=NodePort --port=80 --target-port=80 --name=<Service-Name-To-Be-Created>
    kubectl expose deployment my-first-deployment --type=NodePort --port=80 --target-port=80 --name=my-first-deployment-service
    # Get Service Info
    kubectl get svc
    Observation: Make a note of port which starts with 3 (Example: 80:3xxxx/TCP). Capture the port 3xxxx and use it in application URL below. 
    # Get Public IP of Worker Nodes
    kubectl get nodes -o wide
    Observation: Make a note of "EXTERNAL-IP" if your Kubernetes cluster is setup on AWS EKS.
  • Access the Application using Public IP