kubernetes pod restart takes time and downtime

12/14/2020

I have a service and pod in node.js . .consider hello world .. exposed port : 80 on http

I want to seamlessly restart my service/pod

pod/service restart is taking a lot of time, thus there is downtime.

Using : kubectl delete; then recreate it with kubectl.

How can i avoid delay and downtime ?

-- shrw
autoscaling
kubernetes

1 Answer

12/14/2020

Considering continuous deployments, your previous Pods will be terminated & new Pods will be created. Therefore, downtime of service is possible.

To avoid this add strategy in your deployment spec

example:

apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: api
spec:
  replicas: 4
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0

where maxUnavailable: 0 defines that at any given time more than 1 pods should be available

Extra:

If you service takes some time to be live you can use readiness probe in spec to avoid traffic to be routed before the pods are ready .

example :

readinessProbe:
  tcpSocket:
    port: 80
  initialDelaySeconds: 15
  periodSeconds: 30
-- praveenK
Source: StackOverflow