I have deploy my application in kubernetes using deployment.
- Whenever user gets login to application pod will generate session for that user.
- To maintain session stickiness I have set session cookie using Nginx ingress annotations.
- When hpa scale down pods application user is phasing a logout problem when pod is get terminated. If ingress has generated a session using this pod. It needs to log in again.
- What I want is some sort of graceful termination of the connection. when pod is in a terminating state it should serve existing sessions until grace period.
2
Answers
You can use the key in POD spec : terminationGracePeriodSeconds
this will wait for the mentioned second and after that POD will get terminated.
You can read more at : https://cloud.google.com/blog/products/containers-kubernetes/kubernetes-best-practices-terminating-with-grace
The answer Harsh Manvar is great, However, I want to expand it a bit 🙂
You can of course use terminationGracePeriodSeconds in the POD spec. Look at the example yaml:
For more look here.
If you want to know how exactly looks like pod lifecycle see this link to the official documentation. The part about the termination of pods should be most interesting. You will also have it described how exactly the termination takes place.
It is recommended that applications deployed on Kubernetes have a design that complies with the recommended standards.
One set of standards for modern, cloud-based applications is known as the Twelve-Factor App: