- Deployment is like a manager in kubernetes.
- Deployment manages ReplicaSets, supports rollbacks, and updates the currently running application version.
- Definition for creating Deployment is same as ReplicaSets. Value of
kindfield is replaced withDeployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: server
labels:
app: webserver
env: prod
spec:
replicas: 3
selector:
matchLabels:
env: prod
template:
metadata:
labels:
env: prod
spec:
containers:
- name: nginx
image: nginx
- The
.spec.replicasis a field that specifies the desired number of pod you want to run at any given time. - The
.spec.selectoris a label selector which tells the ReplicaSet how to find which Pods it should manage. - The
.spec.templateis a pod template that ReplicaSet will manage. - The
.spec.template.metadata.labelsare the labels given to the pod which will be manage/created by ReplicaSet. This is crucial as ReplicaSet will manages all the pods with labels that match the selector and hence.spec.template.metadata.labelsmust be equal to the.spec.selector.
Rollout and Versioning
- when we create
Deploymentit creates a rollout of new version of applications and new revision ofDeploymentis created. - If the current revision has some errors we can revert back to older
Deployment
Deloyment Strategy
RecreateandRollingUpdatestrategy are used to deploy new version of applicationRecreatewill bring all pods down and starts new ones with new versionRollingUpdatewill bring one pod down and start new one and so onRollingUpdateis default strategy- See Blue Green and Canary Deployment to see Additional Strategy
Commands
- create deployment
kubectl create -f deployment-definition.yml
- get deplotment
kubectl get deployments
- describe deployment
kubectl describe deployment <deployment-name>
- rollout status
kubectl rollout status <deployment-name>
- rollout history
kubectl rollout history <deployment-name>
- rollout undo
kubectl rollout undo <deployment-name>
⬅️ ReplicaSets | Service ➡️