Deployment is a Kubernetes object. The deployment provides us with the capability to upgrade the underlying instances seamlessly using rolling updates, undo changes, pause, and resume changes as required.
In a production environment,
- You need not one but many such instances of the server running.
- Whenever newer versions of the application builds become available on the docker registry, you would like to upgrade your docker instances seamlessly. However, when you upgrade your instances you do not want to upgrade all of them at once. This may impact users accessing our applications so you might want to upgrade them one after the other and that kind of upgrade is known as rolling updates.
- You would like to make multiple changes to your environment such as upgrading the underlying web server versions as well as scaling the environment and also modifying the resource allocations etc. You do not want to apply each change immediately after the command is run, instead you like to apply a pause to your environment make the changes and then resumes so that all the changes are rolled out together.
All of these capabilities are available with the Kubernetes deployments.
The contents of the deployment file is similar to replicaSet file.
apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment labels: app: nginx spec: replicas: 3 selector: matchLabels: app: nginx template: metadata: name: nginx-pod labels: app: nginx spec: containers: - name: nginx-container image: nginx ports: - containerPort: 80 protocol: TCP
$ kubectl apply -f nginx-deployment.yaml deployment.apps/nginx-deployment created $ kubectl get deployments NAME READY UP-TO-DATE AVAILABLE AGE nginx-deployment 3/3 3 3 55s $ kubectl get replicaset NAME DESIRED CURRENT READY AGE nginx-deployment-5b4596cf84 3 3 3 2m28s $ kubectl get pods NAME READY STATUS RESTARTS AGE nginx-deployment-5b4596cf84-4h22n 1/1 Running 0 2m48s nginx-deployment-5b4596cf84-8tx7f 1/1 Running 0 2m48s nginx-deployment-5b4596cf84-c9vmc 1/1 Running 0 2m48s
The deployment automatically creates a replicaSet, so you can see the the replicaSet is running with
kubectl get replicaset commands. The replicaSets ultimately create pods. Thus, if you run the
kubectl get pods, you will be able to see the pod with the name of the deployment and the replicaSet. so far there hasn’t been much of a difference between replicaSet and deployments except for the fact that deployment created a new kubernetes object called deployments
kubectl get all
$ kubectl get all -n default NAME READY STATUS RESTARTS AGE pod/nginx-deployment-5b4596cf84-4h22n 1/1 Running 0 43m pod/nginx-deployment-5b4596cf84-8tx7f 1/1 Running 0 43m pod/nginx-deployment-5b4596cf84-c9vmc 1/1 Running 0 43m NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 88d NAME READY UP-TO-DATE AVAILABLE AGE deployment.apps/nginx-deployment 3/3 3 3 43m NAME DESIRED CURRENT READY AGE replicaset.apps/nginx-deployment-5b4596cf84 3 3 3 43m