A Kubernetes deployment is a resource object in Kubernetes that provides declarative updates to applications. A deployment allows you to describe an application’s life cycle, such as which images to use for the app, the number of pods there should be, and the way in which they should be updated.
For example, you have a web server that needs to be deployed in a production environment. You need not run but many such instances of the web server running for obvious reasons.
Secondly, whenever newer versions of the application builds available in the docker registry, you would like to upgrade your docker instances seamlessly.
However, while upgrade your instances you don’t want upgrade all of them at once as this may impact to users accessing your application. So you might want to upgrade them one after the other. This kind of update is called as rolling update.
Suppose one of the upgrade you performed resulted in an unexpected error, and you are asked to undo the recent change. You would like to be rollback the changes that recently carried out.
Finally, say for example you would like to make multiple changes in your environment, such as underlying the web server versions, as well as scaling your environment, also modifying the resource allocations etc.
You don’t want to apply the each change immediately after the command is running instead you would like to pause 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 Deployment.
A Kubernetes deployment is a supervisor for pods, giving you fine-grained control over how and when a new pod version is rolled out as well as rolled back to a previous state.
Create Kubernetes Deployment
apiVersion: apps/v1 kind: Deployment metadata: myapp-deployment name: myapp-deployment labels: app: myapp type: font-end spec: template: metadata: name: myapp-pod labels: app: myapp spec: containers: - name: nginx-container image: nginx replicas: 3 selector: matchLabels: type: font-end
Once Kubernetes deployment file is ready you can run following command.
> kubectl create -f deployment-definition.yml deployment "myapp-deployment" created
To get the list of deployments you can run the following command.
> kubectl get replicaset NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE myapp-replicaset 3 3 3 3 36s
The Kubernetes deployment automatically creates a Replica Set.
> kubectl get replicaset NAME DESIRED CURRENT READY AGE myapp-deployment-6845796 3 3 3 36s
The ReplicaSet automatically creates pods.
> kubectl get pods NAME READY STATUS RESTARTS AGE myapp-deployment-41rfe 1/1 Running 0 45s myapp-deployment-4fdes 1/1 Running 0 45s myapp-deployment-lcsrx 1/1 Running 0 45s