k8s证书升级文档
1.kubeadm安装的k8s证书升级
查看证书
1
| kubeadm alpha certs check-expiration
|
生成新的证书之前最好备份一下数据:
1 2
| cp -rp /etc/kubernetes /etc/kubernetes.bak cp -rp /var/lib/etcd /var/lib/etcd.bak
|
生成新的证书:
1
| kubeadm alpha certs renew all
|
再次查看证书
1
| kubeadm alpha certs check-expiration
|
2.二进制安装的k8s证书升级
本机版:
1.备份
1 2
| cp -r /root/TLS /root/TLS.bak
|
2.etcd证书升级
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| cd /root/TLS/etcd
openssl x509 -in ca.pem -noout -text |grep ' Not '
openssl x509 -in server.pem -noout -text |grep ' Not '
cfssl gencert -initca ca-csr.json | cfssljson -bare ca -
cfssl gencert -ca=ca.pem -ca-key=ca-key.pem -config=ca-config.json -profile=www server-csr.json | cfssljson -bare server
cat /usr/lib/systemd/system/etcd.service
cp ~/TLS/etcd/ca*pem ~/TLS/etcd/server*pem /opt/etcd/ssl/
scp -r /opt/etcd/ root@192.168.188.129:/opt/ scp -r /opt/etcd/ root@192.168.188.130:/opt/
systemctl daemon-reload systemctl start etcd
ETCDCTL_API=3 /opt/etcd/bin/etcdctl --cacert=/opt/etcd/ssl/ca.pem --cert=/opt/etcd/ssl/server.pem --key=/opt/etcd/ssl/server-key.pem --endpoints="https://192.168.188.128:2379,https://192.168.188.129:2379,https://192.168.188.130:2379" endpoint health
|
3.k8s证书升级
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| cd /root/TLS/k8s
cfssl gencert -initca ca-csr.json | cfssljson -bare ca - ls *pem
openssl x509 -in ca.pem -noout -text |grep ' Not '
cfssl gencert -ca=ca.pem -ca-key=ca-key.pem -config=ca-config.json -profile=kubernetes server-csr.json | cfssljson -bare server
cfssl gencert -ca=ca.pem -ca-key=ca-key.pem -config=ca-config.json -profile=kubernetes kube-proxy-csr.json | cfssljson -bare kube-proxy
openssl x509 -in server.pem -noout -text |grep ' Not ' openssl x509 -in kube-proxy.pem -noout -text |grep ' Not '
cp ~/TLS/k8s/ca*pem ~/TLS/k8s/server*pem /opt/kubernetes/ssl/
KUBE_APISERVER="https://192.168.188.128:6443" TOKEN="c47ffb939f5ca36231d9e3121a252940"
kubectl config set-cluster kubernetes \ --certificate-authority=/opt/kubernetes/ssl/ca.pem \ --embed-certs=true \ --server=${KUBE_APISERVER} \ --kubeconfig=bootstrap.kubeconfig kubectl config set-credentials "kubelet-bootstrap" \ --token=${TOKEN} \ --kubeconfig=bootstrap.kubeconfig kubectl config set-context default \ --cluster=kubernetes \ --user="kubelet-bootstrap" \ --kubeconfig=bootstrap.kubeconfig kubectl config use-context default --kubeconfig=bootstrap.kubeconfig
KUBE_APISERVER="https://192.168.188.128:6443"
kubectl config set-cluster kubernetes \ --certificate-authority=/opt/kubernetes/ssl/ca.pem \ --embed-certs=true \ --server=${KUBE_APISERVER} \ --kubeconfig=kube-proxy.kubeconfig kubectl config set-credentials kube-proxy \ --client-certificate=./kube-proxy.pem \ --client-key=./kube-proxy-key.pem \ --embed-certs=true \ --kubeconfig=kube-proxy.kubeconfig kubectl config set-context default \ --cluster=kubernetes \ --user=kube-proxy \ --kubeconfig=kube-proxy.kubeconfig kubectl config use-context default --kubeconfig=kube-proxy.kubeconfig
cp kube-proxy.kubeconfig /opt/kubernetes/cfg/
systemctl daemon-reload systemctl restart kube-apiserver systemctl restart kube-controller-manager systemctl restart kube-scheduler systemctl restart kubelet
|
生产版:
生产版和本机版就是证书位置,配置文件位置和本地版不一样,需要先查证书,配置文件的位置,所以生产版就写了查文件位置的命令。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| find / -name "*pem"
cd root/TLS cd etcd openssl x509 -in ca.pem -noout -text |grep ' Not '
cd /opt/master cd /opt/app/kubernetes/ssl
cd /usr/lib/systemd/system
etcd.service kube-apiserver.service kube-controller-manager.service kube-scheduler.service kubelet.service kube-proxy.service
|
4.回滚方案:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
| cp -r /root/TLS.bak /root/TLS
cp ~/TLS/etcd/ca*pem ~/TLS/etcd/server*pem /opt/etcd/ssl/
scp -r /opt/etcd/ root@192.168.188.129:/opt/ scp -r /opt/etcd/ root@192.168.188.130:/opt/
vi /opt/etcd/cfg/etcd.conf
ETCD_NAME="etcd-1" ETCD_DATA_DIR="/var/lib/etcd/default.etcd" ETCD_LISTEN_PEER_URLS="https://192.168.31.71:2380" ETCD_LISTEN_CLIENT_URLS="https://192.168.31.71:2379"
ETCD_INITIAL_ADVERTISE_PEER_URLS="https://192.168.31.71:2380" ETCD_ADVERTISE_CLIENT_URLS="https://192.168.31.71:2379" ETCD_INITIAL_CLUSTER="etcd-1=https://192.168.31.71:2380,etcd-2=https://192.168.31.72:2380,etcd-3=https://192.168.31.73:2380" ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster" ETCD_INITIAL_CLUSTER_STATE="new"
systemctl daemon-reload systemctl restart etcd
ETCDCTL_API=3 /opt/etcd/bin/etcdctl --cacert=/opt/etcd/ssl/ca.pem --cert=/opt/etcd/ssl/server.pem --key=/opt/etcd/ssl/server-key.pem --endpoints="https://192.168.188.128:2379,https://192.168.188.129:2379,https://192.168.188.130:2379" endpoint health kubectl get cs
cp ~/TLS/k8s/ca*pem ~/TLS/k8s/server*pem /opt/kubernetes/ssl/ systemctl daemon-reload systemctl restart kube-apiserver systemctl restart kube-controller-manager systemctl restart kube-scheduler
KUBE_APISERVER="https://192.168.188.128:6443" TOKEN="c47ffb939f5ca36231d9e3121a252940"
kubectl config set-cluster kubernetes \ --certificate-authority=/opt/kubernetes/ssl/ca.pem \ --embed-certs=true \ --server=${KUBE_APISERVER} \ --kubeconfig=bootstrap.kubeconfig kubectl config set-credentials "kubelet-bootstrap" \ --token=${TOKEN} \ --kubeconfig=bootstrap.kubeconfig kubectl config set-context default \ --cluster=kubernetes \ --user="kubelet-bootstrap" \ --kubeconfig=bootstrap.kubeconfig kubectl config use-context default --kubeconfig=bootstrap.kubeconfig cp bootstrap.kubeconfig /opt/kubernetes/cfg systemctl daemon-reload systemctl restart kubelet
KUBE_APISERVER="https://192.168.188.128:6443"
kubectl config set-cluster kubernetes \ --certificate-authority=/opt/kubernetes/ssl/ca.pem \ --embed-certs=true \ --server=${KUBE_APISERVER} \ --kubeconfig=kube-proxy.kubeconfig kubectl config set-credentials kube-proxy \ --client-certificate=./kube-proxy.pem \ --client-key=./kube-proxy-key.pem \ --embed-certs=true \ --kubeconfig=kube-proxy.kubeconfig kubectl config set-context default \ --cluster=kubernetes \ --user=kube-proxy \ --kubeconfig=kube-proxy.kubeconfig kubectl config use-context default --kubeconfig=kube-proxy.kubeconfig cp kube-proxy.kubeconfig /opt/kubernetes/cfg/ systemctl daemon-reload systemctl start kube-proxy systemctl enable kube-proxy
|