DEV Community

Cover image for Bite-Sized Kubernetes Part 4 - Deployments
Hrittik Bhattacharjee
Hrittik Bhattacharjee

Posted on • Edited on

Bite-Sized Kubernetes Part 4 - Deployments

Blimey!☸️

In Part 3 we looked at ReplicaSets in kubernetes.
Moving right along to Deployments!🌊

OBJECT DESCRIPTION
Pods The lowest level, single instance of an application
ReplicaSets The next level, manages a set of pods
👉 Deployments The next level, manages a set of ReplicaSets
Services The next level, manages a set of deployments
Ingress The next level, manages a set of services
Volumes The next level, manages a set of ingress
Namespaces The next level, manages a set of volumes
Cluster The highest level, manages a set of namespaces

Deployments:

  • K8s deployments are a higher-level abstraction that are built on top of ReplicaSets.
  • K8s deployments help in rolling updates and rollbacks.
  • K8s deployments are one level above ReplicaSets in the k8s hierarchy.
  • Creating deployments:
  • The .yml definition of a deployment is exactly similar to that of a ReplicaSet except for the kind property.

    • Example deployment-definition.yml:

      apiVersion: apps/v1
      kind: Deployment
      
      # all else is same as ReplicaSet
      
    • Once the .yml file is created, it can be used to create a deployment:

      $ kubectl create -f <file name>.yml
      
    • See list of deployments:

      $ kubectl get deployment
      
    • The deployment will automatically create a ReplicaSet and the ReplicaSet will create the pods.

    • See list of ReplicaSets:

      $ kubectl get replicaset
      
    • See list of pods:

      $ kubectl get pods  
      
    • See detailed info about a deployment:

      $ kubectl describe deployment <deployment name>
      
    • Scale up or down:

      • We can scale up the number of pods by updating the replicas property in the .yml file and then run the kubectl replace command:

        $ kubectl replace -f <file name>.yml
        
      • Or we can use the kubectl scale command:

        $ kubectl scale deployment <deployment name> --replicas=<number of replicas>
        
  • To see all k8s objects created i.e. pods, ReplicaSets, deployments, etc.:

      $ kubectl get all
    
  • Rollouts (updates) and rollbacks in deployments:

    • To see rollout status:

      $ kubectl rollout status deployment <deployment name>
      
    • To see rollout history:

      $ kubectl rollout history deployment <deployment name>
      
    • Deployment strategies:

    • Recreate: the default strategy

      • this will delete all the pods and then create new pods
      • this is not recommended for production
    • RollingUpdate: the recommended strategy

      • this will update the pods one by one
      • this is the recommended strategy and the default strategy for kubectl apply command
    • To update a deployment:

      $ kubectl edit deployment <deployment name>
      
    • After updating the .yml file e.g. updating the app version (image tag), run the kubectl apply command to trigger a new rollout:

      $ kubectl apply -f <file name>.yml
      
    • The k8s deployment will create a new ReplicaSet and the new ReplicaSet will create new pods following wither of the deployment strategies.

    • To rollback a deployment:

      $ kubectl rollout undo deployment <deployment name>
      

You're unstoppable!
Let's look at "Services" next. See ya in Part 5!

Flank Speed!!!🚢

Top comments (0)