Inject the GCP node zone value to Nginx ingress controller for Zone awareness routing

3/8/2019

I am looking to deploy the Nginx ingress controller in multiple zones and would like to be able to inject the region/zone labels into my pods using environment variables for zone awareness routing. In Zone awareness routing, pods running on the zone sends the traffic to backend servers running on the zone-a. This would essentially to reduce the inter-zone cost.

I have looked into the downward API however this only seems to inject labels/metadata from the pod/service and not from the node where these pods are running on.

Is there any feasible solution to inject the node zone to Nginx pod, so that I can use the Environment variable along with map functionality in Nginx to choose the right upstream backend.

Thank you in advance

-- Rakesh
google-cloud-platform
google-kubernetes-engine
kubernetes
nginx-ingress

1 Answer

3/9/2019

An option might be that you inject the node name via Downward API and then use a sidecar container that gets the zone through Google Cloud API and finally injects the environment var accordingly.

Injecting an environment var from a container to another is not straightforward in general. First, such container should be run before the main container---this may be achieved in Kubernetes via init containers. Second, you need to inject the information. An option would be to use a shared volume (but rather you need a way to watch it or read it at the main container's startup to populate the env vars). Another option would be to use configmaps, where the sidecar/init container populates the configmap to be used by the main container---apparently this problem has been already solved, e.g., here.

-- metaphori
Source: StackOverflow