Kubernetes Gateway API integration with Cert Manager
This article will walk you through the steps to activate Cert Manager with LetsEncrypt certificates for use with the Kubernetes Gateway API resources.
This post is a part of the Gateway API series on Kubito. Make sure you check out the other posts in this series in the menu above.
Building on our previous discussions about establishing the Gateway API with Cilium and its configuration for exposing applications from a Kubernetes cluster, we now turn our focus to integrating Cert Manager with the Gateway API. This step is crucial for terminating SSL directly at the Gateway API level.
Certificate Generation with Cluster Issuers
In our setup, we will leverage Cert Manager to streamline the generation and automated renewal of SSL certificates for our domains. This setup aligns with our previous work with Cilium and Gateway API resources. Cert Manager not only generates a certificate but also crafts a Kubernetes Secret
from it. This secret is subsequently utilized by the previously established Gateway
. It handles automatic renewal 15 days prior to expiration, aligning with our preset configuration.
The foundation of Cert Manager’s functionality is a ClusterIssuer
resource. This resource demands the staging or production LetsEncrypt server and the API token created by our desired DNS records manager. In this post, we will use Cloudflare in the examples. You should have a Secret
ready with the Cloudflare API token. With this resource in place, Cert Manager is empowered to issue certificates across the entire cluster. In our scenario, we’re setting up two distinct ClusterIssuers
, one for each of our domain types: .link
and .io
.
|
|
Now, let’s delve into the specifics of our certificate configurations. We’ve opted for wildcard certificates to ensure that all subdomains are equally secured with valid certificates. Each certificate configuration explicitly references the appropriate ClusterIssuer
, ensuring a seamless integration. Additionally, we meticulously set the duration and renewal periods for each certificate. It’s important to note that the names we assign to these certificates are not just labels; they are the key identifiers for the secrets that the Gateway
will reference.
|
|
Attaching Certificates to Gateway
After generating the certificates, you can simply attach the secret to the HTTPS listeners:
|
|
Certificate Generation with Gateway Annotations
Cert Manager is adept at producing TLS certificates specifically for Gateway resources. This capability is used by appending annotations to a Gateway, a process akin to what we undertake when securing Ingress Resources.
Activating the cert-manager
feature for GatewayAPI integration involves enabling the GatewayAPI feature gate. For those utilizing Helm, the process is straightforward:
|
|
When configuring cert-manager
for a Gateway
, the annotations cert-manager.io/issuer
or cert-manager.io/cluster-issuer
play a pivotal role. They signal cert-manager
to initiate the creation of a Certificate
specifically for that Gateway
. Consider the following scenario, a Gateway
configured as below will prompt cert-manager
to generate a Certificate
named example-com-tls
:
|
|
Shortly after the initial setup, cert-manager
springs into action, creating a Certificate
. This Certificate
bears the name of the Secret
, wildcard-example-io
, in this instance. Notably, the dnsNames
field within the Certificate aligns with the hostname
field specified in the Gateway
specifications.
Conclusion
This post details integrating Cert Manager with the Gateway API in Kubernetes for efficient SSL termination. It focuses on using Cert Manager for automated SSL certificate generation and renewal, highlighting the configuration of ClusterIssuer
resources for domain-specific management. The setup includes creating wildcard certificates for broader security coverage and linking these certificates to the Gateway
via Kubernetes secrets. Additionally, the post explores Cert Manager’s capability to generate TLS certificates for Gateway
resources using annotations, streamlining certificate management and enhancing security in Kubernetes clusters. This integration exemplifies a seamless and secure approach to SSL certificate management in Kubernetes environments.
If you find this post helpful, please consider supporting the blog. Your contributions help sustain the development and sharing of great content. Your support is greatly appreciated!
Buy Me a Coffee