<p>I have nginx pod with following configuration (partly shown here): </p>

<pre><code>        upstream something-1-8080 {
              server something-1.namespace:8080;
        }
        upstream something-2-8080 {
              server something-2.namespace:8080;
        }

        server {
              proxy_buffering off;
              proxy_redirect off;
              proxy_set_header X-Real-IP $remote_addr;
              access_log /dev/stdout timed_combined;

              listen 443 ssl http2;
              server_name some.server.net;
              location /api/v1/something1 {
                    rewrite ^/api/v1/something1/(.*)$ /$1  break;
                    rewrite ^/api/v1/something1(.*)$ /$1  break;
                    proxy_pass http://something-1-8080;
              }
              location /api/v1/something2 {
                    rewrite ^/api/v1/something2/(.*)$ /$1  break;
                    rewrite ^/api/v1/something2(.*)$ /$1  break;
                    proxy_pass http://something-2-8080;
              }
              location / {
                    proxy_pass  http://some.nice.server.com;

              }
              ssl_certificate     /etc/nginx/secret/tls.crt;
              ssl_certificate_key /etc/nginx/secret/tls.key;
        }
</code></pre>

<p>I would like to translate my nginx config to kubernetes ingress-nginx (Ingress resource).
Is there a way to implement this config using kubernetes Ingress resources? Reading ingress-nginx docs I haven't found how to map proxy_pass or multiple rewrites to Ingress resource. I would appreciate ref to some detailed doc or sample with similar config. </p>

<p>The ingress-nginx <code>mandatory.yaml</code> file, which the documentation specifies for deploying the ingress-nginx ingress controller, sets-up a k8s ConfigMap with the default name <code>nginx-configuration</code> in the default <code>ingress-nginx</code> namespace.  See the link to the mandatory file from the <a href="https://kubernetes.github.io/ingress-nginx/deploy/" rel="nofollow noreferrer">deployment documentation</a>.</p>

<p>Then, to configure your nginx conf file, you can simply add key-value pairs to the <code>nginx-configuration</code> ConfigMap. The available settings and their keys are in the ingress-nginx documentation on <a href="https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/configmap/" rel="nofollow noreferrer">ConfigMaps</a>. I have found they differ (slightly) from the nginx config names.</p>

<p>Here's an example ConfigMap.yaml file with some settings I've made for my controller.</p>

<pre><code>kind: ConfigMap
apiVersion: v1
metadata:
  name: nginx-configuration
  namespace: ingress-nginx
  labels:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
data:
  # This tells the nginx config to look at a different ConfigMap named custom-headers if you have a lot of headers you want to set
  proxy-set-headers: "ingress-nginx/custom-headers"

  # Suggested changes for interacting with Cloud service load balancing
  proxy-read-timeout: "660"  
  proxy-send-timeout: "660"

  # Custom code that can be referenced
  http-snippet: "map $http_upgrade $connection_upgrade {
                     default 'upgrade';
                     ''      close;
                }"
  proxy-body-size: "500m"
</code></pre>

<p>When you post your ConfigMap, ingress-nginx is smart enough to update itself, on-the-fly with no downtime. You should see the changes noted in the logs.</p>

<p>Finally, it's best to check your config settings are active by looking at the dynamically-generated nginx.conf file. I like to do that with the <a href="https://kubernetes.github.io/ingress-nginx/kubectl-plugin/" rel="nofollow noreferrer">kubectl plugin described in the documentation</a>.</p>
