kubernetes-- scheduling constraints

Fundamental

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

Scheduling

nodeName用于将Pod调度到指定的Node名称上,跳过调度器直接分配.

nodeSelector用于将Pod调度到匹配Label的Node上,前提是node要有标签.

#illustration#

Detailed principles

图中左上角的运维人员往节点中创建一个nginx资源.

API Server和etcd和Scheduler是master.

Kubelet和Docker是node节点.

API Server做为唯一入口,接受create创建资源的属性信息写入到etcd中(属性信息:名称,镜像名称,限制条件),
etcd完善发现机制(watch)给Scheduler调度器(查看那个节点适合),然后绑定相关pod的网络信息,
反馈给API Server,收到信息后api写入etcd中,此时etcd存储了pod的网络信息(IP),node1、中的kubelet会管理pod资源,
会触发容器的创建命令,安装完成后docker就会反馈状态信息给API Server,当API Server收到状态信息写入到etcd中.

API Server相当于是平台中的管理员,负责记录相关信息,

etcd相当于管理员的记事本,相关信息内容写在其中,

如果API Server挂了,那么k8s基本上就瘫痪了.

Sample demonstrates -nodeName

  • Edit the file yaml
vim pod5.yaml

apiVersion: v1
kind: Pod
metadata:
  name: pod-example
  labels:
    app: nginx
spec:
  nodeName: 192.168.142.131
  #指定给node1节点
  containers:
  - name: nginx
    image: nginx:1.15
    #验证是否创建了nginx
  • Create a file yaml
kubectl create -f pod5.yaml

kubectl get pods
  • View detailed event scheduler has not been found
kubectl describe pod pod-example
  • Empty pod resources
kubectl delete -f .

kubectl get pods

Sample demonstrates -nodeSelector

  • Gets the label Help
kubectl label --help
  • NAME need to get the name of the node
kubectl get node
  • Provided to the corresponding node label kgc = a and, respectively kgc = b
kubectl label nodes 192.168.142.130 kgc=a

kubectl label nodes 192.168.142.131 kgc=b
  • Look at the label
kubectl get nodes --show-labels

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

kubectl apply -f pod5.yaml
  • View event details can be observed through the scheduler allocates by events
kubectl describe pod pod-example

Troubleshooting

  • View pod event
kubectl describe TYPE NAME_PREFIX
  • View Log pod (under Failed state)
kubectl logs POD_NAME
  • Into the pod (status is running, but the service is not provided)
kubectl exec –it POD_NAME bash

#illustration#

thanks for reading!

Guess you like

Origin blog.51cto.com/14449521/2474242