博客
关于我
Kubernetes 证书有效期更改
阅读量:634 次
发布时间:2019-03-14

本文共 2006 字,大约阅读时间需要 6 分钟。

Kubernetes 相关证书详细介绍

在更新 Kubernetes 集群证书之前,应优先查看当前证书的过期时间

查看证书过期时间命令

kubeadm alpha certs check-expiration

在查看证书过期时间之前,需要确保 Go 环境的正确部署

Go 环境部署步骤

  • 下载 Go 发布包
  • wget https://dl.google.com/go/go1.15.6.linux-amd64.tar.gz
    1. 解压 Go 发布包并添加到系统路径
    2. tar -zxvf go1.15.6.linux-amd64.tar.gz -C /usr/local
      1. 修改环境变量
      2. vim /etc/profile

        在文件末尾添加以下内容:

        export PATH=$PATH:/usr/local/go/bin
        1. 重新加载环境变量
        2. source /etc/profile

          下载 Kubernetes 源码

          cd /homegit clone https://github.com/kubernetes/kubernetes.git

          如果需要特定版本,可执行以下命令:

          git clone -b 1.15.1 --depth=1 https://github.com/kubernetes/kubernetes.git

          切换到指定版本

          git checkout -b remotes/origin/release-1.15.1 v1.15.1

          Kubeadm 源码包更新证书策略修改

        3. 向原始代码添加新的证书更新逻辑
        4. vim staging/src/k8s.io/client-go/util/cert/cert.go
          1. 修改 pkiutils 证书管理代码
          2. vim cmd/kubeadm/app/util/pkiutil/pki_helpers.go

            编译并测试修改后的代码

            make WHAT=cmd/kubeadm GOFLAGS=-v

            将编译后的 kubeadm 拷贝到目标路径

            cp _output/bin/kubeadm /root/kubeadm-new

            更新 kubeadm 命名

            cp /usr/bin/kubeadm /usr/bin/kubeadm.old
            cp /root/kubeadm-new /usr/bin/kubeadm
            chmod a+x /usr/bin/kubeadm

            将节点证书更新至所有 Master 节点

            cp -r /etc/kubernetes/pki /etc/kubernetes/pki.old
            cd /etc/kubernetes/pki
            kubeadm alpha certs renew all --config=/root/kubeadm-config.yaml

            验证证书更新

            openssl x509 -in apiserver.crt -text-noout | grep Not

            为 HA 集群其他 Master 节点进行证书更新

            #aleigharing,如果有多个Master节点需要更新,请根据实际IP配置相应脚本
            #!/bin/bashmasterNode="192.168.66.20 192.168.66.21"for host in ${masterNode}; do    scp /etc/kubernetes/pki/{ca.crt,ca.key,sa.key,sa.pub,front-proxy-ca.crt,front-proxy-ca.key}(${USER}@$host:/etc/kubernetes/pki/)    scp /etc/kubernetes/pki/etcd/{ca.crt,ca.key} "root"@$host:/etc/kubernetes/pki/etcd    scp /etc/kubernetes/admin.conf "root"@$host:/etc/kubernetes/donefor host in ${CONTROL_PLANE_IPS}; do    scp /etc/kubernetes/pki/{ca.crt,ca.key,sa.key,sa.pub,front-proxy-ca.crt,front-proxy-ca.key}(${USER}@$host:/root/pki/)    scp /etc/kubernetes/pki/etcd/{ca.crt,ca.key} "root"@$host:/root/etcd    scp /etc/kubernetes/admin.conf "root"@$host:/root/kubernetes/done

            完成后请再次查看证书过期时间

            kubeadm alpha certs check-expiration

    转载地址:http://txqoz.baihongyu.com/

    你可能感兴趣的文章
    npm install 卡着不动的解决方法
    查看>>
    npm install 报错 EEXIST File exists 的解决方法
    查看>>
    npm install 报错 ERR_SOCKET_TIMEOUT 的解决方法
    查看>>
    npm install 报错 fatal: unable to connect to github.com 的解决方法
    查看>>
    npm install 报错 no such file or directory 的解决方法
    查看>>
    npm install 权限问题
    查看>>
    npm install报错,证书验证失败unable to get local issuer certificate
    查看>>
    npm install无法生成node_modules的解决方法
    查看>>
    npm install的--save和--save-dev使用说明
    查看>>
    npm node pm2相关问题
    查看>>
    npm run build 失败Compiler server unexpectedly exited with code: null and signal: SIGBUS
    查看>>
    npm run build报Cannot find module错误的解决方法
    查看>>
    npm run build部署到云服务器中的Nginx(图文配置)
    查看>>
    npm run dev 报错PS ‘vite‘ 不是内部或外部命令,也不是可运行的程序或批处理文件。
    查看>>
    npm scripts 使用指南
    查看>>
    npm should be run outside of the node repl, in your normal shell
    查看>>
    npm start运行了什么
    查看>>
    npm WARN deprecated core-js@2.6.12 core-js@<3.3 is no longer maintained and not recommended for usa
    查看>>
    npm 下载依赖慢的解决方案(亲测有效)
    查看>>
    npm 安装依赖过程中报错:Error: Can‘t find Python executable “python“, you can set the PYTHON env variable
    查看>>