首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >kubernetes高级调度的一些方式

kubernetes高级调度的一些方式

作者头像
极客运维圈
发布2020-03-21 10:05:17
发布2020-03-21 10:05:17
4750
举报
文章被收录于专栏:乔边故事乔边故事

节点选择器

nodeSelector

如下:

代码语言:javascript
复制
apiVersion: v1kind: Podmetadata:  name: pod-nodeselectorspec:  containers:  - name: myapp    image: ikubernetes/myapp:v1  nodeSelector:    disktype: ssd

上面定义只有调度到符合标签为disktype=ssd得node。

nodeName

当确认要让某个Pod允许在指定的节点上,如下:

代码语言:javascript
复制
apiVersion: v1kind: Podmetadata:  name: pod-nodenamespec:  containers:  - name: myapp    image: ikubernetes/myapp:v1  nodeName: 172.16.1.130     # 节点名字

节点亲和性

nodeAffinity

nodeAffinity有两种,优选和必选,其为:preferredDuringSchedulingIgnoredDuringExecution和requiredDuringSchedulingIgnoredDuringExecution。

requiredDuringSchedulingIgnoredDuringExecution的例子如下:

代码语言:javascript
复制
apiVersion: v1kind: Podmetadata:  name: pod-nodeaffinity-requiredspec:  containers:  - name: myapp    image: ikubernetes/myapp:v1  affinity:    nodeAffinity:      requiredDuringSchedulingIgnoredDuringExecution:        nodeSelectorTerms:        - matchExpressions:          - key: disktype            operator: In            values: ["ssd", "harddisk"]

其中operator支持In,NotIn, Exists, DoesNotExist. Gt, and Lt。

preferredDuringSchedulingIgnoredDuringExecution的例子如下:

代码语言:javascript
复制
apiVersion: v1kind: Podmetadata:  name: pod-nodeaffinity-preferredspec:  containers:  - name: myapp    image: ikubernetes/myapp:v1  affinity:    nodeAffinity:      preferredDuringSchedulingIgnoredDuringExecution:      - preference:          matchExpressions:          - key: disktype            operator: In            values: ["ssd", "harddisk"]        weight: 60

podAffinity

podAffinity也有preferredDuringSchedulingIgnoredDuringExecution和requiredDuringSchedulingIgnoredDuringExecution,其定义方式和nodeAffinity一样

代码语言:javascript
复制
apiVersion: v1kind: Podmetadata:  name: pod-first  labels:    app: myapp    row: frontedspec:  containers:  - name: myapp    image: ikubernetes/myapp:v1---apiVersion: v1kind: Podmetadata:  name: pod-second  labels:    app: db    row: backendspec:  containers:  - name: db    image: busybox    imagePullPolicy: IfNotPresent    command:    - "/bin/sh"    - "-c"    - "sleep 3600"  affinity:    podAffinity:      requiredDuringSchedulingIgnoredDuringExecution:      - labelSelector:          matchExpressions:          - key: app            operator: In            values: ["myapp"]        topologyKey: kubernetes.io/hostname

podAntiAffinity

pod的反亲和性。

代码语言:javascript
复制
apiVersion: v1kind: Podmetadata:  name: pod-first  labels:    app: myapp    row: frontedspec:  containers:  - name: myapp    image: ikubernetes/myapp:v1---apiVersion: v1kind: Podmetadata:  name: pod-second  labels:    app: db    row: backendspec:  containers:  - name: db    image: busybox    imagePullPolicy: IfNotPresent    command:    - "/bin/sh"    - "-c"    - "sleep 3600"  affinity:    podAntiAffinity:      requiredDuringSchedulingIgnoredDuringExecution:      - labelSelector:          matchExpressions:          - key: app            operator: In            values: ["myapp"]        topologyKey: kubernetes.io/hostname

污点调度方式

taints是Node级别的,可以通过kubectl explain node.spec.taints来查看。

代码语言:javascript
复制
# kubectl explain node.spec.taintsKIND:     NodeVERSION:  v1RESOURCE: taints <[]Object>DESCRIPTION:     If specified, the node's taints.     The node this Taint is attached to has the "effect" on any pod that does     not tolerate the Taint.FIELDS:   effect    <string> -required-     Required. The effect of the taint on pods that do not tolerate the taint.     Valid effects are NoSchedule, PreferNoSchedule and NoExecute.   key    <string> -required-     Required. The taint key to be applied to a node.   timeAdded    <string>     TimeAdded represents the time at which the taint was added. It is only     written for NoExecute taints.   value    <string>     Required. The taint value corresponding to the taint key.

其中effect定义对Pod的排斥效果:

  • NoSchdule:仅影响调度过程,对现存在的Pod不产生影响;
  • NoExecute:不仅影响调度,而且还影响现存Pod,不容忍的Pod对象将被驱逐;
  • PreferNoSchedule:

管理污点用kubectl taint.

tolerations容忍度是定义在Pod上的。

代码语言:javascript
复制
apiVersion: apps/v1kind: Deploymentmetadata:  name: nginx-deployment  labels:    app: nginxspec:  replicas: 2  selector:    matchLabels:      app: nginx  template:    metadata:      labels:        app: nginx    spec:      containers:      - name: nginx        image: nginx:1.7.9        imagePullPolicy: IfNotPresent         ports:        - containerPort: 80      tolerations:      - key: "node-type"        operator: Equal        value: dev        effect: NoSchedule        tolerationSeconds: 20
本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2020-02-18,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 乔边故事 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 节点选择器
    • nodeSelector
    • nodeName
  • 节点亲和性
    • nodeAffinity
    • podAffinity
    • podAntiAffinity
  • 污点调度方式
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档