0

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:

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!

Stroboscopio
  • 150
  • 3
  • 11
  • Hello, this topic could be quite extensive considering the fact of multiple ways of `nginx-ingress` provisioning, the `Service` usage alongside with it and the support for specific features. Also `nginx.conf` is "hidden" behind the `Ingress` resource definition (exec into the `ingress-nginx-controller` Pod and see for yourself. First of all please tell how your Kubernetes cluster was created? Is it on premise one or a provider-managed like `GKE` or `EKS` or `AKS`. Knowing this information would help to give you more specific solution and give you more baseline idea behind it. – Dawid Kruk Mar 16 '21 at 13:40
  • @DawidKruk Thanks for your help in advance! I wanted to host my cluster locally so I'm using the Docker Desktop Kubernetes plugin, it creates a 1 node cluster on my local machine. I followed the "Installation with Manifests" guide on the NGINX website (https://docs.nginx.com/nginx-ingress-controller/installation/installation-with-manifests/). I looked at the config file from exec'ing into the pod like you said and the proxy_pass looks kind of strange to me. If you tell me what .yaml files to include in the question I'll edit it and include them. – Stroboscopio Mar 16 '21 at 14:41

2 Answers2

1

The most straightforward process of installing nginx ingress controller (or any other for that matter) would be using helm. This would need basic understanding of helm and how to work with helm charts.

Here's the repo: https://github.com/kubernetes/ingress-nginx/tree/master/charts/ingress-nginx

Follow the instructions in there - quite straightforward if you use the default values. For the configuration, you can customize the chart too before installing. Look at the Readme to see how to get all the configurable options.

Hope this helps as a starting point.

rock'n rolla
  • 1,883
  • 1
  • 13
  • 19
  • I'll make sure to give it a look! I'm getting some 404 Not Found errors in the app so I think I misconfigured something and I'll have to look it over. Either that or I delete and re-apply with helm. – Stroboscopio Mar 16 '21 at 18:27
  • @Stroboscopio 404 not found error could mean that either you haven't configured `Ingress` resource or the `Host` or `Path` doesn't match. – Dawid Kruk Mar 18 '21 at 12:32
1

Answering:

How should I install nginx-ingress

There is no one correct way to install nginx-ingress. 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.

You can choose from running:

  • $ kubectl apply -f ...,
  • $ helm install ...,
  • terraform apply ... (helm provider),
  • etc.

How should I properly configure Ingress?

Citing the official documentation:

An API object that manages external access to the services in a cluster, typically HTTP.

-- Kubernetes.io: Docs: Concepts: Services networking: Ingress

Basically Ingress is a resource that tells your Ingress controller how it should handle specific HTTP/HTTPS traffic.

Speaking specifically about the nginx-ingress, it's entrypoint that your HTTP/HTTPS traffic should be sent to is a Service of type LoadBalancer named: ingress-nginx-controller (in a ingress-nginx namespace). In Docker with Kubernetes implementation it will bind to the localhost of your machine.

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: minimal-ingress
spec:
  ingressClassName: "nginx"
  rules:
  - http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: nginx
            port:
              number: 80

The modified example from the documentation will tell your Ingress controller to pass the traffic with any Host and with path: / (every path) to a service named nginx on port 80.

The above configuration after applying will be reflected by ingress-nginx in the /etc/nginx/nginx.conf file.

A side note!

Take a look on how the part of nginx.conf looks like when you apply above definition:

                location / {
                       set $namespace      "default";
                       set $ingress_name   "minimal-ingress";
                       set $service_name   "nginx";
                       set $service_port   "80";
                       set $location_path  "/";
                       set $global_rate_limit_exceeding n;

On how your specific Ingress manifest should look like you'll need to consult the documentation of the software that you are trying to send your traffic to and ingress-nginx docs.


Addressing the part:

how to properly configure the Ingress. For example, the Kubernetes docs say to use a nginx.conf file (https://kubernetes.io/docs/tasks/access-application-cluster/connecting-frontend-backend/#creating-the-frontend) which is never mentioned in the actual NGINX docs. They say to use ConfigMaps or annotations.

You typically don't modify nginx.conf that the Ingress controller is using by yourself. You write an Ingress manifest and rest is taken by Ingress controller and Kubernetes. nginx.conf in the Pod responsible for routing (your Ingress controller) will reflect your Ingress manifests.

Configmaps and Annotations can be used to modify/alter the configuration of your Ingress controller. With the Configmap you can say to enable gzip2 compression and with annotation you can say to use a specific rewrite.

To make things clearer. The guide that is referenced here is a frontend Pod with nginx installed that passes the request to a backend. This example apart from using nginx and forwarding traffic is not connected with the actual Ingress. It will not acknowledge the Ingress resource and will not act accordingly to the manifest you've passed.

A side note!

Your traffic would be directed in a following manner (simplified):

  • Ingress controller -> frontend -> backend

This example speaking from personal perspective is more of a guide how to connect frontend and backend and not about Ingress.


Additional resources:

The guide that I wrote some time ago should help you with the idea on how you can configure basic Ingress (it could be little outdated):

Dawid Kruk
  • 8,982
  • 2
  • 22
  • 45
  • Ok, thank you very much for the amazing answer! I had some difficulties so I uninstalled and then reinstalled everything, following your answer made the process much clearer and I know understand how the Ingress Controller works and is configured. I'm having some problems with my React app right now but I think that's down to some other misconfiguration with the Docker Image. Before that I didn't really understand how the Ingress controller could "configure itself" suing the Ingress resource. Thanks for being so polite also! – Stroboscopio Mar 18 '21 at 14:02