apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
# add an annotation indicating the issuer to use.
cert-manager.io/cluster-issuer: nameOfClusterIssuer
name: myIngress
namespace: myIngress
spec:
rules:
host: example.com
http:
paths:
pathType: Prefix
path: /
backend:
service:
name: myservice
port:
number: 80
tls: # < placing a host in the TLS config will determine what ends up in the cert's subjectAltNames
hosts:
example.com
secretName: myingress-cert
If I use the annotation cert-manager.io/cluster-issuer: nameOfClusterIssuer should I create a certificate resource? What should I use in the secretName if I use the annotation?
Assistant
When using the cert-manager.io/cluster-issuer annotation on your Ingress resource, you do not need to create a separate Certificate resource. The cert-manager's Ingress controller (often referred to as the "ingress-shim") automatically handles the creation and management of the Certificate based on the annotations and the TLS configuration specified in the Ingress.
Here's How It Works:
Annotation Usage:
By adding the annotation cert-manager.io/cluster-issuer: nameOfClusterIssuer to your Ingress metadata, you instruct cert-manager to use the specified ClusterIssuer (nameOfClusterIssuer) to obtain the TLS certificate.
TLS Configuration:
In the spec.tls section of your Ingress, you specify the hosts for which the certificate should be valid and the secretName where the certificate will be stored.
Here, myingress-cert is the name of the Kubernetes Secret that will store the TLS certificate and private key. cert-manager will automatically create and manage this Secret based on the Ingress configuration.
Automatic Certificate Creation:
Once the Ingress is applied, cert-manager's Ingress controller detects the annotation and the TLS configuration, then:
Creates a Certificate resource behind the scenes.
Requests the certificate from the specified ClusterIssuer.
Stores the obtained certificate in the specified Secret (myingress-cert).
Keeps the certificate updated as needed (e.g., handles renewals).
Summary:
No Need for Manual Certificate Resource: The annotation and TLS configuration on the Ingress are sufficient for cert-manager to handle certificate provisioning automatically.
Specify secretName in TLS Section: Use the secretName field within the tls section of your Ingress to define where the certificate should be stored. This name is arbitrary and can be chosen based on your preference (e.g., myingress-cert).
cert-manager will automatically create and manage a TLS certificate for example.com using the specified ClusterIssuer.
The certificate and its key will be stored in the Kubernetes Secret named myingress-cert.
Additional Considerations:
Ensure ClusterIssuer Exists: Make sure that the ClusterIssuer named nameOfClusterIssuer is already created and properly configured in your cluster.
Cert-Manager Installation: Ensure that cert-manager is installed and running in your Kubernetes cluster.
Ingress Controller Compatibility: Ensure that your Kubernetes Ingress controller is compatible with cert-manager and correctly configured to work with Ingress resources.
By following this approach, you simplify certificate management by leveraging cert-manager's automation capabilities, reducing the overhead of manually handling Certificate resources.
TL;DR: No, you don’t need to create a separate Certificate resource. By adding the cert-manager.io/cluster-issuer annotation to your Ingress and specifying a secretName in the TLS section (e.g., myingress-cert), cert-manager will automatically generate and store the certificate in that secret.
No; with that annotation, cert-manager will automatically create the Certificate using the secret named in the Ingress’s TLS section (e.g., “myingress-cert”), so you don’t need to create a separate Certificate resource and should set secretName to your desired secret name as shown.