0

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 !

Rémy
  • 364
  • 1
  • 14

2 Answers2

2

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.

Chris
  • 5,109
  • 3
  • 19
  • 40
0

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