K8S 将 pod 调度到指定 nodes 上运行

教程 透心凉 ⋅ 于 2021-06-04 19:41:48 ⋅ 1670 阅读

K8S将pod调度到指定nodes上运行

两种方式

方式1:强制固定
  • 编写yaml,添加参数(node节点名)
vim text.yaml
nodeName: worker01  #添加节点名参数
  • 具体yaml
apiVersion: v1
kind: Pod
metadata:
  name: text
  namespace: text
spec:
  nodeName: worker01   #添加节点名参数
  containers:
  - name: hello
    image: centos:7
    imagePullPolicy: IfNotPresent
    command: ["bash","-c","--"]
    args: ["while true; do sleep 3;done;"]
  • 创建改pod
kubectl create -f text.yaml

file

  • 查看pod,运行成功

file

  • 查看是否在worker01上运行
kubectl describe pod text -n text

file

方式2:使用标签选择器(label-selector)
  • 给节点添加标签
kubectl label nodes worker03 type=node_type  

file

  • 查看标签是否添加成功
kubectl get node --show-labels   #获取所有节点的标签,得到worker03设置的标签

file

  • 编写yaml创建pod,添加标签选择器参数
vim text1.yaml
  • 内容如下
apiVersion: v1
kind: Pod
metadata:
  name: text1
  namespace: text
spec:
  nodeSelector:    #标签选择器参数
    type: node_type #刚刚添加的类型
  containers:
  - name: hello1
    image: centos:7
    imagePullPolicy: IfNotPresent
    command: ["bash","-c","--"]
    args: ["while true; do sleep 3;done;"]

file

  • 查看是否运行
kubectl get pod -n text 

file

  • 查看是否成功在worker03上运行
kubectl describe pod text1 -n text

file

版权声明:原创作品,允许转载,转载时务必以超链接的形式表明出处和作者信息。否则将追究法律责任。来自海汼部落-透心凉,http://hainiubl.com/topics/75623
回复数量: 0
    暂无评论~~
    • 请注意单词拼写,以及中英文排版,参考此页
    • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`, 更多语法请见这里 Markdown 语法
    • 支持表情,可用Emoji的自动补全, 在输入的时候只需要 ":" 就可以自动提示了 :metal: :point_right: 表情列表 :star: :sparkles:
    • 上传图片, 支持拖拽和剪切板黏贴上传, 格式限制 - jpg, png, gif,教程
    • 发布框支持本地存储功能,会在内容变更时保存,「提交」按钮点击时清空
    Ctrl+Enter