<p>I'm new to Kubernetes and wanted to use the NGINX Ingress Controller for the project I'm currently working on. I read some of the docs and watched some tutorials but I haven't really understood the:</p>
<ul>
<li>installation process (should I use Helm, the git repo???)</li>
<li>how to properly configure the Ingress. For example, the Kubernetes docs say to use a nginx.conf file (<a href="https://kubernetes.io/docs/tasks/access-application-cluster/connecting-frontend-backend/#creating-the-frontend" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/access-application-cluster/connecting-frontend-backend/#creating-the-frontend</a>) which is never mentioned in the actual NGINX docs. They say to use ConfigMaps or annotations</li>
</ul>
<p>Does anybody know of a blog post or tutorial that makes these things clear. Out of everything I've learned so far (both frontend and backend) developing and deploying to a cloud environment has got me lost. I've been stuck on a problem for a week and want to figure out it Ingress can help me.
Thanks!</p>

Stroboscopio
<p>Answering:</p>
<blockquote>
<p>How should I install <code>nginx-ingress</code></p>
</blockquote>
<p>There is no one correct way to install <code>nginx-ingress</code>. Each way has its own advantages/disadvantages, each Kubernetes cluster could require different treatment (for example: cloud managed Kubernetes and minikube) and you will need to determine which option is best suited for you.</p>
<p>You can choose from running:</p>
<ul>
<li><code>$ kubectl apply -f ...</code>,</li>
<li><code>$ helm install ...</code>,</li>
<li><code>terraform apply ...</code> (helm provider),</li>
<li>etc.</li>
</ul>
<hr />
<blockquote>
<p>How should I properly configure <code>Ingress</code>?</p>
</blockquote>
<p>Citing the official documentation:</p>
<blockquote>
<p>An API object that manages external access to the services in a cluster, typically HTTP.</p>
<p>-- <em><a href="https://kubernetes.io/docs/concepts/services-networking/ingress/" rel="nofollow noreferrer">Kubernetes.io: Docs: Concepts: Services networking: Ingress</a></em></p>
</blockquote>
<p>Basically <code>Ingress</code> is a resource that tells your <code>Ingress controller</code> how it should handle specific <code>HTTP</code>/<code>HTTPS</code> traffic.</p>
<p>Speaking specifically about the <code>nginx-ingress</code>, it's entrypoint that your <code>HTTP</code>/<code>HTTPS</code> traffic should be sent to is a <code>Service</code> of type <code>LoadBalancer</code> named: <code>ingress-nginx-controller</code> (in a <code>ingress-nginx</code> namespace). In Docker with Kubernetes implementation it will bind to the localhost of your machine.</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: minimal-ingress
spec:
  ingressClassName: &quot;nginx&quot;
  rules:
  - http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: nginx
            port:
              number: 80
</code></pre>
<p>The modified example from the documentation will tell your <code>Ingress</code> controller to pass the traffic with any <code>Host</code> and with <code>path: /</code> (every <code>path</code>) to a service named <code>nginx</code> on port <code>80</code>.</p>
<p>The above configuration after applying will be reflected by <code>ingress-nginx</code> in the <code>/etc/nginx/nginx.conf</code> file.</p>
<blockquote>
<p>A side note!</p>
<p>Take a look on how the part of <code>nginx.conf</code> looks like when you apply above definition:</p>
<pre><code>                location / {
                       set $namespace      &quot;default&quot;;
                       set $ingress_name   &quot;minimal-ingress&quot;;
                       set $service_name   &quot;nginx&quot;;
                       set $service_port   &quot;80&quot;;
                       set $location_path  &quot;/&quot;;
                       set $global_rate_limit_exceeding n;
</code></pre>
</blockquote>
<p>On how your specific <code>Ingress</code> manifest should look like you'll need to consult the documentation of the software that you are trying to send your traffic to and <a href="https://kubernetes.github.io/ingress-nginx/" rel="nofollow noreferrer">ingress-nginx docs</a>.</p>
<hr />
<p>Addressing the part:</p>
<blockquote>
<p>how to properly configure the Ingress. For example, the Kubernetes docs say to use a nginx.conf file (<a href="https://kubernetes.io/docs/tasks/access-application-cluster/connecting-frontend-backend/#creating-the-frontend" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/access-application-cluster/connecting-frontend-backend/#creating-the-frontend</a>) which is never mentioned in the actual NGINX docs. They say to use ConfigMaps or annotations.</p>
</blockquote>
<p>You typically don't modify <code>nginx.conf</code> that the <code>Ingress controller</code> is using by yourself. You write an <code>Ingress</code> manifest and rest is taken by <code>Ingress controller</code> and <code>Kubernetes</code>. <code>nginx.conf</code> in the <code>Pod</code> responsible for routing (your <code>Ingress controller</code>) will reflect your <code>Ingress</code> manifests.</p>
<p><code>Configmaps</code> and <code>Annotations</code> can be used to modify/alter the configuration of your <code>Ingress controller</code>. With the <code>Configmap</code> you can say to enable <code>gzip2</code> compression and with annotation you can say to use a specific <code>rewrite</code>.</p>
<p>To make things clearer. The guide that is referenced here is a frontend <code>Pod</code> with <code>nginx</code> installed that passes the request to a <code>backend</code>. This example apart from using <code>nginx</code> and forwarding traffic is not connected with the actual <code>Ingress</code>. It will not acknowledge the <code>Ingress</code> resource and will not act accordingly to the manifest you've passed.</p>
<blockquote>
<p>A side note!</p>
<p>Your traffic would be directed in a following manner (simplified):</p>
<ul>
<li><code>Ingress controller</code> -&gt; <code>frontend</code> -&gt; <code>backend</code></li>
</ul>
</blockquote>
<p>This example <strong>speaking from personal perspective</strong> is more of a guide how to connect <code>frontend</code> and <code>backend</code> and not about <code>Ingress</code>.</p>
<hr />
<p>Additional resources:</p>
<ul>
<li><em><a href="https://stackoverflow.com/questions/61541812/ingress-nginx-how-to-serve-assets-to-application/61751019#61751019">Stackoverflow.com: Questions: Ingress nginx how sto serve assets to application</a></em></li>
<li><em><a href="https://stackoverflow.com/questions/64647258/how-nginx-ingress-controller-back-end-protocol-annotation-works-in-path-based-ro/64662822#64662822">Stackoverflow.com: Questions: How nginx ingress controller backend protocol annotation works</a></em></li>
</ul>
<p>The guide that I wrote some time ago should help you with the idea on how you can configure basic <code>Ingress</code> (it could be little outdated):</p>
<ul>
<li><em><a href="https://stackoverflow.com/questions/59255445/how-can-i-access-nginx-ingress-on-my-local/59274163#59274163">Stackoverflow.com: Questions: How can I access nginx ingress on my local</a></em></li>
</ul>
