Setting up Ingress with SSL using NGINX and Cert-Manager
This guide explains how to configure NGINX Ingress Controller and Cert-Manager in a Kubernetes cluster for managing ingress resources with SSL termination.
Prerequisites
- A Kubernetes cluster
kubectl
CLI configured to interact with the cluster
Step 1: Install NGINX Ingress Controller
Deploy the NGINX Ingress Controller to your cluster using the following command:
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/deploy.yaml
Verify the installation:
kubectl get pods -n ingress-nginx
Step 2: Install Cert-Manager
Deploy Cert-Manager to manage SSL certificates:
kubectl apply -f https://github.com/jetstack/cert-manager/releases/download/v1.7.1/cert-manager.yaml
Verify the installation:
kubectl get pods -n cert-manager
Step 3: Create a ClusterIssuer for Let's Encrypt
Apply the following YAML file to create a ClusterIssuer for Let's Encrypt:
apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
name: letsencrypt-prod
namespace: cert-manager
spec:
acme:
server: https://acme-v02.api.letsencrypt.org/directory
email: [email protected]
privateKeySecretRef:
name: letsencrypt-prod
solvers:
- http01:
ingress:
class: nginx
Save this YAML as cluster-issuer.yaml
and apply it:
kubectl apply -f cluster-issuer.yaml
Step 4: Create an Ingress Resource
Replace <your-host>
with your domain name in the following Ingress manifest. This example sets up multiple services with SSL termination:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: example-ingress
annotations:
cert-manager.io/cluster-issuer: "letsencrypt-prod"
kubernetes.io/ingress.class: "nginx"
spec:
tls:
- hosts:
- <your-host>
secretName: tls-secret
rules:
- host: "<your-host>"
http:
paths:
- pathType: Prefix
path: /sample-1
backend:
service:
name: sample-1
port:
number: 3000
- host: "<your-host>"
http:
paths:
- pathType: Prefix
path: /sample-2
backend:
service:
name: sample-2
port:
number: 3000
- host: "<your-host>"
http:
paths:
- pathType: Prefix
path: "/"
backend:
service:
name: sample-3
port:
number: 3000
- host: "<your-host>"
http:
paths:
- pathType: Prefix
path: "/"
backend:
service:
name: sample-4
port:
number: 3000
Save this YAML as ingress.yaml
and apply it:
kubectl apply -f ingress.yaml
Step 5: Verify the Setup
Check the status of the ingress:
kubectl get ing
Check the status of the certificate:
kubectl get certificates