Para usar seus próprios certificados, armazene os certificados TLS em um secret
do Kubernetes e configure o gateway de entrada do Cloud Service Mesh para usar esse
secret.
Antes de começar
Estas instruções presumem que você já tenha recebido seus certificados
TLS.
É necessário configurar cada um dos serviços do Knative serving
que usam
gateway de entrada
para veicular tráfego externo. Se esses serviços externos não estiverem
configurados para usar os certificados TLS, os serviços não poderão
verificar uma conexão HTTPS e, portanto, nunca atingir o estado ready.
Como armazenar certificados TLS em um secret do Kubernetes
Para armazenar os certificados em um Secret, siga estas etapas:
Abra um terminal e navegue até o diretório em que seus certificados TLS
estão localizados.
Use o seguinte comando para criar um secret que armazene seus certificados:
INGRESS_NAMESPACE pelo namespace do
serviço de entrada, istio-ingressgateway. Especifique o namespace
istio-system se tiver instalado o Cloud Service Mesh com a configuração padrão.
SECRET_NAME pelo nome que você quer usar para o
Secret do Kubernetes.
PRIVATE_KEY.pem pelo nome do arquivo que contém a chave privada do
certificado.
FULL_CHAIN.pem pelo nome do arquivo que contém seu
certificado público.
Agora é possível configurar o gateway de entrada para usar o secret que você acabou de criar
para o certificado TLS.
Como configurar o gateway de entrada para usar seus certificados
Modifique o gateway de entrada do Cloud Service Mesh para usar o secret que você criou
para seus certificados TLS:
Abra o YAML do gateway de entrada no modo de edição executando o seguinte comando:
Exemplo da configuração padrão do gateway de entrada:
apiVersion:networking.istio.io/v1beta1kind:Gatewaymetadata:...# other skipped configuration...spec:selector:istio:ingressgatewayservers:-hosts:-'*'port:name:httpnumber:80protocol:HTTP
Configure o gateway de entrada para usar o secret anexando os atributos hosts,
port e tls ao YAML atual.
Para configurar todos os serviços para usar a mesma chave secreta: anexe o seguinte
à sua configuração YAML e especifique "*" como o valor do
atributo hosts:
...# other skipped configuration...-hosts:-"*"port:name:httpsnumber:443protocol:HTTPStls:mode:SIMPLEcredentialName:SECRET_NAME
Substitua SECRET_NAME pelo nome do secret
que você criou.
Para configurar cada um dos serviços individualmente: anexe o seguinte
à sua configuração YAML e especifique os valores dos atributos
hosts usando o nome e o namespace do serviço:
Para cada serviço, é preciso especificar os valores dos atributos hosts, port
e tls:
...# other skipped configuration...-hosts:-SERVICE_NAME.SERVICE_NAMESPACE.CUSTOM_DOMAINport:number:443name:https-SERVICE_NAMEprotocol:HTTPStls:mode:SIMPLEcredentialName:SECRET_NAME
Substitua:
SERVICE_NAME pelo nome do Knative serving
. Cada serviço que usa o gateway de entrada para exibir o tráfego
externo precisa ser configurado individualmente.
SERVICE_NAMESPACE pelo nome do namespace
em que o serviço está sendo executado.
CUSTOM_DOMAIN pelo domínio personalizado para o qual você
configurou o serviço a ser usado.
SECRET_NAME pelo nome do secret que você quer
que o serviço use. Se você criou vários secrets para diferentes
conjuntos de certificados TLS, especifique o secret que cada serviço usa.
Agora é possível usar o protocolo HTTPS para acessar o Knative serving implantado
.
Exemplos
Configure todos os serviços:
Neste exemplo, demonstramos como configurar todos os serviços para usar o
secret TLSsecret:
apiVersion:networking.istio.io/v1alpha3kind:Gatewaymetadata:...# other skipped configuration...spec:selector:istio:ingressgatewayservers:-hosts:-"*"port:name:httpnumber:80protocol:HTTP-hosts:-"*"port:name:httpsnumber:443protocol:HTTPStls:mode:SIMPLEcredentialName:TLSsecret
Configure serviços individuais:
Este exemplo demonstra como configurar individualmente os três
serviços que veiculam o tráfego da Internet:
apiVersion:networking.istio.io/v1alpha3kind:Gatewaymetadata:...# other skipped configuration...spec:selector:istio:ingressgatewayservers:-hosts:-"*"port:name:httpnumber:80protocol:HTTP-hosts:-prodservice.prodnamespace.my-custom-domain.com
port:number:443name:https-prodserviceprotocol:HTTPStls:mode:SIMPLEcredentialName:TLSsecret-hosts:-experiment.namespace.my-custom-domain.com
port:number:443name:https-experimentprotocol:HTTPStls:mode:SIMPLEcredentialName:TLSsecret-hosts:-fallbackservice.anothernamespace.my-custom-domain.com
port:number:443name:https-fallbackserviceprotocol:HTTPStls:mode:SIMPLEcredentialName:anotherTLSsecret
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-09-01 UTC."],[],[],null,["# Using your own TLS certificates\n\nLearn how to configure Knative serving to use your own SSL/TLS certificates.\n\nAlternatively, you can use the\n[managed TLS certificates](/kubernetes-engine/enterprise/knative-serving/docs/managed-tls) feature, which\nautomatically creates and renews TLS certificates through\n[Let's Encrypt](https://letsencrypt.org/)\n\nTo use your own certificates, you store your TLS certificates in a Kubernetes\nSecret and then configure the ingress gateway of Cloud Service Mesh to use that\nsecret.\n\nBefore you begin\n----------------\n\n- These instructions assume that you have already obtained your TLS certificates.\n- You must configure a custom domain. For details, see [Mapping custom domains](/kubernetes-engine/enterprise/knative-serving/docs/mapping-custom-domains).\n- You are required to configure each of your Knative serving services that use the [ingress gateway](/kubernetes-engine/enterprise/knative-serving/docs/architecture-overview#components_in_the_default_installation) to serve external traffic. If these external facing services are not configured to use your TLS certificates, the services will not be able to verify an HTTPS connection and therefore, never achieve the `ready` state.\n\nStoring TLS certificates in a Kubernetes Secret\n-----------------------------------------------\n\nTo store the certificates into a Secret:\n\n1. Open a terminal and navigate to the directory where your TLS certificates\n are located.\n\n2. Use the following command to create a secret that stores your certificates:\n\n ```bash\n kubectl create --namespace INGRESS_NAMESPACE secret tls SECRET_NAME \\\n --key PRIVATE_KEY.pem \\\n --cert FULL_CHAIN.pem\n ```\n\n Replace:\n - \u003cvar translate=\"no\"\u003eINGRESS_NAMESPACE\u003c/var\u003e with the namespace of your ingress service, `istio-ingressgateway`. Specify the `istio-system` namespace if you installed Cloud Service Mesh using the default configuration.\n - \u003cvar translate=\"no\"\u003eSECRET_NAME\u003c/var\u003e with the name that you want use for your Kubernetes Secret.\n - \u003cvar translate=\"no\"\u003ePRIVATE_KEY.pem\u003c/var\u003e with the name of the file that holds your certificate private key.\n - \u003cvar translate=\"no\"\u003eFULL_CHAIN.pem\u003c/var\u003e with the name of the file that holds your public certificate.\n\nYou can now configure the ingress gateway to use the secret you just created\nfor your TLS certificate.\n\nConfiguring the ingress gateway to use your certificates\n--------------------------------------------------------\n\nModify the ingress gateway of Cloud Service Mesh to use the secret that you created\nfor your TLS certificates:\n\n1. Open the ingress gateway YAML in edit mode by running the following command:\n\n ```bash\n kubectl edit gateway knative-ingress-gateway --namespace knative-serving\n ```\n\n Example of the default ingress gateway configuration: \n\n apiVersion: networking.istio.io/v1beta1\n kind: Gateway\n metadata:\n ...\n # other skipped configuration\n ...\n spec:\n selector:\n istio: ingressgateway\n servers:\n - hosts:\n - '*'\n port:\n name: http\n number: 80\n protocol: HTTP\n\n2. Configure the ingress gateway to use your secret by appending the `hosts`,\n `port`, and `tls` attributes to the existing YAML.\n\n - **To configure all services to use the same secret** : Append the following\n to your YAML configuration and specify `\"*\"` as the `hosts` attribute\n value:\n\n ...\n # other skipped configuration\n ...\n - hosts:\n - \"*\"\n port:\n name: https\n number: 443\n protocol: HTTPS\n tls:\n mode: SIMPLE\n credentialName: \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003eSECRET_NAME\u003c/span\u003e\u003c/var\u003e\n\n Replace \u003cvar translate=\"no\"\u003eSECRET_NAME\u003c/var\u003e with the name of the secret\n that you created.\n\n [See example](#example_all).\n - **To individually configure each of your services** : Append the following\n to your YAML configuration and specify the values for the `hosts`\n attributes using the service's name and namespace:\n\n For each service, you specify values for the `hosts`, `port`, and `tls`\n attributes: \n\n ...\n # other skipped configuration\n ...\n - hosts:\n - \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003eSERVICE_NAME\u003c/span\u003e\u003c/var\u003e.\u003cvar translate=\"no\"\u003eSERVICE_NAMESPACE\u003c/var\u003e.\u003cvar translate=\"no\"\u003eCUSTOM_DOMAIN\u003c/var\u003e\n port:\n number: 443\n name: https-\u003cvar translate=\"no\"\u003eSERVICE_NAME\u003c/var\u003e\n protocol: HTTPS\n tls:\n mode: SIMPLE\n credentialName: \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003eSECRET_NAME\u003c/span\u003e\u003c/var\u003e\n\n Replace:\n - \u003cvar translate=\"no\"\u003eSERVICE_NAME\u003c/var\u003e with the name of the Knative serving service. Every service that uses the ingress gateway to serve external traffic must be individually configured.\n - \u003cvar translate=\"no\"\u003eSERVICE_NAMESPACE\u003c/var\u003e with the name of the namespace in which the service is running.\n - \u003cvar translate=\"no\"\u003eCUSTOM_DOMAIN\u003c/var\u003e with the custom domain for which you configured the service to use.\n - \u003cvar translate=\"no\"\u003eSECRET_NAME\u003c/var\u003e with the name of the secret that you want the service to use. If you created multiple secrets for different sets of TLS certificates, you can specify which secret each service uses.\n\n [See example](#example_individual).\n3. Save your changes.\n\nYou can now use the HTTPS protocol to access your deployed Knative serving\nservices.\n\nExamples\n--------\n\nConfigure all services:\n\n: This example demonstrates how to configure all services to use the\n `TLSsecret` secret:\n\n apiVersion: networking.istio.io/v1alpha3\n kind: Gateway\n metadata:\n ...\n # other skipped configuration\n ...\n spec:\n selector:\n istio: ingressgateway\n servers:\n - hosts:\n - \"*\"\n port:\n name: http\n number: 80\n protocol: HTTP\n - hosts:\n - \"*\"\n port:\n name: https\n number: 443\n protocol: HTTPS\n tls:\n mode: SIMPLE\n credentialName: TLSsecret\n\nConfigure individual services:\n\n: This example demonstrates how to individually configure all three of the\n services that are serving internet traffic:\n\n apiVersion: networking.istio.io/v1alpha3\n kind: Gateway\n metadata:\n ...\n # other skipped configuration\n ...\n spec:\n selector:\n istio: ingressgateway\n servers:\n - hosts:\n - \"*\"\n port:\n name: http\n number: 80\n protocol: HTTP\n - hosts:\n - prodservice.prodnamespace.my-custom-domain.com\n port:\n number: 443\n name: https-prodservice\n protocol: HTTPS\n tls:\n mode: SIMPLE\n credentialName: TLSsecret\n - hosts:\n - experiment.namespace.my-custom-domain.com\n port:\n number: 443\n name: https-experiment\n protocol: HTTPS\n tls:\n mode: SIMPLE\n credentialName: TLSsecret\n - hosts:\n - fallbackservice.anothernamespace.my-custom-domain.com\n port:\n number: 443\n name: https-fallbackservice\n protocol: HTTPS\n tls:\n mode: SIMPLE\n credentialName: anotherTLSsecret"]]