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

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://www.hainiubl.com/topics/75623

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值