To ensure business continuity and security and mitigate potential risks caused by certificate leakage or key cracking, we recommend that you renew etcd certificates for the master nodes in a dedicated cluster when you receive system notifications. This topic describes how to renew etcd certificates for the master nodes in a Container Service for Kubernetes (ACK) dedicated cluster.
Background information
You can migrate workloads from an ACK dedicated cluster to an ACK Pro cluster. ACK can automatically manage the certificates of the etcd component and the Kubernetes control plane components in an ACK Pro cluster. You do not need to manually renew etcd certificates for ACK Pro clusters. For more information, see Hot migration from ACK dedicated clusters to ACK Pro clusters.
Usage notes
You are notified by internal message and text message two months before etcd certificates expire, and Renew Etcd Certificate is displayed on the Clusters page in the Container Service for Kubernetes (ACK) console.
During the renewal process, control plane components, such as the API server, etcd, kube-controller-manager, and kubelet, are restarted on master nodes one by one. Persistent connections to the API server are interrupted. We recommend that you renew etcd certificates during off-peak hours. The renewal process takes about 30 minutes.
If you have modified directory of the etcd certificates in an ACK dedicated cluster or the default configuration file directory of Kubernetes, you must create a soft link to the original directory before you renew the etcd certificates. Otherwise, the renewal fails.
If you manually renew etcd certificates, and Renew Etcd Certificate is still displayed in the console, submit a ticket to cancel the reminder.
If you fail to renew etcd certificates, submit a ticket.
Scenario 1: Renew etcd certificates that are about to expire
When etcd certificates in a cluster are about to expire, you can renew the certificates in the following ways:
Use the ACK console to renew etcd certificates
Log on to the ACK console. In the left-side navigation pane, click Clusters.
Click Renew Etcd Certificate to the right of the cluster whose etcd certificates are about to expire. In the Update Certificate message, click Update Certificate.
NoteIf the etcd certificates of a cluster are about to expire after two months, Renew Etcd Certificate is displayed on the right side of the cluster.
In the Note message, click OK.
After the certificates are renewed:
The certificate has been updated is displayed in the Update Certificate message.
On the Clusters page, Renew Etcd Certificate on the right side of the cluster disappears.
Manually renew etcd certificates
Scenarios
The etcd certificates in an ACK dedicated cluster are about to expire.
The etcd certificates cannot be renewed by deploying a new template.
The etcd certificates cannot be renewed in the ACK console.
In the preceding scenarios, you can log on to a master node in the ACK dedicated cluster and perform the following steps to renew the etcd certificates:
The script in the following section must be run by using the root user.
Make sure that password-free logon between master nodes is configured for the root user.
Use SSH to log on to a master node from another master node. If the system prompts you to enter a password, perform the following steps to configure password-free logon between master nodes:
# 1. Generate a key. Skip this step if a key exists on your node. ssh-keygen -t rsa # 2. Use ssh-copy-id to copy the public key to all other master nodes. Replace $(internal-ip) with the private IP address of each master node. ssh-copy-id -i ~/.ssh/id_rsa.pub $(internal-ip)
NoteIf you do not configure password-free logon between master nodes, the system prompts you to enter the password of the root user when you run the script.
Use the following template to create a file named restart-apiserver.sh and a file named rotate-etcd.sh, and save the files in the same directory.
NoteThe rotate-etcd.sh script obtains region information by accessing the metadata service of the node, and it pulls renewed images from the region. You can also specify the region information by entering the
--region xxxx
parameter when executing the script.Run the
bash rotate-etcd.sh
command on a master node.If
etcd CA and certs have succesfully rotated!
is returned, the etcd certificates and cluster certificates on all master nodes of the cluster are renewed.Check whether the etcd certificates are renewed.
cd /var/lib/etcd/cert for i in `ls | grep pem| grep -v key`;do openssl x509 -noout -text -in $i | grep -i after && echo "$i" ;done cd /etc/kubernetes/pki/etcd for i in `ls | grep pem| grep -v key`;do openssl x509 -noout -text -in $i | grep -i after && echo "$i" ;done cd /etc/kubernetes/pki/ for i in `ls | grep crt| grep -v key`;do openssl x509 -noout -text -in $i | grep -i after && echo "$i" ;done
NoteIf the expiration time displayed in the preceding script output is 50 years later, the renewal is completed.
After you manually renew the etcd certificates, the control plane of the cluster cannot retrieve the renewal results. Therefore, the update button remains displayed next to the cluster in the cluster list. To remove this button, submit a ticket.
Scenario 2: Renew expired etcd certificates
Scenarios
The etcd certificates are expired.
Renew etcd certificates when you cannot access the API server of your cluster.
The etcd certificates cannot be renewed by deploying a new template.
The etcd certificates cannot be renewed in the ACK console.
In the preceding scenarios, you can log on to a master node in the ACK dedicated cluster and perform the following steps to renew the etcd certificates:
The script in the following section must be run by using the root user.
Make sure that password-free logon between master nodes is configured for the root user.
Use SSH to log on to a master node from another master node. If the system prompts you to enter a password, perform the following steps to configure password-free logon between master nodes:
# 1. Generate a key. Skip this step if a key exists on your node. ssh-keygen -t rsa # 2. Use ssh-copy-id to copy the public key to all other master nodes. Replace $(internal-ip) with the private IP address of each master node. ssh-copy-id -i ~/.ssh/id_rsa.pub $(internal-ip)
NoteIf you do not configure password-free logon between master nodes, the system prompts you to enter the password of the root user when you run the script.
Use the following template to create a file named restart-apiserver.sh and a file named rotate-etcd.sh, and save the files in the same directory.
NoteThe rotate-etcd.sh script obtains region information by accessing the metadata service of the node, and it pulls renewed images from the region. You can also specify the region information by entering the
--region xxxx
parameter when executing the script.
Check whether the etcd certificates are renewed.
cd /var/lib/etcd/cert
for i in `ls | grep pem| grep -v key`;do openssl x509 -noout -text -in $i | grep -i after && echo "$i" ;done
cd /etc/kubernetes/pki/etcd
for i in `ls | grep pem| grep -v key`;do openssl x509 -noout -text -in $i | grep -i after && echo "$i" ;done
cd /etc/kubernetes/pki/
for i in `ls | grep crt| grep -v key`;do openssl x509 -noout -text -in $i | grep -i after && echo "$i" ;done
If the expiration time displayed in the preceding script output is 50 years later, the renewal is completed.
After you manually renew the etcd certificates, the control plane of the cluster cannot retrieve the renewal results. Therefore, the update button remains displayed next to the cluster in the cluster list. To remove this button, submit a ticket.
Roll back when you fail to renew etcd certificates
Scenarios
Restore the ACK cluster when you fail to renew etcd certificates by using the ACK console.
Restore the ACK cluster when you fail to renew etcd certificates by using the CLI.
In the preceding scenarios, the cluster administrator can log on to a master node, and manually renew etcd certificates by using the following script. The original certificates are about to expire. Therefore, this operation generates new etcd certificates and renew the etcd server certificate and the kube-apiserver client certificate.
The script in the following section must be run by using the root user.
Make sure that password-free logon between master nodes is configured for the root user.
Use SSH to log on to a master node from another master node. If the system prompts you to enter a password, perform the following steps to configure password-free logon between master nodes:
# 1. Generate a key. Skip this step if a key exists on your node. ssh-keygen -t rsa # 2. Use ssh-copy-id to copy the public key to all other master nodes. Replace $(internal-ip) with the private IP address of each master node. ssh-copy-id -i ~/.ssh/id_rsa.pub $(internal-ip)
NoteIf you do not configure password-free logon between master nodes, the system prompts you to enter the password of the root user when you run the script.
Use the following template to create a file named restart-apiserver.sh and a file named rollback-etcd.sh, and save the files in the same directory.
NoteThe rollback-etcd.sh script obtains region information by accessing the metadata service of the node, and it pulls renewed images from the region. You can also specify the region information by entering the
--region xxxx
parameter when executing the script.Run the
bash rollback-etcd.sh
command on a master node.If
etcd CA and certs have successfully rotated!
is returned, the etcd certificates and cluster certificates on all master nodes of the cluster are renewed.Check whether the etcd certificates are renewed.
cd /var/lib/etcd/cert
for i in `ls | grep pem| grep -v key`;do openssl x509 -noout -text -in $i | grep -i after && echo "$i" ;done
cd /etc/kubernetes/pki/etcd
for i in `ls | grep pem| grep -v key`;do openssl x509 -noout -text -in $i | grep -i after && echo "$i" ;done
cd /etc/kubernetes/pki/
for i in `ls | grep crt| grep -v key`;do openssl x509 -noout -text -in $i | grep -i after && echo "$i" ;done
If the expiration time in the preceding script output is 50 years later, the renewal is completed.