Service Mesh (ASM) ingress gateways support dynamic certificate loading through Istio's Secret Discovery Service (SDS). You can dynamically configure private keys, server certificates, and root certificates without restarting the gateway or mounting secret volumes. A single gateway can serve multiple certificates for different hosts, so you can manage HTTPS across all your domains from one entry point.
How it works
When you create a Kubernetes secret containing a TLS certificate and private key, the ingress gateway detects it and loads the certificate automatically. The gateway watches for secrets in the same namespace as the ingress gateway and dynamically loads them through the credentialName field in the Gateway resource.
Zero-downtime certificate updates -- Add, replace, or remove certificates without restarting the ingress gateway.
No volume mounts required -- The gateway reads certificates directly from Kubernetes secrets.
Multi-host support -- Create separate secrets for each domain and reference them in a single Gateway resource.
Prerequisites
An application is deployed in the cluster added to the ASM instance
openssl is installed on your local machine (for generating self-signed certificates)
kubectl is configured to connect to the cluster where the ingress gateway pod runs
Step 1: Generate TLS certificates
A domain name must have an Internet Content Provider (ICP) filing before it can serve traffic in China.
Create a self-signed certificate and private key for the aliyun.com domain. If you already have a certificate and private key for this domain, rename them to aliyun.com.crt and aliyun.com.key, then skip to Step 2.
Generate a root certificate and private key:
openssl req -x509 -sha256 -nodes -days 365 -newkey rsa:2048 \ -subj '/O=myexample Inc./CN=aliyun.com' \ -keyout aliyun.root.key -out aliyun.root.crtGenerate a server certificate and private key signed by the root certificate:
openssl req -out aliyun.com.csr -newkey rsa:2048 -nodes \ -keyout aliyun.com.key -subj "/CN=aliyun.com/O=myexample organization" openssl x509 -req -days 365 -CA aliyun.root.crt -CAkey aliyun.root.key \ -set_serial 0 -in aliyun.com.csr -out aliyun.com.crt
Step 2: Store the certificate
Choose one of the following methods based on your ASM instance version.
ASM versions earlier than 1.17
Use kubectl to create a TLS secret in the istio-system namespace:
kubectl create -n istio-system secret tls myexample-credential \
--key=aliyun.com.key --cert=aliyun.com.crtThe secret name must not start with istio or prometheus, and must not contain the token field.
ASM 1.17 or later (recommended)
Use the ASM console to upload the certificate:
Log on to the ASM console. In the left-side navigation pane, choose Service Mesh > Mesh Management.
On the Mesh Management page, click the name of your ASM instance. In the left-side navigation pane, choose ASM Gateways > Certificate Management.
Click Create. In the Certificate Information panel, configure the following parameters and click OK.
Parameter Description Name Enter myexample-credential.Public Key Certificate Paste the contents of aliyun.com.crtgenerated in Step 1.Private Key Paste the contents of aliyun.com.keygenerated in Step 1.
Step 3: Deploy sample backend services
This step deploys two sample services behind the ingress gateway. If you already have backend services running in the cluster, skip to Step 4.
Service A: NGINX (for a.aliyun.com)
Create an NGINX configuration file named
myexample-nginx.conf:events { } http { log_format main '$remote_addr - $remote_user [$time_local] $status ' '"$request" $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; error_log /var/log/nginx/error.log; server { listen 80; location /hello { return 200 'Welcome to a.aliyun.com!'; add_header Content-Type text/plain; } } }Create a ConfigMap from the configuration file:
kubectl create configmap myexample-nginx-configmap \ --from-file=nginx.conf=./myexample-nginx.confEnable automatic sidecar proxy injection for the
defaultnamespace.Create a file named
myexampleapp.yamlwith the following content, then deploy it:kubectl apply -f myexampleapp.yaml
Service B: HTTPBin (for b.aliyun.com)
Create a file named
httpbin.example.yamlwith the following content, then deploy it:kubectl apply -f httpbin.example.yaml
Step 4: Create a Gateway resource
Define an Istio Gateway that terminates TLS on port 443 using the certificate stored in myexample-credential. The wildcard host *.aliyun.com allows this single gateway to handle HTTPS traffic for all subdomains.
Log on to the ASM console. In the left-side navigation pane, choose Service Mesh > Mesh Management.
On the Mesh Management page, click the name of your ASM instance. In the left-side navigation pane, choose ASM Gateways > Gateway. Click Create from YAML.
Select the default namespace, paste the following YAML, and click Create:
The gateway appears on the Gateway page after creation.
Step 5: Create virtual services
Create VirtualService resources to route traffic from the gateway to backend services.
Log on to the ASM console. In the left-side navigation pane, choose Service Mesh > Mesh Management.
On the Mesh Management page, click the name of your ASM instance. In the left-side navigation pane, choose Traffic Management Center > VirtualService. Click Create from YAML.
Create a VirtualService for
a.aliyun.com:Create another VirtualService for
b.aliyun.com:
Both virtual services appear on the VirtualService page after creation.
Step 6: Verify the setup
Get the ingress gateway IP address
Retrieve the IP address using one of the following methods:
ASM console: Log on to the ASM console, navigate to the ASM instance, then choose ASM Gateways > Ingress Gateway to find the IP address.
ACK console: View the ingress gateway in the ACK console. For details, see the "View the ingress gateway in the ACK console" section of Create an ingress gateway.
Store the IP address in an environment variable so you can reuse it in the verification commands:
export INGRESS_HOST=<ingress-gateway-ip>Replace <ingress-gateway-ip> with the actual IP address of your ingress gateway.
Test HTTPS access
Send a request to a.aliyun.com:
curl -k -HHost:a.aliyun.com \
--resolve "a.aliyun.com:443:${INGRESS_HOST}" \
https://a.aliyun.com/helloExpected output:
Welcome to aliyun.com!Send a request to b.aliyun.com:
curl -k -HHost:b.aliyun.com \
--resolve "b.aliyun.com:443:${INGRESS_HOST}" \
https://b.aliyun.com/status/418Expected output:
-=[ teapot ]=-
_...._
.' _ _ `.
| ."` ^ `". _,
\_;`"---"`|//
| ;/
\_ _/
`"""`Update a gateway certificate
To rotate or replace a certificate, create a new secret and update the credentialName in the Gateway resource. The ingress gateway picks up the new certificate automatically -- no restart required.
The following example replaces the certificate with a new one for example.com.
Create a new certificate
Generate a root certificate and private key:
openssl req -x509 -sha256 -nodes -days 365 -newkey rsa:2048 \ -subj '/O=myexample Inc./CN=example.com' \ -keyout example.root.key -out example.root.crtGenerate a server certificate and private key:
openssl req -out example.com.csr -newkey rsa:2048 -nodes \ -keyout example.com.key -subj "/CN=example.com/O=myexample organization" openssl x509 -req -days 365 -CA example.root.crt -CAkey example.root.key \ -set_serial 0 -in example.com.csr -out example.com.crtObtain the kubeconfig file and connect kubectl to the cluster.
Create a new secret:
kubectl create -n istio-system secret tls new-istio-ingressgateway-certs \ --key example.com.key --cert example.com.crtDelete the old secret:
kubectl delete secret istio-ingressgateway-certs -n istio-system
Update the Gateway resource
Log on to the ASM console. In the left-side navigation pane, choose Service Mesh > Mesh Management.
On the Mesh Management page, click the name of your ASM instance. In the left-side navigation pane, choose ASM Gateways > Gateway.
Find the target gateway and click YAML in the Actions column.
In the Edit dialog box, change
credentialNametonew-istio-ingressgateway-certsand click OK.
Verify the certificate update
Dump the ingress gateway configuration: Replace
<ingress-gateway-pod>with the actual pod name (for example,istio-ingressgateway-xxxx).kubectl exec <ingress-gateway-pod> -n istio-system -- \ curl localhost:15000/config_dump > ingressgateway_dump.yamlSearch for the new certificate name in the dump:
grep new-istio-ingressgateway-certs -A 3 ingressgateway_dump.yamlCopy the value of the
inline_bytesfield from the output. This is the Base64-encoded certificate.Decode the certificate and save it to a file: Replace
<base64-encoded-certificate>with the actual value from the previous step.echo <base64-encoded-certificate> | base64 --decode > test.com.crtVerify the certificate issuer: If the
Organizationfield showsmyexample, the certificate update was successful.openssl x509 -in test.com.crt -text -noout