Kubernetes rolling update delete old pod before starting a new one

1k views Asked by At

I've a deployment whose app makes a lock on a file, and crash if there's any existing lock. How can I ask Kubernetes to remove the old pod before spinning up the new one ?

I know you usually want the opposite, spinning up the new, and only when it's ready remove the old, to avoid downtime. For this case I don't care, it's typesense in a developments environments, we're using the SaaS for staging & production.

Thanks for any help !

2

There are 2 answers

0
Chris On BEST ANSWER

Easiest way to achieve that is to set the upgrade strategy to Recreate.

apiVersion: apps/v1
kind: Deployment
metadata:
[...]
spec:
  selector:
[...]
  strategy:
    type: Recreate
  template:
[...]

From docs:

All existing Pods are killed before new ones are created when .spec.strategy.type==Recreate.

0
Isaac Carrington On

If you set your replicas to 0 this should generally achieve that:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 0