The connection to the server 127.0.0.1:6443 was refused – did you specify the right host or port? 报错

  • Post author:
  • Post category:其他


The connection to the server 127.0.0.1:6443 was refused – did you specify the right host or port? 报错解决

在部署K3S集群的过程中,部署完之后server端能够查看到在集群内的所有节点,如下图

在agent端查看的时候,却画风一变,提示端口或者主机错误,如下图

root@gpu-2-3:/home/sutpc# kubectl get nodes
E0725 17:10:48.642284    3433 memcache.go:265] couldn't get current server API group list: Get "https://127.0.0.1:6443/api?timeout=32s": dial tcp 127.0.0.1:6443: connect: connection refused
E0725 17:10:48.645636    3433 memcache.go:265] couldn't get current server API group list: Get "https://127.0.0.1:6443/api?timeout=32s": dial tcp 127.0.0.1:6443: connect: connection refused
E0725 17:10:48.646647    3433 memcache.go:265] couldn't get current server API group list: Get "https://127.0.0.1:6443/api?timeout=32s": dial tcp 127.0.0.1:6443: connect: connection refused
E0725 17:10:48.647742    3433 memcache.go:265] couldn't get current server API group list: Get "https://127.0.0.1:6443/api?timeout=32s": dial tcp 127.0.0.1:6443: connect: connection refused
E0725 17:10:48.648968    3433 memcache.go:265] couldn't get current server API group list: Get "https://127.0.0.1:6443/api?timeout=32s": dial tcp 127.0.0.1:6443: connect: connection refused
The connection to the server 127.0.0.1:6443 was refused - did you specify the right host or port?

这个错误的原因就是去打开的时候提示:是从127.0.0.1:6443(这个地址并没有我们需要的K3S集群)的地址打开,但是实际上我们是需要从server端去打开,所以需要配置一下相关的地址,方法如下:


1、将server端路径/etc/rancher/k3s中的k3s.yaml文件拷贝到agent端对应的目录中,若是没有相关的目录则新建


2、将配置文件的路径写入到/etc/profile文件中,保证永久生效

#将k3s.yaml所在的文件路径写入到配置文件/etc/profile
root@gpu-2-3:/etc/rancher/k3s# echo "export KUBECONFIG=/etc/rancher/k3s/k3s.yaml" >> /etc/profile

#更新配置文件
root@gpu-2-3:/etc/rancher/k3s# source /etc/profile


3、修改客户端的配置文件,给客户端指定服务器,截图如下

#打开配置文件
root@gpu-2-3:/home/sutpc# vi /etc/rancher/k3s/k3s.yaml


#配置文件的内容
apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUJkekNDQVIyZ0F3SUJBZ0lCQURBS0JnZ3Foa2pPUFFRREFqQWpNU0V3SHdZRFZRUUREQmhyTTNNdGMyVnkKZG1WeUxXTmhRREUyT1RBeU5qWTVNamt3SGhjTk1qTXdOekkxTURZek5USTVXaGNOTXpNd056SXlNRFl6TlRJNQpXakFqTVNFd0h3WURWUVFEREJock0zTXRjMlZ5ZG1WeUxXTmhRREUyT1RBeU5qWTVNamt3V1RBVEJnY3Foa2pPClBRSUJCZ2dxaGtqT1BRTUJCd05DQUFTb3U4aFhtTGxPUU1nMmRvUERwZ0xzOFcxbWttOUNUbXRnSHk2T2pZemgKSktVbHd6Z3UwaWNwaXE0WFdWTjNKTEdXUngrenN2RVdxb0VlY1JLeUE5OXJvMEl3UURBT0JnTlZIUThCQWY4RQpCQU1DQXFRd0R3WURWUjBUQVFIL0JBVXdBd0VCL3pBZEJnTlZIUTRFRmdRVW0rbFo5K2NEZVF6ZUdLTDNPSG9RCndxU3AwNlF3Q2dZSUtvWkl6ajBFQXdJRFNBQXdSUUlnY0dMenMyZjl1SGV3R0dQWU1yRllMTkxLall3Z0FuaGMKYjBEazBYYU5CT0FDSVFDUHNCM1c1NzR1STNwVDJXcVdkcldrTGlMLytnMW5paVVwRzBiaHY5UGttZz09Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K
    server: https://10.10.46.250:6443  #指定服务的地址
    #server: https://127.0.0.1:6443
  name: default
contexts:
- context:
    cluster: default
    user: default
  name: default
current-context: default
kind: Config
preferences: {}
users:
- name: default
  user:
    client-certificate-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUJrVENDQVRlZ0F3SUJBZ0lJSkFLYmx0YTVZRFV3Q2dZSUtvWkl6ajBFQXdJd0l6RWhNQjhHQTFVRUF3d1kKYXpOekxXTn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bFpwM1hDcmNmM0V4QnlmNnNlT2pZSjRYVGR1d0RXVzkvbU9vMEl3UURBT0JnTlZIUThCQWY4RQpCQU1DQXFRd0R3WURWUjBUQVFIL0JBVXdBd0VCL3pBZEJnTlZIUTRFRmdRVU5iQUFVRzVBbTZvRWlzai9OZXY3CjFiRXZQTGN3Q2dZSUtvWkl6ajBFQXdJRFNBQXdSUUlnQkQrOFRBcEU3Q094akhIRWZ4Qy9QVUIxS1BqUmxOU3IKSkZ5ekx0eG5VOUFDSVFDNkZWdkUvMzJCazFLeDN2MVcrclZtWVlTOUw1cFNvQk5xQXYyekVSQW5FQT09Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K
    client-key-data: LS0tLS1CRUdJTiBFQyBQUklWQVRFIEtFWS0tLS0tCk1IY0NBUUVFSUlpSkFuVVJmS3Ayenk1Z3BUc0dNQS9QOGpuYlZaUHFud05SbG5qTmdmOVdvQW9HQ0NxR1NNNDkKQXdFSG9VUURRZ0FFUFpOa1Q0TWV1STh1aTY2VzZLeFRuT052ZC9oUjZQZjN4TVBYZ0RQem45TnI0SW5YYXpDago1NXh4NmxvQmMvaTJwbWF4ODZOejhFcEt2QkhBemVKMU1BPT0KLS0tLS1FTkQgRUMgUFJJVkFURSBLRVktLS0tLQo=
~
~


4、再次查看集群kubectl get nodes



版权声明:本文为GNNUXXL原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。