Kubernetes PodAffinity无法部署Pod [英] Kubernetes PodAffinity not able to deploy pods

查看:1140
本文介绍了Kubernetes PodAffinity无法部署Pod的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有

So I have this problem, and try to implement podAffinity to solve it.

我有3个节点,并希望在同一节点上部署2个Pod.在Deployment YAML文件中,我在metadata.labels下具有service:git,以下是相似性设置:

I have 3 nodes and want to deploy 2 pods on the same node. In the Deployment YAML files I have service:git under metadata.labels, and the following is the affinity setting:

  affinity:
    podAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
      - labelSelector:
          matchExpressions:
          - key: service
            operator: In
            values:
            - git
        topologyKey: kubernetes.io/hostname

但是pod部署失败,出现以下错误:

But the pods failed to deploy, I got the following error:

0/3 nodes are available: 3 node(s) didn't match pod affinity rules, 3 node(s) didn't match pod affinity/anti-affinity.

我的配置有问题吗?

如果没有,我想可能是因为部署第一个Pod时,系统将尝试查找包含标签为service: git的Pod的节点并失败(因为它是第一个),而另一个失败由于同样的原因,pod也将失败.这是正确的吗?

If not, I guess maybe it is because when the first pod is deployed, the system will try to find a node that contains a pod with the label service: git and fail (because it is the first one), and another pod also fail because of the same reason. Is this correct?

但是随后如何解决该问题(不采用解决方法)?

But then how to solve the problem (without resorting to workarounds)?

推荐答案

  • 您正在使用"requiredDuringSchedulingIgnoredDuringExecution:"因此它将看起来是正在运行(已经)"标签为"service:git"的广告连播并且似乎您还没有带有该标签的广告连播.因此,以下是一种快速的解决方法,其中将创建一个带有标签"service:git"的测试广告连播. .这样podAffinity规则将找到目标节点(将是运行此testpod的节点)
  • kubectl run testpod --image=busybox --labels="service=git" -- sleep infinite

    • 一旦Pod上方的UP出现,您的部署中的所有Pod也将被创建. 如果没有删除,请重新部署.

    • Once above pod is UP .. all the pods in your deployment also should get created. if not delete the deployment and re-apply it.

    If you need a elegant solution then you can consider using "preferredDuringSchedulingIgnoredDuringExecution" instead of "requiredDuringSchedulingIgnoredDuringExecution"

    这篇关于Kubernetes PodAffinity无法部署Pod的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