'Rolling restart of K8s pods without downtime
We have multiple pods running in K8s cluster which are managed by deployment and we want to restart the pods on a scheduled interval. We are tying below command for deployment but this is not terminating the older pods -
kubectl rollout restart deployment/deploymentname -n namespacename
Below is the behaviour after I run this command -
- Current replicaset revision is 1.
- After running this command a new replicaset is getting created with revision 2 and new pods are coming up.
- After few seconds older replicaset revision is getting changed to 3.
- And the new pods starts getting terminated automatically.
- Older pods are still present on the same replicaset but with revision 3.
- Now there is no replicaset present with revision 1.
Anything we are missing here so that older pods can be terminated after the new ones are up and running?
Below is the deployment spec -
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
deployment.kubernetes.io/revision: "15"
labels:
app.kubernetes.io/component: app
name: sampledeployment
spec:
progressDeadlineSeconds: 600
replicas: 7
revisionHistoryLimit: 10
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
labels:
app.kubernetes.io/component: app
spec:
containers:
- name: container1
livenessProbe:
failureThreshold: 3
httpGet:
path: /healthz
port: 10254
scheme: HTTP
initialDelaySeconds: 5
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 5
- name: container2
livenessProbe:
failureThreshold: 3
httpGet:
path: /status
port: status
scheme: HTTP
initialDelaySeconds: 5
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 5
status:
availableReplicas: 7
conditions:
- lastTransitionTime: "2021-07-27T05:11:49Z"
lastUpdateTime: "2022-03-03T07:54:10Z"
message: ReplicaSet "xxx-dcd9dd47b" has successfully progressed.
reason: NewReplicaSetAvailable
status: "True"
type: Progressing
- lastTransitionTime: "2022-03-11T05:31:29Z"
lastUpdateTime: "2022-03-11T05:31:29Z"
message: Deployment has minimum availability.
reason: MinimumReplicasAvailable
status: "True"
type: Available
observedGeneration: 17
readyReplicas: 7
replicas: 7
updatedReplicas: 7
I have removed container section from this.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
