apiVersion:networking.istio.io/v1beta1kind:Gatewaymetadata:...# other skipped configuration...spec:selector:istio:ingressgatewayservers:-hosts:-'*'port:name:httpnumber:80protocol:HTTP
...# other skipped configuration...-hosts:-SERVICE_NAME.SERVICE_NAMESPACE.CUSTOM_DOMAINport:number:443name:https-SERVICE_NAMEprotocol:HTTPStls:mode:SIMPLEcredentialName:SECRET_NAME
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
設定個別服務:
這個範例說明如何個別設定所有三項提供網際網路流量的服務:
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
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-04 (世界標準時間)。"],[],[],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"]]