
Nginx Ingress Controller is a popular Kubernetes Ingress controller that uses Nginx as a reverse proxy and load balancer to securely route external traffic to services in a cluster. It works as the single access point for underlying services while offering SSL/TLS termination, load balancing, session handling, and path-based routing for services in the Kubernetes cluster.
In this article, you will set up a Nginx Ingress Controller with SSL in a Kubernetes Engine cluster. You will deploy two applications and issue Let’s Encrypt certificates with Cert Manager to secure them. You will also see how you can import commercial SSL certificates for TLS encryption.
Before you begin, make sure you:
example.com.Add the Nginx Ingress repository.
Update Helm.
Install the Nginx Ingress Controller.
After installation, a Load Balancer is automatically added to your cluster.
Output:
It may take some time for the service to get an EXTERNAL-IP, depending on your cloud provider.
Install the latest CertManager version.
Visit the official CertManager releases page to get the latest version.
Inspect the CertManager Kubernetes resources.
You should see multiple resources of kind pod, service, replicaset, and deployment, all related to your CertManager.
In this section, you'll deploy example applications to test your Nginx Ingress controller. For purposes of this article, deploy two example applications, app1 and app2 using the http-echo image that outputs the command line argument on a html page.
Create a manifest file app1-deploy.yaml for Deployment app1.
Add the following content to the file.
Save and close the file.
Create the second manifest file app2-deploy.yaml for Deployment app2.
Add the following content to the file.
Save and close the file.
Apply the manifest for the app1 deployment.
Apply the manifest for the app2 deployment.
Verify that your deployments are successful.
Your should see the app1 and app2 deployments listed.
Create a new app1-svc.yaml service manifest.
Add the following content to the file.
Save and close the file.
Create another service manifest file app2-svc.yaml.
Add the following content to the file.
Save and close the file.
Deploy the app1-svc service.
Deploy the app2-svc service.
Verify that all services are running.
Your should see the app1-svc and app2-svc services listed.
Login to your DNS Provider account. For example, Vultr DNS.
Access your domain.
Set up a new domain A subdomain record with the value app1 that points to your LoadBalancer’s external IP Address.
Set up another A subdomain record with the value app2 that points to the same IP Address.
In this section, you'll create Ingress resources for both the applications in the cluster and test them.
Create a new manifest file app1-ingress.yaml to create an Ingress resource for app1 Deployment.
Add the following content to the file.
Replace app1.example.com with your domain name. Save and close the file.
Create another manifest file app2-ingress.yaml to create an Ingress resource for app2 Deployment.
Add the following content to the file.
Replace app2.example.com with your domain name. Save and close the file.
Apply the manifest for the ingress-app1 Ingress resource.
Apply the manifest for the ingress-app2 Ingress resource.
Verify that the Ingress resources are available.
You should see the ingress-app1 and ingress-app2 Ingress resources listed. Wait for the ADDRESS column of the output to get its value, which should be the same as the IP address of your load balancer.
You can set up the Nginx Ingress controller to use SSL certificates for your cluster services using an Issuer resource for CertManager. CertManager creates Custom Resource Definitions (CRDs) to handle the certificate issuance process from a Certificate Authority (CA) such as Let’s Encrypt, and these include the following:
In this section, you'll set up the Nginx Ingress Controller to use trusted SSL certificates issued by CertManager.
Inspect the available CRDs by running the following command.
Your output should contain resources related to CertManager, such as issuers.cert-manager.io, certificates.cert-manager.io, clusterissuers.cert-manager.io, and a few more.
Create a new issuer manifest. For example, cert-issuer.yaml.
Add the following configuration to the file.
The above configuration uses the ACME issuer with the following fields:
@example.com email because it would not allow the issuer resource to become active.http01 challenge or the dns01 challenge. It’s recommended to use the http01 challenge unless issuing wildcard certificates.Enter your email address to replace the pre-filled value, then save and close the file.
Apply the issuer resource to your cluster.
Verify that the issuer resource is available and ready to use.
Your output should look like the one below.
The issuer's READY value is False. After some time, the status changes to True.
To configure the Ingress controller to map hosts with TLS, follow the steps below:
Check the state of your Ingress resources.
Edit the app1-ingress.yaml file you created earlier.
Add the following spec.tls section to the file:
The manifest should look like:
Save and close the file.
Similarly, edit the app2-ingress.yaml file and add the following content to the manifest file.
Apply the configurations to enable TLS on each of the hosts.
Verify that your Ingress resources have the TLS port 443 activated under the PORTS column.
Output:
Verify that the certificate resources are available.
Your output should look like the one below.
If the READY column returns True, your Let’s Encrypt certificates are successfully propagated. If False, please check your Ingress resource configuration and reapply changes to request a new certificate.
Depending on your SSL certificate deployment method, verify that you can securely access your services over HTTPS using a web browser of your choice.
If you try to access your hosts over HTTP, the Ingress controller automatically redirects your request to HTTPS.
To import commercial SSL certificates purchased from a trusted certificate authority (CA), convert the certificate and private key to the base64 format, add them to a Kubernetes secret, and then configure your Ingress resources to use the certificates.
Convert the commercial SSL certificate and private key to base64. Copy the resultant values to your clipboard.
Replace /path with the actual directory path to your commercial SSL certificate and private key.
Create a new Kubernetes secrets manifest.
Add the following configurations to the file.
Paste your base64 encoded values to the respective fields as follows:
tls-crt: SSL certificate in base64tls.key: Certificate private key in base64Save and close the file.
To configure Nginx to use your commercial SSL certificate, mention the above Secret resource name in your Ingress resource's spec.tls.secretName field.
Nginx 502 Gateway Error:
Verify that your Ingress configuration is correct and the referenced services are available and running.
Unable to generate Let’s Encrypt Certificates, READY column remains False:
In this article, you have installed and set up the Nginx Ingress Controller with SSL on a Vultr Kubernetes Engine (VKE) cluster. You can use the controller to route external requests to cluster services securely over HTTPS.
0 Comments
Be the first to comment and share your perspective with the community.