k8s集群添加master节点 certificate etcd/peer is invalid: x509: certificate is valid for xxx,localhost,not x

k8s集群初始化配置后添加第二个master节点提示

error execution phase control-plane-prepare/certs: error creating PKI assets: failed to write or validate certificate "etcd-peer": certificate etcd/peer is invalid: x509: certificate is valid for k8s-master01, localhost, not k8s-master02

[root@k8s-master02 pki]#   kubeadm join 192.168.66.199:16443 --token abcdef.0123456789abcdef     --discovery-token-ca-cert-hash sha256:e1ed0646db7a37d7c263e968aa9c0e9bf3e068ac7fe208ea64c6c066f40b2f13     --control-plane 
[preflight] Running pre-flight checks
[preflight] Reading configuration from the cluster...
[preflight] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -oyaml'
[preflight] Running pre-flight checks before initializing the new control plane instance
[preflight] Pulling images required for setting up a Kubernetes cluster
[preflight] This might take a minute or two, depending on the speed of your internet connection
[preflight] You can also perform this action in beforehand using 'kubeadm config images pull'
[certs] Using certificateDir folder "/etc/kubernetes/pki"
error execution phase control-plane-prepare/certs: error creating PKI assets: failed to write or validate certificate "etcd-peer": certificate etcd/peer is invalid: x509: certificate is valid for k8s-master01, localhost, not k8s-master02
To see the stack trace of this error execute with --v=5 or higher

解决办法:

将初始化的节点上/etc/kubernetes相关证书文件和配置文件copy到第二台master节点上

[root@k8s-master01 pki]# scp /etc/kubernetes/pki/sa.* 192.168.66.201:/etc/kubernetes/pki/
[root@k8s-master01 pki]# scp /etc/kubernetes/pki/front-proxy-ca* 192.168.66.201:/etc/kubernetes/pki/
[root@k8s-master01 pki]# scp /etc/kubernetes/pki/ca.* 192.168.66.201:/etc/kubernetes/pki/
[root@k8s-master01 pki]# scp /etc/kubernetes/pki/etcd/ca.* 192.168.66.201:/etc/kubernetes/pki/etcd/
[root@k8s-master01 pki]# scp /etc/kubernetes/admin.conf 192.168.66.201:/etc/kubernetes/

重新执行添加操作正常

