How to force SSL for Kubernetes Ingress on GKE
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
Securing communication over the internet is a crucial aspect of deploying applications in the cloud. Google Kubernetes Engine (GKE) and Kubernetes provide various methods to implement SSL/TLS to ensure secure communication between clients and services. In this article, we will explore how to enforce SSL for Kubernetes Ingress on GKE, providing a detailed step-by-step guide along with technical explanations and examples.
What is Kubernetes Ingress?
Kubernetes Ingress is an API object that manages external access to the services within a cluster, typically via HTTP and HTTPS. It can be configured to provide load balancing, SSL termination, and name-based virtual hosting.
Prerequisites
Before diving in, ensure that you meet these prerequisites:
- A Google Cloud Platform (GCP) account
- A GKE cluster
- The
kubectlcommand-line tool configured to communicate with your cluster - A domain name pointed to your Ingress's IP address
- An SSL certificate for your domain
SSL/TLS Overview
SSL (Secure Sockets Layer) and its successor TLS (Transport Layer Security) are protocols that provide encryption for data transferred over a network. Enforcing SSL/TLS ensures that data exchanged with your services is encrypted and secure from potential intercept or tampering threats.
Enforcing SSL in Kubernetes Ingress
Step 1: Obtain an SSL Certificate
- Use Let's Encrypt: A popular method for obtaining SSL certificates is using Let's Encrypt, a free Certificate Authority.
- Use Google-managed SSL Certificates: GKE simplifies SSL management by allowing you to use Google-managed certificates.
Step 2: Configure Ingress with SSL Certificate
Example: Using a Google-managed SSL Certificate
- Create a ManagedCertificate Resource
- Apply the
ManagedCertificateResource
- Create an Ingress Resource
The Ingress resource is configured to use the previously created ManagedCertificate:
- Apply the
IngressResource
Step 3: Verify SSL Enforcement
- Access your domain (e.g.,
https://yourdomain.com) to verify that the SSL/TLS encryption is active. - Use tools like
curlor a browser to inspect TLS details.
Step 4: Redirect HTTP to HTTPS
To ensure all traffic is encrypted, redirect HTTP traffic to HTTPS:
Step 5: Test the Setup
After applying the configurations, test to ensure that:
- The HTTPS site is loading with a valid certificate.
- HTTP requests are being redirected to HTTPS.
Summary Table
Below is a summary of key points for enforcing SSL with GKE Ingress:
| Step | Description | Tools/Commands |
| Obtain SSL Certificate | Use Let's Encrypt or Google-managed certs | kubectl apply -f managed-cert.yaml |
| Configure Ingress | Use ManagedCertificate with Ingress | kubectl apply -f ingress.yaml |
| Redirect HTTP to HTTPS | Ensure all traffic is secure | Apply NGINX annotations |
| Test SSL enforcement | Validate HTTPS redirect & encryption | Access URLs, use curl for verification |
Additional Considerations
- Certificate Renewal: Automate the renewal process for SSL certificates using Let's Encrypt certbot or similar tools.
- Monitoring: Implement monitoring to alert for SSL/TLS expiration or issues.
- Security Best Practices: Regularly update Kubernetes and adhere to best-practice guidelines for securing GKE clusters.
By following this guide, you should be able to enforce SSL/TLS encryption effectively on Kubernetes Ingress, ensuring secure access to your services hosted on GKE.
Related reading
- How to format the output of kubectl describe to JSON
- how to found the Killed reason of the app in kubernetes pods
- How to generate YAML template with kubectl command?
- How to get a custom healthcheck path in a GCE L7 balancer serving a Kubernetes Ingress?
- How to format a URL to get a file from Amazon S3?
- How to forward port in AWS Application load balancer ALB port forwarding
- How to forward http request to https in Amazon Route53?
- How to generate a verification code/number?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.