NestJS Kubernetes Deployment | Part 3: Ingress Configuration
Deploying NestJS applications on the Kubernetes Cluster series is divided into two main and two follow-up stories.
Part 1: Containerizing a NestJS application with Docker
Part 2: Kubernetes Deployment
Part 3: Bonus: Ingress Configuration
Part 4: Bonus: Kubernetes CronJob — NestJS
This is a follow-up story for . See part 2.
Getting Started 📌
Ingress is an API object that manages external access to the services in a cluster.
Ingress-nginx is preferred in this story which is built around Kubernetes’ ingress and configmap resources. There are many different options. (read more) Find the suiting commands for your provider from here to install ingress-nginx on your cluster if you don’t already have it. This story continues with the installation using Helm.
Installation Using Helm 🔧
$ helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
$ helm repo update
$ helm install ingress-nginx ingress-nginx/ingress-nginx --namespace ingress-nginx --create-namespace --wait
These commands will create a namespace called ingress-nginx and deploy ingress controller inside it. (see original document)
(Takes few minutes)
Defining Ingress Rule ↗️⬇️⬅️
Create a file named ingress.yaml. Use the following configuration to define your first ingress rule.
$ kubectl apply -f ingress.yaml
In a real-life scenario, you will have your actual hostname instead of kubernetes.docker.internal. This allows us to test our ingress rules locally as much as possible. Running the following command is a good practice to track the state of your ingress definition. It is not usable until it gets an address. Again, in a real-life scenario, you will see the address of your domain.
$ kubectl get ingress --watch
See other configurations such as re-writing, annotations, fanout, and more from here.
kubernetes.docker.internal is the default host Docker appends to the etc/hosts file during installation.
You can duplicate the 127.0.0.1 kubernetes.docker.internal line and change the host part. See the example below.
After that update the host inside your ingress file and apply again. Now you can access it via your new host.
Minikube users, you are not forgotten.
$ minikube ip
Get your IP and add it to the etc/hosts file.
Update your ingress file and apply. (replace kubernetes.docker.internal with demo.home) Now you must be able to access the application from the following link. http://demo.home/health