• kubectl get nodes报错:The connection to the server localhost:8080


    报错描述kubectl get nodes命令无法执行

    K8S-master初始化后,worker-node节点加入K8S集群后

    kubeadm join 192.168.31.150:6443 --token 2n0t62.gvuu8x3zui9o8xnc \
            --discovery-token-ca-cert-hash sha256:d294c082cc7e0d5f620fb10e527a8a7cb4cb6ccd8dc45ffaf2cddd9bd3016695
    
    • 1
    • 2

    通过kubectl get nodes查看集群的情况,出现了报错,内容如下:

    [root@k8s-master01 ~]# kubectl get nodes
    E1114 16:28:52.032089    2254 memcache.go:265] couldn't get current server API group list: Get "http://localhost:8080/api?timeout=32s": dial tcp [::1]:8080: connect: connection refused
    E1114 16:28:52.032313    2254 memcache.go:265] couldn't get current server API group list: Get "http://localhost:8080/api?timeout=32s": dial tcp [::1]:8080: connect: connection refused
    E1114 16:28:52.033599    2254 memcache.go:265] couldn't get current server API group list: Get "http://localhost:8080/api?timeout=32s": dial tcp [::1]:8080: connect: connection refused
    E1114 16:28:52.034881    2254 memcache.go:265] couldn't get current server API group list: Get "http://localhost:8080/api?timeout=32s": dial tcp [::1]:8080: connect: connection refused
    E1114 16:28:52.036130    2254 memcache.go:265] couldn't get current server API group list: Get "http://localhost:8080/api?timeout=32s": dial tcp [::1]:8080: connect: connection refused
    The connection to the server localhost:8080 was refused - did you specify the right host or port?
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    最初,查找在/etc/kubernetes目录下,存放了许多K8S配置文件,通过kubectl --kubeconfig命令执行正常,这样执行感觉很怪。
    在这里插入图片描述

    解决办法

    最终发现,答案其实就在k8s-worker-node节点生成的内容当中,只需要master执行以下命令就可以:
    在这里插入图片描述

    mkdir -p $HOME/.kube
    
    cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
    
    chown $(id -u):$(id -g) $HOME/.kube/config
    
    • 1
    • 2
    • 3
    • 4
    • 5

    mkdir -p $HOME/.kube ##创建一个名为 .kube 的目录,该目录用于存储 Kubernetes 相关的配置文件

    cp -i /etc/kubernetes/admin.conf $HOME/.kube/config##表示复制 Kubernetes 集群的管理员配置文件(通常是 /etc/kubernetes/admin.conf)到用户的 .kube 目录下的 config 文件。

    chown $(id -u):$(id -g) $HOME/.kube/config ##更改用户的 .kube/config 文件的所有者为当前用户(通过 ( i d − u ) 获取用户 I D , (id -u) 获取用户 ID, (idu)获取用户ID(id -g) 获取用户所属的主要组 ID)。

    再次执行该命令:kubectl get nodes
    在这里插入图片描述

  • 相关阅读:
    k-form-design 改成自己组件步骤
    Proxy 代理对象使用详解即原理总结
    springboot整合TDengine实现数据订阅——多线程快速消费
    创建型模式-原型模式
    Matlab基础一、关于初始化数组,数据矩阵,三维数据,字符串数组
    机器学习(五)逻辑回归
    Keras Sequential 模型
    Peter算法小课堂—球盒问题
    利用 Optimum Intel 和 fastRAG 在 CPU 上优化文本嵌入
    用字典统计序列中键和值的数量collections.Counter()
  • 原文地址:https://blog.csdn.net/qq_39689711/article/details/134402806