Kubernetes Python客户端错误create\u namespaced\u binding:(409)原因:confi

2024-10-02 02:37:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用的是k8v1.7和Python Clientv2.0。我的自定义调度程序检测到一个挂起的pod并成功地调度它。然而,在将pod分配给一个节点之后,它会抱怨pod已经被分配给了一个节点,尽管它只是由调度器自己分配的。这有什么值得关注的吗?或者我该怎么解决这个问题?在

错误信息

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}

在计划程序.py在

^{pr2}$

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的回答,谢谢),以找到尚未安排的正确的PENDINGpod。请看我的答案。在


Tags: name程序http节点responsecontent调度pod
2条回答

创建pod时,调度程序将获得三个“挂起”事件:

  1. Pod尚未安排('node_name': None, 'status': {'conditions': None,...}
  2. Pod已安排('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']}

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

如果出了问题,调度程序可能需要考虑以前的错误,并可能尝试将pod调度到不同的节点。在

在您的情况下,您的调度程序威胁所有三个事件,如第一个事件,并尝试一次又一次地调度pod。这就是为什么你看到“pod xxx is already assigned to node yyy”错误。在

下面是更新后的main方法(根据@VAS的回答,谢谢)来找到尚未被调度的正确的PENDINGpod。在

def main():
    w = watch.Watch()
    for event in w.stream(v1.list_namespaced_pod, 'default'): # default == namespace name
        # All pending pods have 3 states (not scheduled, scheduled, initialized but not ready yet)
        # We look for NOT SCHEDULED pod and conditions==None
        if event['object'].status.phase == 'Pending' and event['object'].status.conditions == None and event['object'].spec.scheduler_name == CUSTOM_SCHEDULER_NAME:
            print "Pending and Not Scheduled POD Found "+event['object'].metadata.name
            try:
                res = scheduler(event['object'].metadata.name,random.choice(nodes_available())) # nodes_available() returns all available nodes
                print "success"
            except Exception as a:
                print ("Exception when calling CoreV1Api->create_namespaced_binding: %s\n" % a)

相关问题 更多 >

    热门问题