Practical Guide to Setting Up ingress-nginx on Kubernetes
This post walks you through setting up the ingress-nginx controller on your Kubernetes cluster, deploying a minimal backend application, and creating an Ingress resource to route external traffic to your backend.
Prerequisites
Deploy Example Service
Follow the instructions from Setting Up an Example Service to set up an example kubernetes service.
Deploying an example service helps verify that the Ingress controller correctly routes traffic to a live service.
Install Cert-Manager
Follow installation instructions from Cert-Manager post to install cert-manager.
cert-manager is crucial for securing your Ingress traffic with TLS. (The ClusterIssuer will be created in a later step.)
Ingress Controller Setup
Follow these steps to deploy the Ingress-NGINX controller and configure DNS routing.
- Deploy Ingress-NGINX Controller
- Run the following command to install or upgrade the Ingress-NGINX controller using Helm.
1 2 3
helm upgrade --install ingress-nginx ingress-nginx \ --repo https://kubernetes.github.io/ingress-nginx \ --namespace ingress-nginx --create-namespace
- This command creates a new namespace (ingress-nginx) and deploys the Ingress-NGINX controller within it.
- Run the following command to install or upgrade the Ingress-NGINX controller using Helm.
- Retrieve the External IP of the Load Balancer
- Once the controller is deployed, check the external IP assigned to the ingress-nginx-controller service.
- Look for the
EXTERNAL-IPunder the LoadBalancer type service. It may take a few moments to be assigned.1
kubectl get svc -n ingress-nginx
- Map the External IP to a DNS Name:
- Use your preferred DNS provider (e.g., Cloudflare, AWS Route 53, Google Domains) to create an
A recordpointing to the retrievedExternal IP. - For exact instructions, refer to your DNS provider’s documentation.
- Use your preferred DNS provider (e.g., Cloudflare, AWS Route 53, Google Domains) to create an
- Verification:
- Once updated, verify that the domain is correctly resolving to the External IP by running
1 2 3
nslookup app.example.com # replace this with your dns. # OR dig app.example.com # replace this with your dns
- Once updated, verify that the domain is correctly resolving to the External IP by running
Configuring Cluster Issuer
Configure your ClusterIssuer by following the instructions in the Cert-Manager post. This issuer will be used later to generate TLS certificates for your Ingress.
Deploy TLS-Enabled Ingress Resource
Create an Ingress resource to route traffic to your service and enable TLS.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: http-echo-ingress
namespace: example
annotations:
cert-manager.io/cluster-issuer: "letsencrypt-cluster-issuer" # name of the cluster issuer.
kubernetes.io/ingress.class: "nginx"
spec:
ingressClassName: nginx
tls:
- hosts:
- app.example.com # replace with your domain name.
secretName: http-echo-staging-tls
rules:
- host: app.example.com # replace with your domain name.
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: http-echo
port:
number: 80
- Apply the ingress resource.
1
kubectl apply -f ingress.yaml
Verification
Test the Ingress configuration by accessing your service:
1
curl https://app.example.com -v # replace with your domain name.
If everything is set up correctly, you should receive a hello-world response from the server.