K8S之调度约束

Kubernetes通过watch的机制进行每个组件的协作,每个组件之间的设计实现了解耦。
在这里插入图片描述

一、调度方式

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

示例1:nodeName

apiVersion: v1  
kind: Pod  
metadata:
  name: pod-example  
  labels:
    app: nginx  
spec:
  nodeName: 192.168.195.150
  containers:
  - name: nginx  
    image: nginx:1.15

[root@localhost demo]# kubectl create -f pod5.yaml 
pod/pod-example created
[root@localhost demo]# kubectl get pods
pod-example                       1/1     Running   0          86s
//查看网络
[root@localhost demo]# kubectl get pods -o wide
pod-example                       1/1     Running   0          2m9s   172.17.47.7   192.168.195.150   <none>
//查看详细事件(发现未经过调度器)
[root@localhost demo]# kubectl describe pod pod-example

Events:
  Type    Reason   Age   From                      Message
  ----    ------   ----  ----                      -------
  Normal  Pulled   97s   kubelet, 192.168.195.150  Container image "nginx:1.15" already present on machine
  Normal  Created  97s   kubelet, 192.168.195.150  Created container
  Normal  Started  97s   kubelet, 192.168.195.150  Started container

//清空所有pod
[root@localhost demo]# kubectl delete -f .
[root@localhost demo]# kubectl get pods
No resources found.

示例2:nodeSelector

//获取标签帮助
[root@localhost demo]# 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名称
[root@localhost demo]# kubectl get node
NAME              STATUS   ROLES    AGE   VERSION
192.168.195.150   Ready    <none>   14d   v1.12.3
192.168.195.151   Ready    <none>   14d   v1.12.3
//给对应的node设置标签分别为kgc=a和kgc=b
[root@localhost demo]# kubectl label nodes 192.168.195.150 kgc=a
node/192.168.195.150 labeled
[root@localhost demo]# kubectl label nodes 192.168.195.151 kgc=b
node/192.168.195.151 labeled
//查看标签
[root@localhost demo]# kubectl get nodes --show-labels
NAME              STATUS   ROLES    AGE   VERSION   LABELS
192.168.195.150   Ready    <none>   14d   v1.12.3   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kgc=a,kubernetes.io/hostname=192.168.195.150
192.168.195.151   Ready    <none>   14d   v1.12.3   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kgc=b,kubernetes.io/hostname=192.168.195.151


[root@localhost demo]# vim pod5.yaml 
apiVersion: v1
kind: Pod
metadata:
  name: pod-example
  labels:
    app: nginx
spec:
  nodeSelector: 
    kgc: b
  containers:
  - name: nginx
    image: nginx:1.15

[root@localhost demo]# kubectl apply -f pod5.yaml 
pod/pod-example created
//查看详细事件(通过事件可以观察经过调度器分配)
[root@localhost demo]# kubectl describe pod pod-example
Events:
  Type    Reason     Age   From                      Message
  ----    ------     ----  ----                      -------
  Normal  Scheduled  67s   default-scheduler         Successfully assigned default/pod-example to 192.168.195.151
  Normal  Pulling    66s   kubelet, 192.168.195.151  pulling image "nginx:1.15"
  Normal  Pulled     24s   kubelet, 192.168.195.151  Successfully pulled image "nginx:1.15"
  Normal  Created    24s   kubelet, 192.168.195.151  Created container
  Normal  Started    24s   kubelet, 192.168.195.151  Started container

二、故障排除

在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

清风~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值