Inter

您所在的位置:网站首页 pod一直处于pending Inter

Inter

#Inter| 来源: 网络整理| 查看: 265

Inter-pod topological affinity and anti-affinity(pod之间拓扑上的关联与反关联)

翻译

podAffinityrequiredDuringSchedulingIgnoredDuringExecutionapiVersion: v1kind: Podmetadata: name: test1spec: affinity: podAffinity: requiredDuringSchedulingIgnoredDuringExecution: - labelSelector: matchExpressions: - key: "mysvc" operator: In values: - S1 topologyKey: kubernetes.io/hostname containers: - name: dao-2048 image: daocloud.io/daocloud/dao-2048 imagePullPolicy: IfNotPresent 通过该文件创建得到的pod,一直处于pending状态,错误原因如下图 ,可知当使用requiredDuringSchedulingIgnoredDuringExecution参数时,如果无法满足affinity条件,pod无法启动 执行kubectl label po test1 mysvc=S1``kubectl label po test1 mysvc=S1修改pod标签使pod满足条件,通过kubectl get pod,可观察到pod状态变为running。再执行kubectl label po test1 mysvc-删除pod的标签,使pod不满足affinity条件,发现pod转态仍为running。由此确定schedule状态包含pending而且在IgnoredDuringExecutio n条件下,在执行期间发生条件改变,对pod的状态是不会产生影响的。 preferredDuringSchedulingIgnoredDuringExecutionapiVersion: v1kind: Podmetadata: name: test1spec: affinity: podAffinity: preferredDuringSchedulingIgnoredDuringExecution: - weight: 100 podAffinityTerm: labelSelector: matchExpressions: - key: security operator: In values: - S1 topologyKey: kubernetes.io/hostname containers: - name: dao-2048 image: daocloud.io/daocloud/dao-2048 imagePullPolicy: IfNotPresent

通过配置文件产生pod,观察可得pod的状态为running,由此可知preferredDuringScheduling下的affinity为非必须条件。

podAntiAffinityrequiredDuringSchedulingIgnoredDuringExecutionapiVersion: v1kind: Podmetadata: name: test4 labels: security: S1spec: affinity: podAntiAffinity: requiredDuringSchedulingIgnoredDuringExecution: - labelSelector: matchExpressions: - key: security operator: In values: - S1 topologyKey: kubernetes.io/hostname containers: - name: dao-2048 image: daocloud.io/daocloud/dao-2048 imagePullPolicy: IfNotPresent

使用该文件创建3个pod,可以发现3个pod运行在不同的node上。。如果再创建一个pod,可以观察到该pod处于pending状态。因为在该环境只有三台worknode,符合条件的所有worknode均被占用。

preferredDuringSchedulingIgnoredDuringExecutionapiVersion: v1kind: Podmetadata: name: test3 labels: security: S1spec: affinity: podAntiAffinity: preferredDuringSchedulingIgnoredDuringExecution: - weight: 100 podAffinityTerm: labelSelector: matchExpressions: - key: security operator: In values: - S1 topologyKey: kubernetes.io/hostname containers: - name: dao-2048 image: daocloud.io/daocloud/dao-2048 imagePullPolicy: IfNotPresent

使用该配置模板创建三个pod,可以发现pod依旧分配到了不同的节点上。当创建第四个pod时,第四个pod能够被顺利创建,说明preferredDuringScheduling在podAntiAnffinity下也是不严格匹配规则。

podAntiAffinity的对称性apiVersion: v1kind: Podmetadata: name: test3 labels: security: S1spec: containers: - name: dao-2048 image: daocloud.io/daocloud/dao-2048 imagePullPolicy: IfNotPresent

以及

apiVersion: v1kind: Podmetadata: name: test2 labels: security: S1spec: affinity: podAntiAffinity: requiredDuringSchedulingIgnoredDuringExecution: - labelSelector: matchExpressions: - key: security operator: In values: - S1 topologyKey: kubernetes.io/hostname containers: - name: dao-2048 image: daocloud.io/daocloud/dao-2048 imagePullPolicy: IfNotPresent

先使用第二个配置文件创建两个pod,再用第一个文件创建一个pod,可以观察到,三个pod在三个不同的node上。,说明当设置test1对test2排他,不用设置test2对test1排他。



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3