解决镜像因为“Tolerations:node.kubernetes.io/not-ready:NoExecute for 300s”处于“Pending”状态

参考文章:k8s基本概念-配置调度策略之(Taints-and-Tolerations)
https://blog.51cto.com/nosmoking/2097380

问题现象:新创建的rc,查看对应的pod一直处于Pending状态
[root@master contos7文件]# kubectl get pods
NAME          READY   STATUS    RESTARTS   AGE
mysql-phrqz   1/1     Running   0          30m
myweb-qvjr4   0/1     Pending   0          29s

查看详情发现:1 node(s) had taints that the pod didn't tolerate.
===>Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
===>node.kubernetes.io/unreachable:NoExecute for 300s
[root@master contos7文件]# kubectl describe pod myweb-qvjr4
Name:               myweb-qvjr4
Namespace:          default
Priority:           0
PriorityClassName:  <none>
Node:               <none>
Labels:             app=myweb
Annotations:        <none>
Status:             Pending
IP:                 
Controlled By:      ReplicationController/myweb
Containers:
  myweb:
    Image:      docker.io/kubeguide/tomcat-app:v1
    Port:       8080/TCP
    Host Port:  0/TCP
    Environment:
      MYSQL_SERVICE_HOST:  mysql
      MYSQL_SERVICE_PORT:  3306
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-8sqth (ro)
Conditions:
  Type           Status
  PodScheduled   False 
Volumes:
  default-token-8sqth:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-8sqth
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s

Events:
  Type     Reason            Age                From               Message
  ----     ------            ----               ----               -------
  Warning  FailedScheduling  41s (x3 over 51s)  default-scheduler  0/1 nodes are available: 1 node(s) had taints that the pod didn't tolerate.

查看yaml文件:
[root@master contos7文件]# cat myweb-rc.yaml
apiVersion: v1
kind: ReplicationController
metadata:
  name: myweb
spec:
  replicas: 1    #在这里选择配置成了1个副本
  selector:
   app: myweb
  template:
   metadata:
     labels:
       app: myweb
   spec:
     containers:
     - name: myweb
       image: docker.io/kubeguide/tomcat-app:v1
       ports:
       - containerPort: 8080
       env:
       - name: MYSQL_SERVICE_HOST               #value: '节点内IP'
         value: 'mysql'
       - name: MYSQL_SERVICE_PORT
         value: '3306'

对yaml文件进行修改,添加一个tolerations解决node上的taints
[root@master contos7文件]# cat myweb-rc.yaml 
apiVersion: v1
kind: ReplicationController
metadata:
  name: myweb
spec:
  replicas: 1    #在这里选择配置成了1个副本
  selector:
   app: myweb
  template:
   metadata:
     labels:
       app: myweb
   spec:
     containers:
     - name: myweb
       image: docker.io/kubeguide/tomcat-app:v1
       ports:
       - containerPort: 8080
       env:
       - name: MYSQL_SERVICE_HOST               #value: '节点内IP'
         value: 'mysql'
       - name: MYSQL_SERVICE_PORT
         value: '3306'
     tolerations:
     - key: "node-role.kubernetes.io/master"
       operator: "Equal"
       value: ""
       effect: "NoSchedule"

删除之前未成功启动的rc,重新执行新的yaml文件并查看pod状态,已经运行了
[root@master shenqh]# kubectl get pods
NAME          READY   STATUS    RESTARTS   AGE
mysql-phrqz   1/1     Running   0          4h23m
myweb-2vkh2   1/1     Running   0          3h33m

发布了46 篇原创文章 · 获赞 10 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/sqhren626232/article/details/93619602