- 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
kind
field 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.replicas
is a field that specifies the desired number of pod you want to run at any given time. - The
.spec.selector
is a label selector which tells the ReplicaSet how to find which Pods it should manage. - The
.spec.template
is a pod template that ReplicaSet will manage. - The
.spec.template.metadata.labels
are 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.labels
must be equal to the.spec.selector
.
Rollout and Versioning
- when we create
Deployment
it creates a rollout of new version of applications and new revision ofDeployment
is created. - If the current revision has some errors we can revert back to older
Deployment
Deloyment Strategy
Recreate
andRollingUpdate
strategy are used to deploy new version of applicationRecreate
will bring all pods down and starts new ones with new versionRollingUpdate
will bring one pod down and start new one and so onRollingUpdate
is 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 ➡️