Configuring HTTPS with TLS certificates

    You can use either Certbot or to obtain certificates. Both tools support TLS certificates but if you want to enable Knative for automatic TLS certificate provisioning, you must install and configure the cert-manager tool:

    • Manually obtain and renew certificates: Both the Certbot and cert-manager tools can be used to manually obtain TLS certificates. In general, after you obtain a certificate, you must create a Kubernetes secret to use that certificate in your cluster. See the procedures later in this topic for details about manually obtaining and configuring certificates.

    • Enable Knative to automatically obtain and renew TLS certificates: You can also use cert-manager to configure Knative to automatically obtain new TLS certificates and renew existing ones. If you want to enable Knative to automatically provision TLS certificates, instead see the Enabling automatic TLS certificate provisioning topic.

    By default, the is used to demonstrate how to enable HTTPS connections, but you can configure Knative to use any certificate from a CA that supports the ACME protocol. However, you must use and configure your certificate issuer to use the DNS-01 challenge type.

    Warning

    Certificates issued by Let’s Encrypt are valid for only . Therefore, if you choose to manually obtain and configure your certificates, you must ensure that you renew each certificate before it expires.

    You must meet the following requirements to enable secure HTTPS connections:

    • Knative Serving must be installed. For details about installing the Serving component, see the .
    • You must configure your Knative cluster to use a custom domain.

    Warning

    Istio only supports a single certificate per Kubernetes cluster. To serve multiple domains using your Knative cluster, you must ensure that your new or existing certificate is signed for each of the domains that you want to serve.

    If you already have a signed certificate for your domain, see Manually adding a TLS certificate for details about configuring your Knative cluster.

    If you need a new TLS certificate, you can choose to use one of the following tools to obtain a certificate from Let’s Encrypt:

    • Setup Certbot to manually obtain Let’s Encrypt certificates
    • Setup cert-manager to either manually obtain a certificate, or to automatically provision certificates

    This page covers details for both options.

    For details about using other CA’s, see the tool’s reference documentation:

    Use the following steps to install Certbot and the use the tool to manually obtain a TLS certificate from Let’s Encrypt.

    1. Run the following command to use Certbot to request a certificate using DNS challenge during authorization:

    where specifies your domain. If you want to validate multiple domain’s, you can include multiple flags: -d MY.EXAMPLEDOMAIN.1 -d MY.EXAMPLEDOMAIN.2. For more information, see the reference.

    The Certbot tool walks you through the steps of validating that you own each domain that you specify by creating TXT records in those domains.

    Result: CertBot creates two files:

    • Certificate:fullchain.pem
    • Private key: privkey.pem

    What’s next:

    Add the certificate and private key to your Knative cluster by creating a Kubernetes secret.

    Using cert-manager to obtain Let’s Encrypt certificates

    You can install and use cert-manager to either manually obtain a certificate or to configure your Knative cluster for automatic certificate provisioning:

    • Manual certificates: Install cert-manager and then use the tool to manually obtain a certificate.

    To use cert-manager to manually obtain certificates:

    1. .

    2. Continue to the steps about manually adding a TLS certificate by creating and using a Kubernetes secret.

    3. Automatic certificates: Configure Knative to use cert-manager for automatically obtaining and renewing TLS certificate. The steps for installing and configuring cert-manager for this method are covered in full in the topic.

    If you have an existing certificate or have used one of the Certbot or cert-manager tool to manually obtain a new certificate, you can use the following steps to add that certificate to your Knative cluster.

    For instructions about enabling Knative for automatic certificate provisioning, see . Otherwise, follow the steps in the relevant tab to manually add a certificate:

    ContourIstio

    1. Create a Kubernetes secret to hold your TLS certificate, cert.pem, and the private key, key.pem, by running the command:

      1. kubectl create -n contour-external secret tls default-cert \
      2. --key key.pem \

      Note

      Take note of the namespace and secret name. You will need these in future steps.

    2. To use this certificate and private key in different namespaces, you must create a delegation. To do so, create a YAML file using the following template:

      1. apiVersion: projectcontour.io/v1
      2. kind: TLSCertificateDelegation
      3. metadata:
      4. name: default-delegation
      5. namespace: contour-external
      6. spec:
      7. delegations:
      8. - secretName: default-cert
      9. targetNamespaces:
      10. - "*"
    3. Apply the YAML file by running the command:

      Where <filename> is the name of the file you created in the previous step.

    4. Update the Knative Contour plugin to use the certificate as a fallback when autoTLS is disabled by running the command:

      1. -p '{"data":{"default-tls-secret":"contour-external/default-cert"}}'

    To manually add a TLS certificate to your Knative cluster, you create a Kubernetes secret and then configure the knative-ingress-gateway:

    1. Create a Kubernetes secret to hold your TLS certificate, cert.pem, and the private key, key.pem, by entering the following command:
    1. kubectl create --namespace istio-system secret tls tls-cert \
    2. --key key.pem \
    3. --cert cert.pem
    1. Configure Knative to use the new secret that you created for HTTPS connections:

    2. Run the following command to open the Knative shared gateway in edit mode:

    3. Update the gateway to include the following tls: section and configuration:

      1. tls:
      2. mode: SIMPLE
      3. credentialName: tls-cert

      Example:

      1. # An empty file will abort the edit. If an error occurs while saving this
      2. # file will be reopened with the relevant failures.
      3. apiVersion: networking.istio.io/v1alpha3
      4. kind: Gateway
      5. metadata:
      6. spec:
      7. selector:
      8. istio: ingressgateway
      9. servers:
      10. - hosts:
      11. - "*"
      12. port:
      13. name: http
      14. number: 80
      15. protocol: HTTP
      16. - hosts:
      17. - TLS_HOSTS
      18. port:
      19. name: https
      20. number: 443
      21. protocol: HTTPS
      22. tls:
      23. mode: SIMPLE
      24. credentialName: tls-cert

      In this example, represents the hosts of your TLS certificate. It can be a single host, multiple hosts, or a wildcard host. For detailed instructions, please refer Istio documentation

    After your changes are running on your Knative cluster, you can begin using the HTTPS protocol for secure access your deployed Knative services.