Deployment
Upgrade your apps (pod images).
Rollbacks if something goes wrong.
A deployment controller provides declarative updates for Pods and ReplicaSets (Deployment creates ReplicaSet to manage number of PODS).
You describe a desired state in a Deployment, and the Deployment Controller changes the actual state to the desired state at a controlled rate.
Update Image Tag
example tags:
- nginx:1.0
- nginx:2.0
- nginx:3.0
With deployments you can upgrade from old image tag e.g: nginx:1.0
to nginx:3.0
.
If something goes wrong then the image will roll back to old version nginx:1.0
.
Hands On
vim nginx-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
Run the deployment
kubectl apply -y nginx-deployment.yaml
kubectl get deployments
# example output:
# NAME READY UP-TO-DATE AVAILABLE AGE
# nginx-deployment 0/3 0 0 1s
kubectl get deploy
kubectl get rs
kubectl get pod
kubectl describe pod <pod-name>
Updating a deployment
check if new version was changed:
search for image:
confirm that the version is set to 1.16.1
Rollback to a Previous Revision
check if there is old revision
output:
output:
check revision rollout history
rollout to revision number
Delete Deployment
Remember
imperetive is for learning, testing purpose.
But in production do it through definition files.