Secure a Nginx Ingress with cert-manager on OVHcloud Managed Kubernetes
Objective
In this tutorial you are going to:
- deploy an application (a
Deploymentand a ClusterIPService) on your OVHcloud Managed Kubernetes cluster - install the Nginx Ingress Controller
- deploy an Ingress to configure the Nginx Ingress Controller to use SSL/TLS through cert-manager
Before you begin
This tutorial presupposes that you already have a working OVHcloud Managed Kubernetes cluster, and some basic knowledge of how to operate it. If you want to know more on those topics, please look at the OVHcloud Managed Kubernetes Service Quickstart guide.
You need to have Helm installed on your workstation and your cluster. Please refer to our tutorial on How to install Helm on OVHcloud Managed Kubernetes Service.
You also need to install cert-manager on your OVHcloud Managed Kubernetes.
Instructions
Deploying the application
In this guide you will deploy an application that runs a HTTP server and displays a web page.
First, create a deployment.yaml file with the following content:
This YAML deployment manifest file defines that our application, based on the ovhplatform/hello:latest image will be deployed with 1 replica (1 pod).
Then, create a svc.yaml file with the following content to define our service (a service exposes a deployment):
Apply the deployment and service manifest files to your cluster with the following commands:
Output should be like this:
You can verify if your application is running and service is created by running the following commands:
Output should be like this:
Installing the Nginx Ingress Controller Helm chart
For this tutorial, we are using the Nginx Ingress Controller Helm chart found on its own Helm repository.
The chart is fully configurable, but here we are using the default configuration.
Add the Ingress Nginx Helm repository:
These commands will add the Ingress Nginx Helm repository to your local Helm chart repository and update the installed chart repositories:
Install the latest version of Ingress Nginx with helm install command:
The install process will begin and a new ingress-nginx namespace will be created.
As the LoadBalancer creation is asynchronous, and the provisioning of the load balancer can take several minutes, you will surely get a <pending> EXTERNAL-IP.
If you try again in a few minutes you should get an EXTERNAL-IP:
You can then access your nginx-ingress at http://[YOUR_LOAD_BALANCER_IP] via HTTP or https://[YOUR_LOAD_BALANCER_IP] via HTTPS.
Configuring the Nginx Ingress Controller to use SSL/TLS
After installing cert-manager on your OVHcloud Manager Kubernetes cluster, if you followed the guide, you should have two running ClusterIssuer, one for production and one for staging/dev usages:
If it's not the case, create a issuer.yaml file with the following content:
nginx is the name of the Ingress resource you are going to create.
And deploy it:
To certificate a resource, the Ingress in our case, we will use annotations.
Thanks to that, Cert-manager will create the Certificate resource that represents a human readable definition of a certificate request. Cert-manager uses this input to generate a private key and CertificateRequest resource in order to obtain a signed certificate from an Issuer or ClusterIssuer. The signed certificate and private key are then stored in the specified Secret resource.
At this step, you need to deploy an Ingress resource and configure it to use the SSL/TLS terminaison.
Create an ingress-tls.yaml file with the following content:
Don't forget to replace [YOUR_DN] with your domain name.
In this manifest file you can see that we define a Nginx Ingress resource with several annotations. For more information about the annotations, please refer to the Securing Ingress Resources in cert-manager documentation.
Apply the ingress manifest files to your cluster with the following commands:
Output should be like this:
At this step, a Certificate resource has been created:
You can display the events of the certificate to check if the certificate has been correctly created and if it creates the necessary CertificateRequest:
And you can check that a CertificateRequest, an Order and a Challenge resource have been created:
You now need to map the Domain Name (DN) and the Load Balancer. In order to do this, create an A-record for [YOUR_DN] (your domain name ;-) mapped to the value of $INGRESS_URL.
Wait until the challenge is resolved:
dig +short [YOUR_DN]
Describe the certificate again and wait until you see "Certificate issued successfully" when you describe the certificate.
Certificate renewal
Cert-manager is a very powerful tool that manages certificate creation and also automatic certificate renewal.
Once an X.509 certificate has been issued, cert-manager will calculate the renewal time for the Certificate and will set the Certificate's RenewalTime status to the time when the renewal is attempted.
You can check your certificate renewal:
Go further
-
If you need training or technical assistance to implement our solutions, contact your sales representative or click on this link to get a quote and ask our Professional Services experts for assisting you on your specific use case of your project.
-
Join our community of users on https://community.ovh.com/en/.