k8s deployments
- Refer Here for official docs
- Deployments create replicasets which in turn creates pods
- Deployments have strategy
- RollingUpdate: Roll new pods and kill older ones according to percentages or numbers defined (default is 25%)
- Recreate: Delete all existing and recreate new pods
Example 1
- Lets write a deployment spec based on nginx containers
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: example-1
labels:
app: web
spec:
minReadySeconds: 2
replicas: 4
revisionHistoryLimit: 10
selector:
matchLabels:
app: web
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
template:
metadata:
labels:
app: web
env: dev
spec:
containers:
- name: web
image: nginx
ports:
- containerPort: 80
- with the workloads that support rollout (deployment, daemonset, statefulset) we can use
kubectl rollout command
- our version 2 will be httpd containers
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: example-1
labels:
app: web
spec:
minReadySeconds: 2
replicas: 4
revisionHistoryLimit: 10
selector:
matchLabels:
app: web
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
template:
metadata:
labels:
app: web
env: dev
spec:
containers:
- name: web
image: httpd
ports:
- containerPort: 80
- Commands which we used
- kubectl rollout status deployment example-1
- kubectl rollout history deployment example-1
- kubectl rollout undo deployment example-1 –to-revision=1
Annotations
- Annotations are also key pairs. They are designed for external tools to fetch info and add some metadata for tools.
- K8s has well known annotations with specific purposes
You are an expert in k8s, Give me a table of well known annonations and their purpose.
Also add 3 more tables for cloud specific annoations (AWS, Azure, GKE)
- Watch classroom video and add change-cause.
Exercise
- Push your docker images with tags
v1 into docker hub
- Write a deployment manifest with 2 replicas
- now rebuild the docker image and upload the new tag
v2
- Now update the deployment with rollingupdate with 50% maxSurge adn 50% unavailable.
Like this:
Like Loading...