Routing based on request headers using AWS Load Balancer or nginx Routing based on request headers using AWS Load Balancer or nginx kubernetes kubernetes

Routing based on request headers using AWS Load Balancer or nginx


You can configure your Nginx Ingress Controller and use annotation:

nginx.ingress.kubernetes.io/server-snippet

Your Ingress might look like the following:

apiVersion: extensions/v1beta1kind: Ingressmetadata:  annotations:    nginx.ingress.kubernetes.io/server-snippet: | set $agentflag 0; if ($http_user_agent ~* "(Mobile)" ){ set $agentflag 1; } if ( $agentflag = 1 ) { return 301 https://m.example.com; }

Please check a more detailed explanation of Annotations for ingress-nginx on Github.

If you have more than one node, you can schedule POD on the same node by using Node affinity. This can be also achieved by using nodeSelector which is a simple version of Node affinity.