[root@k8s-master02 kubernetes]#   kubeadm join 192.168.66.199:16443 --token abcdef.0123456789abcdef     --discovery-token-ca-cert-hash sha256:e1ed0646db7a37d7c263e968aa9c0e9bf3e068ac7fe208ea64c6c066f40b2f13     --control-plane 
[preflight] Running pre-flight checks
[preflight] Reading configuration from the cluster...
[preflight] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -oyaml'
[preflight] Running pre-flight checks before initializing the new control plane instance
[preflight] Pulling images required for setting up a Kubernetes cluster
[preflight] This might take a minute or two, depending on the speed of your internet connection
[preflight] You can also perform this action in beforehand using 'kubeadm config images pull'
[certs] Using certificateDir folder "/etc/kubernetes/pki"
[certs] Generating "front-proxy-client" certificate and key
[certs] Generating "etcd/server" certificate and key
[certs] etcd/server serving cert is signed for DNS names [k8s-master02 localhost] and IPs [192.168.66.201 127.0.0.1 ::1]
[certs] Generating "etcd/peer" certificate and key
[certs] etcd/peer serving cert is signed for DNS names [k8s-master02 localhost] and IPs [192.168.66.201 127.0.0.1 ::1]
[certs] Generating "etcd/healthcheck-client" certificate and key
[certs] Generating "apiserver-etcd-client" certificate and key
[certs] Generating "apiserver" certificate and key
[certs] apiserver serving cert is signed for DNS names [k8s-master02 kubernetes kubernetes.default kubernetes.default.svc kubernetes.default.svc.cluster.local] and IPs [10.96.0.1 192.168.66.201 192.168.66.199 192.168.66.200 192.168.66.201 192.168.66.199]
[certs] Generating "apiserver-kubelet-client" certificate and key
[certs] Valid certificates and keys now exist in "/etc/kubernetes/pki"
[certs] Using the existing "sa" key
[kubeconfig] Generating kubeconfig files
[kubeconfig] Using kubeconfig folder "/etc/kubernetes"
[endpoint] WARNING: port specified in controlPlaneEndpoint overrides bindPort in the controlplane address
[kubeconfig] Using existing kubeconfig file: "/etc/kubernetes/admin.conf"
[endpoint] WARNING: port specified in controlPlaneEndpoint overrides bindPort in the controlplane address
[kubeconfig] Writing "controller-manager.conf" kubeconfig file
[endpoint] WARNING: port specified in controlPlaneEndpoint overrides bindPort in the controlplane address
[kubeconfig] Writing "scheduler.conf" kubeconfig file
[control-plane] Using manifest folder "/etc/kubernetes/manifests"
[control-plane] Creating static Pod manifest for "kube-apiserver"
W0513 23:15:41.090932   86862 manifests.go:225] the default kube-apiserver authorization-mode is "Node,RBAC"; using "Node,RBAC"
[control-plane] Creating static Pod manifest for "kube-controller-manager"
W0513 23:15:41.104078   86862 manifests.go:225] the default kube-apiserver authorization-mode is "Node,RBAC"; using "Node,RBAC"
[control-plane] Creating static Pod manifest for "kube-scheduler"
W0513 23:15:41.105195   86862 manifests.go:225] the default kube-apiserver authorization-mode is "Node,RBAC"; using "Node,RBAC"
[check-etcd] Checking that the etcd cluster is healthy
[kubelet-start] Downloading configuration for the kubelet from the "kubelet-config-1.18" ConfigMap in the kube-system namespace
[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
[kubelet-start] Starting the kubelet
[kubelet-start] Waiting for the kubelet to perform the TLS Bootstrap...
[etcd] Announced new etcd member joining to the existing etcd cluster
[etcd] Creating static Pod manifest for "etcd"
[etcd] Waiting for the new etcd member to join the cluster. This can take up to 40s
{"level":"warn","ts":"2023-05-13T23:15:57.114+0800","caller":"clientv3/retry_interceptor.go:61","msg":"retrying of unary invoker failed","target":"passthrough:///https://192.168.66.201:2379","attempt":0,"error":"rpc error: code = DeadlineExceeded desc = context deadline exceeded"}
[upload-config] Storing the configuration used in ConfigMap "kubeadm-config" in the "kube-system" Namespace
[mark-control-plane] Marking the node k8s-master02 as control-plane by adding the label "node-role.kubernetes.io/master=''"
[mark-control-plane] Marking the node k8s-master02 as control-plane by adding the taints [node-role.kubernetes.io/master:NoSchedule]

This node has joined the cluster and a new control plane instance was created:

* Certificate signing request was sent to apiserver and approval was received.
* The Kubelet was informed of the new secure connection details.
* Control plane (master) label and taint were applied to the new node.
* The Kubernetes control plane instances scaled up.
* A new etcd member was added to the local/stacked etcd cluster.

To start administering your cluster from this node, you need to run the following as a regular user:

        mkdir -p $HOME/.kube
        sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
        sudo chown $(id -u):$(id -g) $HOME/.kube/config

Run 'kubectl get nodes' to see this node join the cluster.

[root@k8s-master02 kubernetes]# 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这个错误提示通常表示证书的颁发机构未被信任,可能是因为证书是自签名的或者是从未知的颁发机构获取的。这种情况下,您可以尝试以下几种方法来解决这个问题: 1. 忽略证书错误:如果您确定目标网站的证书是可信的,您可以在使用命令时添加 --no-check-certificate 参数来忽略证书错误。例如: ``` wget --no-check-certificate https://example.com ``` 或者在使用 curl 命令时添加 -k 参数: ``` curl -k https://example.com ``` 这种方法不太安全,因为它会使您的连接变得容易受到攻击。因此,我们建议您仅在必要时使用此方法。 2. 添加证书:如果您有目标网站的证书,可以将其添加到您的系统证书库中。具体步骤可能会因操作系统而异,但通常可以使用以下命令来完成: ``` sudo cp example.crt /usr/local/share/ca-certificates/ sudo update-ca-certificates ``` 这将把证书复制到 /usr/local/share/ca-certificates/ 目录下,并更新系统证书库。 3. 安装证书颁发机构:如果证书是由未知的颁发机构签署的,您可以尝试安装该颁发机构的根证书。具体步骤可能会因操作系统而异,但通常可以使用以下命令来完成: ``` sudo apt-get install ca-certificates sudo cp example.crt /usr/local/share/ca-certificates/ sudo update-ca-certificates ``` 这将安装 ca-certificates 包,并将证书复制到 /usr/local/share/ca-certificates/ 目录下,并更新系统证书库。 请注意,这些方法都只是解决证书错误的临时方法,如果您需要频繁访问目标网站,建议您与网站管理员联系,以获取正确的证书。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值