Deploying HTTPS with Kubernetes Nginx Ingress and Cert Manager
Introduction
This article will guide you through using Nginx Ingress Controller and Cert Manager on Kubernetes (K8s) to automatically issue TLS (Transport Layer Security) certificate. To follow along, you'll need:
- Basic knowledge of Google Kubernetes Engine for cluster initialization
- Understanding of K8s Deployment, Service to deploy applications
- Familiarity with Helm for installing necessary charts.
Ingress
Ingress is a Kubernetes resource used to manage external access to Services within a cluster. It acts like a traffic router, allowing you to define routing configurations to efficiently manage incoming traffic to Services.
Ingress Controller
An Ingress Controller is a distinct component from Ingress itself. There are various types of Ingress Controllers, each capable of different deployments. However, their main function is to manage and deploy according to Ingress rules. When requests reach Ingress, the Ingress Controller uses these defined rules to route traffic to the respective Services. In this article, I'll demonstrate using the Nginx Ingress Controller.
Cert-Manager
Cert-Manager is a tool used to secure Ingress by automatically creating and renewing SSL/TLS certificates before they expire, at no cost.
Implementation Steps
Firstly, you need to initialize a K8s cluster. Here, I'm using GCP, so execute the following command:
Note that the above command works if you have already set the default project ID and region. Check out this article for more specific options to initialize GKE.
Next, use Helm to install the Nginx Ingress Controller and cert-manager along with the necessary configurations.
Check if the resources were successfully installed as follows:
Next, create a deployment.yml file to define the main resources for the application.
Explain:
- Deployment is used to deploy the application. You can replace the Docker image in the image field with the one you want to use, or follow this guide to build the Docker image I used in this example.
- The Service is set to the default type, ClusterIP. I didn’t use LoadBalancer because the Nginx Ingress Controller already has a LoadBalancer service.
- ClusterIssuer contains the configuration info for cert-manager to create HTTPS certificates. In this case, it uses the Let's Encrypt server and the Nginx Ingress Controller to create the private key secret.
- Ingress registers the TLS certificate with your domain and sets up rules to direct traffic to the Service.
- For the Certificate, make sure to specify the correct namespace (here, it’s the default namespace) and set the DNS names according to your domain provider.
Apply the configurations to create the resources.
Note: I've defined all resources in a single file for simplicity, but in practice, you should separate each resource into individual YAML files for better management.
When resources are successfully created:
The application is deployed with an HTTPS TLS certificate.
See you in the next articles!
Comments
Post a Comment