Kubernetes Python客户端错误create_namespaced_binding:(409)原因:冲突 [英] Kubernetes Python Client error create_namespaced_binding: (409) Reason: Conflict

查看:525
本文介绍了Kubernetes Python客户端错误create_namespaced_binding:(409)原因:冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用k8 v1.7和 Python客户端 v2.0.我的自定义调度程序检测到一个暂挂的Pod并成功调度它.但是,在将Pod分配给节点之后,它抱怨说Pod已经分配给了一个节点,尽管它只是由调度程序本身分配的.这件事值得关注吗?或者我该如何解决?

I'm using k8 v1.7 and Python Client v2.0. My custom scheduler detects a pending pod and schedules it successfully. However, after assigning a pod to a node, it complains that the pod is already assigned to a node though it is just assigned by the scheduler itself. Is this something to be concerned? Or how can I fix this?

错误消息

create_namespaced_binding: (409)
Reason: Conflict
HTTP response headers: HTTPHeaderDict({'Date': 'Tue, 19 Jun 2018 16:14:57 GMT', 'Content-Length': '289', 'Content-Type': 'application/json'})
HTTP response body: {"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"Operation cannot be fulfilled on pods/binding \"ps0-16-r935x\": pod ps0-16-r935x is already assigned to node \"blipp65\"","reason":"Conflict","details":{"name":"ps0-16-r935x","kind":"pods/binding"},"code":409}

scheduler.py

scheduler.py

from kubernetes import client, config, watch
from kubernetes.client.rest import ApiException
config.load_kube_config()
v1 = client.CoreV1Api()

scheduler_name = 'my-custom-scheduler-v1'

def nodes_available():
    ready_nodes = []
    for n in v1.list_node().items:
        for status in n.status.conditions:
            if status.status == 'True' and status.type == 'Ready':
                ready_nodes.append(n.metadata.name)
    return ready_nodes


def scheduler(name, node, namespace='default'):
    body = client.V1Binding()

    target = client.V1ObjectReference()
    target.kind = 'Node'
    target.apiVersion = 'v1'
    target.name = node

    meta = client.V1ObjectMeta()
    meta.name = name

    body.target = target
    body.metadata = meta

    return v1.create_namespaced_binding_binding(name, namespace, body)


def main():
    w = watch.Watch()
    for event in w.stream(v1.list_namespaced_pod, 'default'):
        if event['object'].status.phase == 'Pending' and event['object'].spec.scheduler_name == scheduler_name:
            print "Pending Found"
            try:
                res = scheduler(event['object'].metadata.name,random.choice(nodes_available()))
                print "success"
            except Exception as a:
                print ("Exception when calling CoreV1Api->create_namespaced_binding: %s\n" % a)

POD YML文件

apiVersion: v1
kind: Pod
metadata:
  name: shoeb-pod
spec:
  schedulerName: my-custom-scheduler-v1
  containers:
  - name: redis
    image: redis

已于2019-06-03更新

我刚刚添加了更新的main方法(根据@VAS的回答,谢谢),以找到尚未安排的正确的PENDING吊舱.请看我的回答.

I just added the updated main method (according to @VAS's answer, thanks) to find the right PENDING pod that has not been scheduled yet. Please see my answer.

推荐答案

创建pod时,调度程序会收到三个待处理"事件:

When a pod is created, the scheduler gets three "Pending" events:

  1. 尚未预定Pod('node_name': None, 'status': {'conditions': None,...})
  2. 预定播客('node_name': 'some_node_name','status': {'conditions': [...,'status': True, 'type':'PodScheduled'],...})
  3. Pod已初始化但尚未准备就绪('node_name': 'minikube','status': {'conditions': [...,'status': True, 'type':'Initialized'], ... ,'status': False, 'type':'Ready']})
  1. Pod is not scheduled yet ('node_name': None, 'status': {'conditions': None,...})
  2. Pod is scheduled ('node_name': 'some_node_name','status': {'conditions': [...,'status': True, 'type':'PodScheduled'],...} )
  3. Pod is initialized but not ready yet ('node_name': 'minikube','status': {'conditions': [...,'status': True, 'type':'Initialized'], ... ,'status': False, 'type':'Ready']} )

因此,您的自定义调度程序应将Pod绑定到第一个事件的节点上,检查Pod的状态并确保已在第二个事件出现时对Pod进行了调度,然后检查在第三个事件出现时是否对Pod进行了初始化

Therefore, your custom scheduler should bind pod to the node on the first event, check the status of the pod and make sure it is scheduled when the second event appears, and then check if the pod is initialized when the third event appears.

如果出现问题,调度程序可能需要考虑先前的错误,并可能尝试将Pod调度到其他节点.

If something goes wrong, the scheduler may need to take into account the previous errors and probably try to schedule the pod to different nodes.

在您的情况下,您的调度程序会威胁到所有三个事件(如第一个事件),并试图一次又一次地调度播客.这就是为什么您看到"pod xxx is already assigned to node yyy"错误.

In your case, your scheduler threats all three events like the first one and tries to schedule the pod again and again. That's why you see that "pod xxx is already assigned to node yyy" error.

这篇关于Kubernetes Python客户端错误create_namespaced_binding:(409)原因:冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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