<h2>Scenario</h2>
<p>I'm running NGINX and Kubernetes. I need to configure NGINX so that it sets or overrides the Host header <code>Host: minio:9000</code> to a pod so that the Pod will always service requests thinking that it's hosting as <code>minio:9000</code> no matter where the request is coming from. I believe the recommended approach is to use NGINX and modify the ingress annotations of that Pod (maybe I'm wrong).</p>
<h2>How I currently set it up</h2>
<p>I instead my nginx controller with helm via this guide <a href="https://kubernetes.github.io/ingress-nginx/deploy/#using-helm" rel="nofollow noreferrer">https://kubernetes.github.io/ingress-nginx/deploy/#using-helm</a></p>
<pre><code>helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm install my-release ingress-nginx/ingress-nginx
</code></pre>
<p>I declared my ingress like this. Guides have suggested I use nginx annotations on the ingress YAML.</p>
<pre><code>apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: {{ template &quot;fullname&quot; . }}
  labels:
    chart: {{ template &quot;chartVersion&quot; . }}
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /$1
    nginx.ingress.kubernetes.io/ssl-redirect: &quot;false&quot;
    nginx.ingress.kubernetes.io/configuration-snippet: |
      more_set_input_headers 'Host: minio:9000';

spec:
  rules:
  - host: {{ .Values.ingress.host }}
    http:
      paths:
      - path: /
        backend:
          serviceName: {{ template &quot;fullname&quot; . }}
          servicePort: {{ .Values.deployment.servicePort }}

</code></pre>
<p>Many guides have said this would work. I've tried</p>
<pre><code>nginx.ingress.kubernetes.io/upstream-vhost: minio:9000
</code></pre>
<p>I've also tried</p>
<pre><code>nginx.ingress.kubernetes.io/configuration-snippet: |
  access_by_lua_block {
    ngx.var.best_http_host = 'minio:9000';
  }
</code></pre>
<p>None of these methods seem to change the host header from inside the cluster. If I do</p>
<pre><code>nginx.ingress.kubernetes.io/configuration-snippet: |
  proxy_set_header Host 'minio:9000';
</code></pre>
<p>I get a 400 response saying too many <code>Host</code> headers (which seems to be caused by the Pod running Go). But at least I know the annotations are being picked up by nginx.</p>
<h2>Questions</h2>
<ul>
<li>How can I configure NGINX in kubernetes so that it changes the Host header from inside the ingress?</li>
<li>Perhaps I installed NGINX the wrong way? It doesn't seem easy to modify the conf files from NGINX if you install it through helm. Is it better to install NGINX manually and not through k8s or helm?</li>
</ul>

Math is Hard
<p>Turns out it was by my other annotation <code>nginx.ingress.kubernetes.io/rewrite-target: /$1</code> stripping the path inside the cluster. Getting rid of this annotation makes the ingress work as intended.</p>
