Using a custom TLS certificate for DomainMapping¶
Feature Availability: beta since Knative v0.24
- beta features are well-tested and enabling them is considered safe. Support for the overall feature will not be dropped, though details may change in incompatible ways.
Provide a certificate Secret to an existing DomainMapping to serve its mapped hostname over HTTPS. Supplying this certificate bypasses automatic certificate creation for that mapping through external-domain TLS.
Prerequisites¶
- You have a working DomainMapping. Keep its domain name and mapping namespace for every command below.
- You can create a TLS Secret in that namespace and update the mapping. The Secret must be in the DomainMapping's namespace, even if its target is elsewhere.
- You have a matching certificate and private key. The certificate must cover the mapped hostname; callers must trust its issuing Certificate Authority.
- Your networking gateway has an HTTPS endpoint reachable by your callers. The default kind Quickstart's local HTTP test does not by itself expose an HTTPS endpoint. Prepare HTTPS access through your networking layer before using this optional TLS procedure.
Procedure¶
Replace the placeholders with the same domain and namespace used by your existing mapping. Replace certificate/key paths with your actual files. Do not commit or share the private key.
-
Create the TLS Secret in the mapping's namespace:
kubectl create secret tls <tls-secret-name> \ --namespace <namespace> \ --cert=path/to/certificate --key=path/to/private-key -
Set the mapping's certificate reference. This patch changes only the TLS setting and retains the existing target reference and other configuration:
kubectl patch domainmapping <domain-name> \ --namespace <namespace> --type merge \ --patch '{"spec":{"tls":{"secretName":"<tls-secret-name>"}}}'If you maintain the mapping as a YAML manifest, use that method instead: add this
tlsblock alongside the existingspec.refwithout replacing it:spec: # Keep the existing ref and other settings here. tls: secretName: <tls-secret-name>Apply the edited manifest explicitly:
kubectl apply -f <mapping-file>.yaml --namespace <namespace> -
Verify the update in the same namespace:
kubectl wait domainmapping/<domain-name> \ --namespace <namespace> --for=condition=Ready --timeout=120s kubectl get domainmapping <domain-name> --namespace <namespace>READYshould beTrue, andURLshould usehttps://. If not, inspectkubectl describe domainmapping <domain-name> --namespace <namespace>for certificate, claim, or ingress errors. Do not share Secret contents when asking for help. -
From a client that can resolve the mapped hostname and reach its HTTPS gateway, request your application:
curl https://<domain-name>Confirm the application's expected response. Readiness alone does not prove external reachability or that your client trusts the certificate.
For a private test CA or self-signed test certificate, explicitly supply the trusted CA certificate rather than disabling certificate checks:
curl --cacert path/to/trusted-ca-certificate https://<domain-name>
TLS protects the connection; it does not add application authorization. The certificate Secret and DomainMapping remain in the cluster until you remove them or delete the disposable cluster that contains them.