I created a deployment using nginx-ingress, and my pods have readinessProbe and livenessProbe defined. The deployment is connected to a service and ingress to be served over a secure endpoint (e.g. https://myservice.com)
A while after the deployment has started, the pods are marked healthy, and the deployment status becomes Ready. This is great, except that nginx-ingress still has to reload the new configuration causing a 503 for a few seconds when trying to access the endpoint right after the deployment is marked Ready.
How do I know when the endpoint is really ready for traffic?
Nginx ingress now supports dynamic updates on backend changes via lua_nginx_module using the balancer_by_lua
directive.
You need to pass the --enable-dynamic-configuration=true
flag to the container arguments in the Nginx ingress controller deployment (e.g.):
args:
- /nginx-ingress-controller
- --configmap=$(POD_NAMESPACE)/nginx-configuration
- --tcp-services-configmap=$(POD_NAMESPACE)/tcp-services
- --udp-services-configmap=$(POD_NAMESPACE)/udp-services
- --publish-service=$(POD_NAMESPACE)/ingress-nginx
- --annotations-prefix=nginx.ingress.kubernetes.io
- --enable-dynamic-configuration=true
This allows an internal Lua handler to add new endpoints to a shared memory zone, add some load balancing and then relay the requests to the actual backends without rewritting the configuration file in the controller.