K8S之调度约束+故障排查

目录

一、调度约束的各个组件流程图

二、基本调度方式 

三、操作实例

3.1 nodeName

3.2 nodeSelector 

四、故障排查 

一、调度约束的各个组件流程图

Kubernetes通过watch的机制进行每个组件的协作,每个组件之间的设计实现了解耦。

二、基本调度方式 

  • nodeName用于将Pod调度到指定的Node名称上(跳过调度器直接分配)
  • nodeSelector用于将Pod调度到匹配Label的Node上

三、操作实例

3.1 nodeName

vim pod5.yaml
kubectl create -f pod5.yaml 
apiVersion: v1  
kind: Pod  
metadata:
  name: pod-example  
  labels:
    app: nginx  
spec:
  nodeName: node1
  containers:
  - name: nginx  
    image: nginx:1.14
kubectl get pods -o wide
#查看详细事件(发现未经过调度器)
kubectl describe pod pod-example

#清空pod
kubectl delete -f .

3.2 nodeSelector 

#查看标签用法
kubectl label --help
Usage:
  kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N
[--resource-version=version] [options]
#需要获取node上的NAME名称
kubectl get node
#给对应的node设置标签分别为cz=alice和cz=bob
kubectl label nodes node1(节点名字为none的用IP) cz=alice
kubectl label nodes node2 cz=bob
#查看标签
kubectl get nodes --show-labels

apiVersion: v1
kind: Pod
metadata:
  name: pod-example
  labels:
    app: nginx
spec:
  nodeSelector:
    cz: bob
  containers:
  - name: nginx
    image: nginx:1.14

vim pod5.yaml 
kubectl create -f pod5.yaml
kubectl get pods -o wide
#查看详细事件(通过事件可以观察经过调度器分配)
kubectl describe pod pod-example

四、故障排查 

状态表

#查看pod事件
kubectl describe TYPE NAME_PREFIX  
#查看pod日志(Failed状态下)
kubectl logs POD_NAME
#进入pod(状态为running,但是服务没有提供)
kubectl exec –it POD_NAME bash

猜你喜欢

转载自blog.csdn.net/weixin_67470255/article/details/126122488