排查 k8s 集群 master 节点无法正常工作的问题

搭建的是 k8s 高可用集群,用了 3 台 master 节点,2 台 master 节点宕机后,仅剩的 1 台无法正常工作。

运行 kubectl get nodes 命令出现下面的错误

The connection to the server k8s-api:6443 was refused - did you specify the right host or port?

注:k8s-api 对应的就是这台 master 服务器的本机 IP 地址。

运行 netstat -lntp 命令发现 kube-apiserver 根本没有运行,同时发现 etcd 与 kube-proxy 也没运行。

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.1:33807         0.0.0.0:*               LISTEN      602/kubelet         
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      572/rpcbind         
tcp        0      0 127.0.0.1:10257         0.0.0.0:*               LISTEN      3229/kube-controlle 
tcp        0      0 127.0.0.1:10259         0.0.0.0:*               LISTEN      3753/kube-scheduler 
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      571/systemd-resolve 
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1644/sshd           
tcp        0      0 127.0.0.1:10248         0.0.0.0:*               LISTEN      602/kubelet         
tcp6       0      0 :::111                  :::*                    LISTEN      572/rpcbind         
tcp6       0      0 :::10250                :::*                    LISTEN      602/kubelet         
tcp6       0      0 :::10251                :::*                    LISTEN      3753/kube-scheduler 
tcp6       0      0 :::10252                :::*                    LISTEN      3229/kube-controlle 

通过 docker ps 命令发现 etcd , kube-apiserver, kube-proxy 这 3 个容器都没有运行,etcd 容器在不停地启动->失败->重启->又失败......,查看容器日志发现下面的错误:

etcdserver: publish error: etcdserver: request timed out
rafthttp: health check for peer 611e58a32a3e3ebe could not connect: dial tcp 10.0.1.252:2380: i/o timeout (prober "ROUND_TRIPPER_SNAPSHOT")
rafthttp: health check for peer 611e58a32a3e3ebe could not connect: dial tcp 10.0.1.252:2380: i/o timeout (prober "ROUND_TRIPPER_RAFT_MESSAGE")
rafthttp: health check for peer cc00b4912b6442df could not connect: dial tcp 10.0.1.82:2380: i/o timeout (prober "ROUND_TRIPPER_SNAPSHOT")
rafthttp: health check for peer cc00b4912b6442df could not connect: dial tcp 10.0.1.82:2380: i/o timeout (prober "ROUND_TRIPPER_RAFT_MESSAGE")
raft: 12637f5ec2bd02b8 is starting a new election at term 254669

etcd 启动失败是由于 etcd 在 3 节点集群模式在启动却无法连接另外 2 台 master 节点的 etcd ,要解决这个问题需要改为单节点集群模式。开始不知道如何将 etcd 改为单节点模式,后来在网上找到 2 个参数 --initial-cluster-state=new--force-new-cluster ,在 /etc/kubernetes/manifests/etcd.yaml 中给 etcd 命令加上这 2 个参数,并重启服务器后,master 节点就能正常运行了。

  containers:
  - command:
    - etcd
    - --advertise-client-urls=https://10.0.1.81:2379
    - --cert-file=/etc/kubernetes/pki/etcd/server.crt
    - --client-cert-auth=true
    - --data-dir=/var/lib/etcd
    - --initial-advertise-peer-urls=https://10.0.1.81:2380
    - --initial-cluster=k8s-master0=https://10.0.1.81:2380
    - --initial-cluster-state=new
    ......

master 正常运行后,需要去掉刚刚添加的这 2 个 etcd 参数。

猜你喜欢

转载自www.cnblogs.com/dudu/p/12161010.html