Manage SSL certificates for an HTTPS listener
This topic describes how to manage SSL certificates for an HTTPS listener, focusing on replacing certificates that are expired or expiring soon.
Prerequisites
The ALB Ingress Controller component is installed. For more information, see Install the ALB Ingress Controller.
SSL certificate management scenarios
Terms
Default certificate: A listener has only one default certificate, which can be replaced but not added or deleted.
Extension certificates: You can add multiple extension certificates to each listener and delete them. For the specific certificate quota, see Quotas and limits.
Listener certificate list: The list of certificates for a listener, viewable in the Application Load Balancer (ALB) console.
New certificate: A certificate that is not in the listener's certificate list.
Manage SSL certificates
Starting from ALB Ingress Controller v2.18.0-aliyun.1, you can specify the default certificate by using the defaultCertificate field in an AlbConfig. For more information, see ALB Ingress Controller release notes.Management scenario | Auto-discovered certificate | Secret certificate | Certificate in AlbConfig |
Set a new certificate as the default certificate | Method 1 (Recommended) | Method 1 (Recommended) | Use the |
Method 2 Log on to the Application Load Balancer (ALB) console to replace the default certificate. | Method 2
| ||
Set an extension certificate as the default certificate | Method 1 (Recommended) | Method 1 (Recommended) | Method 1 (Recommended) |
Method 2
| Method 2
| Method 2
| |
Set a new certificate as an extension certificate | Manually trigger a reconciliation. | Update the Secret resource associated with the ingress. | The following two methods are supported:
|
For more information about auto-discovered certificates, Secret certificates, and certificates specified in an AlbConfig, see Configure an HTTPS certificate for encrypted communication.
Replace default certificate in the Console
Notes
To replace the default certificate with one not yet associated with the listener, first verify its availability in the Digital Certificate Management Service console. If the certificate does not exist, you can purchase or upload a new SSL certificate in the console. For more information, see Purchase a commercial certificate and Upload, synchronize, and share SSL certificates.
Use cases
The default certificate has expired and must be replaced.
You can replace an active default certificate with a new one even if it has not expired.
After you delete an extension certificate in the ALB console, set that certificate as the new default certificate.
Procedure
Log on to the Application Load Balancer (ALB) console. In the top navigation bar, select the region where the ALB instance is deployed.
On the Instances page, find the target instance and click the instance ID. On the instance details tab, disable Disable Configuration Read-only Mode.
ImportantAfter you disable configuration read-only mode, if you change listener configurations in the Application Load Balancer (ALB) console, only the default certificate configuration is written back to the ACK cluster during the next reconciliation. Configuration changes other than the default certificate configuration are not written back to the cluster. This means that during the next reconciliation, these changes risk being overwritten by the cluster's configuration. Therefore, perform other operations with caution. After the next reconciliation, you can run the
kubectl describe albconfig [$Albconfig_Name]command in the cluster and check thestatusfield to verify that the default certificate configuration was successfully written back.Click the Listener tab, click the ID of the target listener to go to the listener details page, and then click the Certificates tab.
On the Server Certificates tab, find the default server certificate for the listener. In the Actions column, click Replace.
In the dialog box that appears, select your new certificate and click OK.
After this operation is complete, the default certificate of the listener is updated to the new certificate.
If the original default certificate is still needed, click Add EV Certificate on the Server Certificates tab to add it as an extension certificate.
If you are sure that the original default certificate is no longer needed and is not referenced by other instances or listeners, on the Server Certificates tab, click Delete in the Actions column of the original default certificate. If not removed, the unexpired certificate becomes an extension certificate for the listener during the next reconciliation.
Enable configuration read-only mode.
Delete extension certificate in the Console
This operation involves deleting an extension certificate before you set it as the default certificate. This process usually takes a few seconds. During this time, forwarding rules for that domain may fail, temporarily disrupting services. Perform this operation with caution and only after confirming no service impact.
Notes
Before you delete an extension certificate, check the certificate list of the listener. If the current configuration of the default and extension certificates meets your requirements, you do not need to delete the extension certificate or replace the default certificate.
To avoid service disruption, first upload a temporary certificate for the same domain to the Digital Certificate Management Service console. Before deleting the original extension certificate, add this temporary certificate by clicking Add Extension Certificate on the Server Certificates tab. After you confirm that the status of the temporary certificate is Associated, remove the extension certificate. After you replace the default certificate, delete the temporary certificate.
Use cases
If the current default certificate has expired, you can first delete the extension certificate. Then, follow the steps in Replace the default certificate in the ALB console to set this certificate as the default certificate.
If the current default certificate has not expired but you decide to stop using it, you can delete the extension certificate. Then, follow the steps in Replace the default certificate in the ALB console to set this certificate as the default certificate. You can decide whether to add the original default certificate back as an extension certificate based on your business needs.
If the default certificate that is automatically selected by the ALB Ingress Controller during reconciliation is not what you expect, you can delete the extension certificate. Then, follow the steps in Replace the default certificate in the ALB console to set this certificate as the default certificate. You can then add the original default certificate back as an extension certificate.
Procedure
Log on to the Application Load Balancer (ALB) console. In the top navigation bar, select the region where the ALB instance is deployed.
On the Instances page, find the target instance and click the Instance ID. On the Instance Details tab, disable Configuration Read-only Mode.
ImportantAfter you disable configuration read-only mode, if you change listener configurations in the Application Load Balancer (ALB) console, only the changes that you make to the default certificate as described in Replace the default certificate in the ALB console are written back to the ACK cluster during the next reconciliation. Changes to configurations other than the certificate configuration are not written back to the cluster. This means that these changes are at risk of being overwritten by the cluster's configuration during the next reconciliation. Therefore, exercise caution when you perform other operations. After the next reconciliation, you can run the
kubectl describe albconfig [$Albconfig_Name]command in the cluster and check the content of thestatusfield to verify whether the certificate configuration was successfully written back.Click the Listener tab, click the ID of the target listener to go to the listener details page, and then click the Certificates tab.
On the Server Certificates tab, find the extension certificate that you want to delete. In the Actions column, click Delete, and then complete the operation as prompted.
Enable configuration read-only mode.
Set a new extension certificate
Extension certificates follow a priority matching logic. The default certificate does not participate in this priority matching.
Manually trigger a reconciliation
Use case
If you use the auto-discovery method to manage certificates, the ALB Ingress Controller does not immediately detect new SSL certificates that you purchase or upload in the Digital Certificate Management Service console. The ALB Ingress Controller queries for and obtains certificates from the Digital Certificate Management Service console only during a reconciliation. To apply a new certificate quickly, you must manually trigger a reconciliation.
The value of thespec.rules[].hostfield in the ingress configuration file must correspond to the domain names listed in thespec.tls[].hosts[]field. This ensures that each domain name is associated with the correct certificate.
Procedure
Obtain the KubeConfig of your cluster and use kubectl to connect to the cluster.
To trigger a reconciliation and update the certificate, you can modify the ALB ingress configuration. Select a configuration to modify from the ALB Ingress annotations based on your business needs.
If no specific configuration changes are needed, you can trigger a reconciliation by adding a non-critical annotation, such as
key_test: value_test, to the ingress YAML file, which triggers the ALB Ingress Controller to reconcile. The following code provides an example:apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: demo-https namespace: default annotations: key_test: value_test # Add a non-critical annotation to trigger reconciliation. spec: ingressClassName: alb rules: - host: demo.alb.ingress.top http: paths: - backend: service: name: demo-service-https port: number: 443 path: / pathType: Prefix tls: - hosts: - demo.alb.ingress.topUpdate the ingress.
kubectl apply -f demo.yamlVerify that the reconciliation was successful.
kubectl describe ingress demo-https -n default(Optional) Delete the non-critical annotation from the ingress YAML file and run the command in Step 3 to update the ingress.
Update the ingress Secret resource
Use cases
To update a Secret resource that is already in effect in the current ALB ingress, you can directly edit the YAML configuration file of the existing Secret resource and apply the updated file to the Kubernetes cluster. This action automatically triggers a reconciliation by the ALB Ingress Controller. For more information, see Configure an HTTPS certificate for encrypted communication.
If you need to add a new Secret certificate to an ALB Ingress, you first need to create a new Secret resource and then modify the configuration file of the ALB Ingress resource to add the name of the new Secret resource to the
secretNamefield for TLS.Obtain the KubeConfig of your cluster and use kubectl to connect to the cluster.
Create a new Secret resource. For more information, see Configure an HTTPS certificate for encrypted communication.
Add the newly created Secret resource to the configuration file of the ALB ingress resource.
In the Ingress YAML file, add the domain name and
secretNamecorresponding to the new Secret resource. The following is a code example.apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: demo-https namespace: default spec: ingressClassName: alb rules: - host: demo.alb.ingress.top http: paths: - backend: service: name: demo-service-https port: number: 443 path: / pathType: Prefix - host: newsecret.alb.ingress.top # The new domain corresponds to the new Secret resource. http: paths: - backend: service: name: demo-service-https port: number: 443 path: / pathType: Prefix tls: - hosts: - demo.alb.ingress.top secretName: secret-tls - hosts: - newsecret.alb.ingress.top # Add the domain corresponding to the new Secret resource. secretName: newsecret # Add the secretName corresponding to the new Secret resource.Update the ingress.
kubectl apply -f demo.yaml # Replace demo.yaml with your own YAML file.
Update the certificate ID with kubectl edit
Use case
If you use an AlbConfig to specify certificates, and you purchase or upload a new SSL certificate in the Digital Certificate Management Service console, or if the certificate ID changes after you modify an old certificate, update the AlbConfig as described in this section.
Procedure
Obtain the KubeConfig of your cluster and use kubectl to connect to the cluster.
Obtain the certificate ID.
Log on to the Digital Certificate Management Service console.
In the navigation pane on the left, choose .
On the SSL Certificate Management page, click the Uploaded Certificate tab. In the Actions column of the target certificate, click More. Then, obtain the Certificate ID from the certificate details panel.
You can perform incremental updates by using the
kubectl editcommand.View the AlbConfig name.
kubectl -n kube-system get AlbConfigUpdate the corresponding AlbConfig.
kubectl -n <NameSpace> edit AlbConfig <AlbConfig_Name>Update the YAML file with the obtained certificate ID.
#... spec: config: #... listeners: - caEnabled: false certificates: #... - CertificateId: 756****-cn-hangzhou # New certificate ID. IsDefault: false port: 443 protocol: HTTPS #...
Manually specify the default certificate in AlbConfig by using defaultCertificate
Notes
The IsDefault field: You can specify the default certificate only during creation, and the system will not automatically change it afterward unless necessary. To manually change the default certificate, use the
defaultCertificatefield.listeners: - port: 443 protocol: HTTPS certificates: - CertificateId: abcdefg-hangzhou IsDefault: truedefaultCertificate priority:
defaultCertificatetakes precedence overcertificates.IsDefault. This means that ifdefaultCertificateis configured,certificates.IsDefaultis automatically ignored.... ... listeners: - port: 443 protocol: HTTPS defaultCertificate: kind: CertIdentifier certificateId: 75****-hangzhou certificates: - CertificateId: 75****-hangzhou IsDefault: trueThe ALB Ingress Controller must be upgraded to v2.18.0-aliyun.1 or later. For more information, see Upgrade the ALB Ingress Controller.
Procedure
Obtain the cluster KubeConfig and connect to the cluster by using kubectl, then specify the default certificate in the defaultCertificate field by using a certificate ID or a Secret.
Starting from version v2.18.0-aliyun.1, the ALB Ingress Controller supports specifying a default certificate by using thedefaultCertificatefield. This field supports onlyCertIdentifierandSecretas values.
Use a certificate ID
When defaultCertificate.kind is set to CertIdentifier, you must specify the corresponding certificate ID (certificateId). The following provides an example:
apiVersion: alibabacloud.com/v1
kind: AlbConfig
metadata:
name: alb
spec:
config:
addressType: Intranet
name: alb-test
listeners:
- port: 80
protocol: HTTP
- port: 443
protocol: HTTPS
defaultCertificate:
kind: CertIdentifier
certificateId: 123****-cn-hangzhou ## Specify the target certificate ID.Use a Secret
When defaultCertificate.kind is set to Secret, you must specify the corresponding secretName and secretNamespace to use the Secret as the default certificate. The following is an example:
apiVersion: alibabacloud.com/v1
kind: AlbConfig
metadata:
name: alb
spec:
config:
addressType: Intranet
name: xiaosha-alb-test
listeners:
- port: 80
protocol: HTTP
- port: 443
protocol: HTTPS
defaultCertificate:
kind: Secret
secretName: test-secret ## Specify the target secretName.
secretNamespace: test ## Specify the target secretNamespace.Additional information
After you modify a certificate in the Digital Certificate Management Service console, such as after a certificate renewal, domain addition, or domain replacement, check whether the certificate ID has changed. If the certificate ID has changed, you need to trigger an update in the ALB ingress based on your chosen certificate management method.
If you use multiple certificate configuration methods simultaneously, consider their compatibility when updating certificates. For more information, see Compatibility of certificate management methods.
FAQ
Why do I receive the error "Specified parameter array contains too many items, up to 15 items, Certificates is not valid" during reconciliation?
Starting from v2.11.0-aliyun.1, the ALB Ingress Controller supports certificate paging. If you receive this error message during reconciliation, it indicates that your ALB Ingress Controller version does not support certificate paging, and you are trying to associate more than 15 certificates in a single reconciliation. To resolve this issue, upgrade the ALB Ingress Controller to the latest version. For more information about component versions, see ALB Ingress Controller. For more information about how to upgrade the component, see Manage the ALB Ingress Controller.
References
To learn how to configure a certificate for an HTTPS listener for the first time by using an ALB ingress, see Compatibility of certificate management methods.
To learn how to implement HTTPS mutual authentication by configuring an ALB ingress, see Use HTTPS mutual authentication to improve service security.
If you encounter errors or issues when you use an Application Load Balancer, see the following topics for troubleshooting: Troubleshoot ALB Ingress issues and ALB ingress FAQ.