运行一个简单pod

kubect run mynginx --image==nginx

查看pod的状态,发现一直是pending状态

然后查看pod日志,但是没有日志信息输出

kubectl logs mynginx

使用describe/event查看详细信息

kubectl describe pod mynginx
kubectl get event

可以看到相关事件提示:

15h         Warning   FailedScheduling   pod/mynginx02      0/3 nodes are available: 3 node(s) had taint {node-role.kubernetes.io/master: }, that the pod didn't tolerate.
15h         Warning   FailedScheduling   pod/mynginx02      0/3 nodes are available: 3 node(s) had taint {node-role.kubernetes.io/master: }, that the pod didn't tolerate.
15h         Warning   FailedScheduling   pod/mynginx02      0/3 nodes are available: 3 node(s) had taint {node-role.kubernetes.io/master: }, that the pod didn't tolerate.
60m         Warning   FailedScheduling   pod/mynginx02      0/3 nodes are available: 3 node(s) had taint {node-role.kubernetes.io/master: }, that the pod didn't tolerate.
52m         Warning   FailedScheduling   pod/mynginx02      0/3 nodes are available: 3 node(s) had taint {node-role.kubernetes.io/master: }, that the pod didn't tolerate.
14m         Warning   FailedScheduling   pod/mynginx02      0/3 nodes are available: 3 node(s) had taint {node-role.kubernetes.io/master: }, that the pod didn't tolerate.

分析:这是pod调度失败了,taint是k8s的一种污点机制;
“node-role.kubernetes.io/master”的污点机制,一般是在k8s集群的master节点上配置,因为master运行着集群的重要组件资源,比如api-server、scheduler等组件,为了防止普通pod在此节点上运行调度,抢占资源,所以master上一般需要自带此设置;

但还有2个普通node节点,也都设置了污点机制,导致mynginx这个pod无法调度到集群上的所有节点,所以一直是pending状态,所以可以将普通node节点的污点机制去掉,处理操作如下:<node-name为节点名>
 

kubectl taint nodes <node-name> node-role.kubernetes.io/master-

2个普通的node节点去掉污点机制后,等待一段时间,发现mynginx状态为running了,日志也正常输出,查看event事件:

  Normal   Pulling           23m                  kubelet            Pulling image "nginx"
  Normal   Pulled            23m                  kubelet            Successfully pulled image "nginx" in 49.168540631s
  Normal   Created           23m                  kubelet            Created container mynginx
  Normal   Started           22m                  kubelet            Started container mynginx

还有一种方式,是通过运行pod时,添加 tolerations,使其容忍 node-role.kubernetes.io/master 的污点。这样 Pod 就能够被调度到带有这个污点的节点上,这里就不再展开了

Logo

鸿蒙生态一站式服务平台。

更多推荐