Skip to main content

Kubernetes: 3. Deployments

What is Deployment in Kubernetes?

  • Deployment is a Kubernetes object
  • It is a higher level object, above the replica set
  • A Deployment provides declarative updates for Pods and ReplicaSets.
  • You describe a desired state in a Deployment, and the Deployment Controller changes the actual state to the desired state at a controlled rate.
  • You can define Deployments to create new ReplicaSets, or to remove existing Deployments and adopt all their resources with new Deployments.
  • A deployment automatically creates the replica set
  • Replica set created by deployment should not be managed manually
Uses of Deployment
  • Run multiple instances of applications
  • Upgrade the docker instances seamlessly - Upgrade one after the other - Rolling updates!
  • Rollback the recent changes
  • Upgrade the webservers / Scaling the environment / Update the resources - All at a single time
  • Pause and Resume the upgrades
deployment-definition.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
    name: myapp-deployment
    labels:
        app: myapp
        type: front-end
spec:
    replicas: 3
    selector:
        matchLabels:
            type: front-end

    template:
        metadata:
            name: myapp-pod
            labels:
                app: myapp
                type: front-end
        spec:
            containers:
            - name: nginx-container
              image: nginx


kubectl create -f deployment-definition.yaml

kubectl get deployment-definition.yaml

kubectl get rs
-> A deployment automatically creates replica set

kubectl get pods
-> Check the pods created by replica set

kubectl get all
-> Get all the objects created by kubernetes in the current namespace

kubectl edit deployment my-deployment
-> Update deployment. Pods are recreated with new template

Comments

Post a Comment