深入kubernetes調度之NodeSelector
阿新 • • 發佈:2018-10-05
調度 rep com 列表 sta spec aml ready sel
本文主要介紹kubernetes調度框架中的NodeName和NodeSelector。
1 NodeName
Pod.spec.nodeName
用於強制約束將Pod調度到指定的Node節點上,這裏說是“調度”,但其實指定了nodeName的Pod會直接跳過Scheduler的調度邏輯,直接寫入PodList列表,該匹配規則是強制匹配。
例子:
apiVersion: extensions/v1beta1 kind: Deployment metadata: name: tomcat-deploy spec: replicas: 1 template: metadata: labels: app: tomcat-app spec: nodeName: k8s.node1 #指定調度節點為k8s.node1 containers: - name: tomcat image: tomcat:8.0 ports: - containerPort: 8080
2 NodeSelector
Pod.spec.nodeSelector
是通過kubernetes的label-selector機制進行節點選擇,由scheduler調度策略MatchNodeSelector
進行label匹配,調度pod到目標節點,該匹配規則是強制約束。啟用節點選擇器的步驟為:
- Node添加label標記
#標記規則:kubectl label nodes <node-name> <label-key>=<label-value> kubectl label nodes k8s.node1 cloudnil.com/role=dev #確認標記 [email protected]:~# kubectl get nodes k8s.node1 --show-labels NAME STATUS AGE LABELS k8s.node1 Ready 29d beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,cloudnil.com/role=dev,kubernetes.io/hostname=k8s.node1
- Pod定義中添加nodeSelector
apiVersion: extensions/v1beta1 kind: Deployment metadata: name: tomcat-deploy spec: replicas: 1 template: metadata: labels: app: tomcat-app spec: nodeSelector: cloudnil.com/role: dev #指定調度節點為帶有label標記為:cloudnil.com/role=dev的node節點 containers: - name: tomcat image: tomcat:8.0 ports: - containerPort: 8080
深入kubernetes調度之NodeSelector