As we dive into kubernetes deployment object. We need to know about kubernetes controller.
A Controller is a control loop that continuously watches the Kubernetes API and tries to manage the desired state of certain aspects of the cluster. There are a number of controllers- Deployments, ReplicaSets and Jobs.
A Deployment has the ability to keep a defined number of replica Pods up and running. A Deployment can also update those Pods to resemble the desired state by means of rolling updates. For example, if you wanted to update a container image to a newer version, you would create a Deployment, and the controller would update the container images one by one until the desired state is achieved. This ensures that there is no downtime when updating or altering your Pods.
Sample deployment yaml
- name: nginx-container
To check how deployment creates Replicasets & PODS.
$ kubectl describe deployment nginx-deployment
To Check the ReplicaSets create:
$ kubectl get rs
To scale up or down replicas ( number of pods).
$ kubectl scale --replicas=2 deploy nginx-deployment
To check what’s running inside container.
$ kubectl log -f <podName>
Other important deployment related commands:
# To check out rollout status
$kubectl rollout status deployment nginx-deployment# Check all revision history
$kubectl rollout history deployment nginx-deployment# To Rollback to previous version
$kubectl rollout undo deploy/nginx-deployment# To Rollback to specific version
$kubectl rollout undo deploy/nginx-deployment --to-revision=<<version>>