title | linkTitle | weight | type |
---|---|---|---|
Enabling automatic TLS certificate provisioning |
Enabling auto TLS certs |
64 |
docs |
If you install and configure cert-manager, you can configure Knative to automatically obtain new TLS certificates and renew existing ones. To learn more about using secure connections in Knative, see Configuring HTTPS with TLS certificates.
You must meet the following prerequisites to enable automatic certificate provisioning:
- The following must be installed on your Knative cluter:
- Knative Serving version 0.6.0 or higher.
- Istio with SDS, version 1.1 or higher. Note: Currently, Gloo is unsupported.
- cert-manager version
0.6.1
or higher.
- Your Knative cluster must be configured to use a custom domain.
- Your DNS provider must be setup and configured to your domain.
To enable Knative to automatically provision TLS certificates:
-
Determine if
networking-certmanager
is installed by running the following command:kubectl get deployment networking-certmanager -n knative-serving
-
If
networking-certmanager
is not found, run the following commands to install it:# KNATIVE_VERSION needs to be 0.6.0 or above. KNATIVE_VERSION=0.6.0 kubectl apply --filename https://github.com/knative/serving/releases/download/v${KNATIVE_VERSION}/serving.yaml \ --selector networking.knative.dev/certificate-provider=cert-manager
-
Create and add the
ClusterIssuer
configuration file to your Knative cluster to define who issues the TLS certificates, how requests are validated (DNS-01
), and which DNS provider validates those requests.-
Create the
ClusterIssuer
file:Use the cert-manager reference to determine how to configure your
ClusterIssuer
file:- See the generic
ClusterIssuer
example - Also see the
DNS-01
example
Example: Cloud DNS
ClusterIssuer
configuration file:The following
letsencrypt-issuer
namedClusterIssuer
file is configured for the Let's Encrypt CA and Google Cloud DNS. Underspec
, the Let's Encrypt account info, requiredDNS-01
challenge type, and Cloud DNS provider info defined. For the complete Google Cloud DNS example, see Configuring HTTPS with cert-manager and Google Cloud DNS.apiVersion: certmanager.k8s.io/v1alpha1 kind: ClusterIssuer metadata: name: letsencrypt-issuer namespace: cert-manager spec: acme: server: https://acme-v02.api.letsencrypt.org/directory # This will register an issuer with LetsEncrypt. Replace # with your admin email address. email: [email protected] privateKeySecretRef: # Set privateKeySecretRef to any unused secret name. name: letsencrypt-issuer dns01: providers: - name: cloud-dns-provider clouddns: # Set this to your GCP project-id project: $PROJECT_ID # Set this to the secret that we publish our service account key # in the previous step. serviceAccountSecretRef: name: cloud-dns-key key: key.json
- See the generic
-
Add your
ClusterIssuer
configuration to your Knative cluster by running the following commands, where<filename>
is the name of the file that you created:-
Add the configuration file to Knative:
kubectl apply -f <filename>.yaml
-
Ensure that the file is created successfully:
kubectl get clusterissuer --namespace cert-manager letsencrypt-issuer --output yaml
Result: The
Status.Conditions
should includeReady=True
.
-
-
-
Update your
config-certmanager
ConfigMap in theknative-serving
namespace to define your newClusterIssuer
configuration and your your DNS provider.-
Run the following command to edit your
config-certmanager
ConfigMap:kubectl edit configmap config-certmanager --namespace knative-serving
-
Add the
issuerRef
andsolverConfig
sections within thedata
section:... data: ... issuerRef: | kind: ClusterIssuer name: letsencrypt-issuer solverConfig: | dns01: provider: cloud-dns-provider
Example:
apiVersion: v1 kind: ConfigMap metadata: name: config-certmanager namespace: knative-serving labels: networking.knative.dev/certificate-provider: cert-manager data: issuerRef: | kind: ClusterIssuer name: letsencrypt-issuer solverConfig: | dns01: provider: cloud-dns-provider
-
Ensure that the file was updated successfully:
kubectl get configmap config-certmanager --namespace knative-serving --output yaml
-
-
Update the
config-network
ConfigMap in theknative-serving
namespace to enableautoTLS
and specify how HTTP requests are handled:-
Run the following command to edit your
config-network
ConfigMap:kubectl edit configmap config-network --namespace knative-serving
-
Add the
autoTLS: Enabled
attribute under thedata
section:... data: ... autoTLS: Enabled ...
Example:
apiVersion: v1 kind: ConfigMap metadata: name: config-network namespace: knative-serving data: ... autoTLS: Enabled ...
-
Configure how HTTP and HTTPS requests are handled in the
httpProtocol
attribute.By default, Knative ingress is configured to serve HTTP traffic (
httpProtocol: Enabled
). Now that your cluster is configured to use TLS certificates and handle HTTPS traffic, you can specify whether or not any HTTP traffic is allowed.Supported
httpProtocol
values:-
Enabled
: Serve HTTP traffic. -
Disabled
: Rejects all HTTP traffic. -
Redirected
: Responds to HTTP request with a302
redirect to ask the clients to use HTTPS.... data: ... autoTLS: Enabled ...
Example:
apiVersion: v1 kind: ConfigMap metadata: name: config-network namespace: knative-serving data: ... autoTLS: Enabled ... httpProtocol: Redirected ...
-
-
Ensure that the file was updated successfully:
kubectl get configmap config-network --namespace knative-serving --output yaml
-
Congratulations! Knative is now configured to obtain and renew TLS certificates. When your TLS certificate is active on your cluster, your Knative services will be able to handle HTTPS traffic.