DEV Community

loading...

How to use NGINX ingress controller in K3s

Ayane Satomi
ex-Coder Technologies and master procrastinator.
・3 min read

The NGINX Ingress Controller is one of the most used ingresses in the Kubernetes ecosystem, being more or less the best ingress controllers out there along with Traefik, which is the default load balancer and ingress in K3s.

So let's say you don't want Traefik, and you want the NGINX Ingress, the answer is: that's possible! And its very easy to get a K3s cluster to use a NGINX Ingress Controller.

Getting your cluster ready

First order of business is that you need to get your cluster have no other ingress controllers as this would conflict with your current ingress controllers. This is because NGINX and Traefik both listens to 80 and 443, which causes conflicts with each other, so make sure your K3s cluster only has one kind of the other.

For the best results, your K3s cluster must be installed with the --no-deploy-traefik argument, which will cause the K3s cluster to deploy only with the bare container orchestrator without the default HTTP backend, which is Traefik.

to make sure you don't have a Traefik controller installed, run kubectl get deployments -n kube-system to see if Traefik is gone.

If you have verified Traefik is not there, then you may proceed with the next part.

Installing NGINX

There's two ways to install NGINX, either from a Helm chart or a direct kubectl apply -f <file>

Using a Helm chart

The NGINX ingress is available in the Helm Stable Charts, and if you have the stable registry already installed in your Helm CLI, simply run helm install stable/nginx-ingress.

You may also modify the installation using the following configurations stated here.

Using the regular kubectl

If you don't want to use Helm, then you can use kubectl apply.

$ kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-0.32.0/deploy/static/provider/cloud/deploy.yaml
Enter fullscreen mode Exit fullscreen mode

This will launch a very basic configuration of the ingress controller, with still having the option to configure it using the configmap.

Verify if it works

Browse on your cluster's address and the all-familiar default NGINX 404 screen should greet you that it works.

Alt Text

How does it compare to Traefik?

In my perspective, not having the UI to monitor the traffic (a Traefik feature) is the only thing I missed, however, I also noticed at one point that the browser returns a HTTP_TOO_MANY_REDIRECTS error if you try to point it in a TLD/subdomain, which I am not yet sure why it doesn't work.

Keep in mind this was tested in Civo so the usual YMMV (Your Mileage May Vary) applies here.

Conclusion

Overall, there's nothing much change for the layman's perspective and nothing's better than the other since Traefik and NGINX are equally good ingress controllers. It depends on preference on which do you like to use for your cluster and which you believe is good for your use case.

This entire guide was tested on the Civo Cloud Platform as part of their #Kube100 initiative. If you're interested to help them test the K3s platform, click on the link to apply!

Discussion (0)

Forem Open with the Forem app