`kubectl get pods` 为什么突然失败?

huangapple go评论58阅读模式
英文:

Why does `kubectl get pods` suddenly fail?

问题

我正在深入研究K8s,并通过kubectl apply在主节点上部署了我的第一个Pod。为了检查其状态,我连续两次调用了kubectl get pods。我没有触碰任何东西,但随后再次调用相同命令时出现了下面的错误。有人可以帮助我理解可能发生了什么吗?

ubuntu:~$ kubectl get pods
NAME    READY   STATUS    RESTARTS   AGE
nginx   0/1     Pending   0          18s
ubuntu:~$ kubectl get pods
The connection to the server xxx.xxx.xxx.xxx:6443 was refused - did you specify the right host or port?

为了完整起见,这里是主节点上kubelet.service的状态:

sudo systemctl status kubelet.service
● kubelet.service - kubelet: The Kubernetes Node Agent
     Loaded: loaded (/lib/systemd/system/kubelet.service; enabled; vendor preset: enabled)
    Drop-In: /etc/systemd/system/kubelet.service.d
             └─10-kubeadm.conf
     Active: active (running) since Thu 2023-04-20 02:12:52 UTC; 23min ago

谢谢任何提示。

英文:

I am diving into K8s and deployed my first pod via kubectl apply on the master node. In order to check its status, I called kubectl get pods twice in a row. I did not touch anything, but a subsequent call of the same command failed with the error below. Can anyone help me understand what may have happened?

ubuntu:~$ kubectl get pods
NAME    READY   STATUS    RESTARTS   AGE
nginx   0/1     Pending   0          18s
ubuntu:~$ kubectl get pods
The connection to the server xxx.xxx.xxx.xxx:6443 was refused - did you specify the right host or port?

For completion, here the status of kubelet.service on the master node:

● kubelet.service - kubelet: The Kubernetes Node Agent
     Loaded: loaded (/lib/systemd/system/kubelet.service; enabled; vendor preset: enabled)
    Drop-In: /etc/systemd/system/kubelet.service.d
             └─10-kubeadm.conf
     Active: active (running) since Thu 2023-04-20 02:12:52 UTC; 23min ago

Thanks for any hint.

答案1

得分: 1

以下是您要翻译的内容:

根据Greek Diary的“admin”在这份文档中的解释,该文档解释了如何修复kubectl错误:“连接到服务器x.x.x.x:6443被拒绝 - 您是否指定了正确的主机或端口?”

以下故障排除步骤将帮助解决您的问题

> 1. kubectl应该在主节点上执行。
>
> 2. 当前用户必须具有Kubernetes集群配置环境变量(如何配置的详细信息列在“准备使用Kubernetes作为常规用户”部分下面),
>
>
> $ env | grep -i kube
>
> KUBECONFIG=/root/.kube/config
>
> 3. Docker服务必须正在运行:
>
> $ systemctl status docker
>
>
> 4. kubelet服务必须正在运行:
>
> $ systemctl status kubelet
>
> 5. TCP端口6443应该在侦听端口列表中:
>
> netstat -pnlt | grep 6443
>
>
> 如果TCP端口6443不可用,请检查防火墙/iptables规则是否匹配要求:
>
> $ firewall-cmd --list-all
>
>
> 还要检查kubelet日志:
>
> # journalctl -xeu kubelet
>
> 6. 尝试重新启动Kubernetes集群,这也会进行一些基本检查:
>
>
>
> $ kubeadm-setup.sh restart

英文:

As explained in this doc by Greek Diary ‘admin’ which explains how to fix the kubectl error:The connection to the server x.x.x.x:6443 was refused - did you specify the right host or port?

Below troubleshooting steps will help to resolve your issue:

> 1. The kubectl should be executed on the Master Node.
>
> 2. Current user must have Kubernetes cluster configuration environment variable (Details of how to are listed under section Preparing to Use
> Kubernetes as a Regular User),
>
>
> $ env | grep -i kube
>
> KUBECONFIG=/root/.kube/config
>
> 3.The docker service must be running:
>
> $ systemctl status docker
>
>
> 4.The kubelet service must be running:
>
> $ systemctl status kubelet
>
> 5.TCP port 6443 should be listed as it is listening to port:
>
> netstat -pnlt | grep 6443
>
>
> If TCP port 6443 is not available, check firewall/iptables rules
> matching requirements:
>
> $ firewall-cmd --list-all
>
>
> Also check kubelet logs:
>
> # journalctl -xeu kubelet
>
> 6.Try restarting Kubernetes cluster which will also do some basic checks:
>
>
>
>
> $ kubeadm-setup.sh restart

huangapple
  • 本文由 发表于 2023年4月20日 10:34:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/76060112.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定