0

Hello everyone I can't find a way to provide a "graceful shutdown" in Nest microservices, in particular using NATS.

Expected behavior:

  1. The application in kubernetes received a 'SIGTERM' signal.
  2. stops listening for new incoming requests.
  3. service of accepted requests is completed and a response is given.
  4. the application closes all connections and shuts down.

1 Answers1

0

You can use the Kubernetes spec config to set the graceful shutdown for POD: terminationGracePeriodSeconds

Default value of terminationGracePeriodSeconds is 30 seconds

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
    name: test
spec:
    replicas: 1
    template:
        spec:
            containers:
              - name: test
                image: ...
            terminationGracePeriodSeconds: 60

Read best practise : https://cloud.google.com/blog/products/containers-kubernetes/kubernetes-best-practices-terminating-with-grace

Harsh Manvar
  • 27,020
  • 6
  • 48
  • 102