ingress-nginx config use custom variables

11/20/2019

I have a nginx conf like below

map $http_upgrade $connection_upgrade {
  default upgrade;
  ''      close;
}

server {
  listen 80 default_server;
  access_log  off;
  return 200 'Hello, World! - nginx\n';
}

server {
  listen 80;
  server_name ~^(dev-)?(?<app>[^.]+)\.mysite\.com$;
  access_log  off;

  location / {
     resolver 127.0.0.11;
     proxy_set_header Host $host;
     proxy_pass http://${app}-web;
     proxy_set_header Upgrade $http_upgrade;
     proxy_set_header Connection $connection_upgrade;
  }
}

I expected that redirecting

dev-blog.mysite.com into service blog-web

dev-market.mysite.com into service market-web

and so on

Is there any way to implement this in k8s ingress-nginx?

-- ke ke
kubernetes
nginx-ingress

1 Answer

11/20/2019

No, you would make a separate Ingress object for each (or one huge one, but that's less common). Usually this is semi-automated through either Helm charts or custom controllers.

-- coderanger
Source: StackOverflow