gpt4 book ai didi

python - ValueError : Invalid value for selector, 不能为 None

转载 作者:行者123 更新时间:2023-12-02 12:10:49 26 4
gpt4 key购买 nike

我是 Kubernetes 的新手,我必须使用 Kubernetes 创建一个 pod python-client .所以为了试验,我正在尝试运行 examples notebooks由项目提供,无需任何更改以查看其工作原理。

intro_notebook.ipynb 开头在第 3 步我得到一个错误:

ValueError: Invalid value for `selector`, must not be `None`

代码如下:

from kubernetes import client, config

我唯一更改的部分是第二个单元格,因为我正在使用 Ubuntu 的 microk8s 运行 Kubernetes:

config.load_kube_config('/var/snap/microk8s/current/credentials/client.config')
api_instance = client.AppsV1Api()
dep = client.V1Deployment()
spec = client.V1DeploymentSpec() # <<< At this line I hit the error!

完整的回溯:

ValueError                                Traceback (most recent call last)
<ipython-input-9-f155901e8381> in <module>
1 api_instance = client.AppsV1Api()
2 dep = client.V1Deployment()
----> 3 spec = client.V1DeploymentSpec()

~/.local/share/virtualenvs/jupyter-2hJZ4kgI/lib/python3.8/site-packages/kubernetes/client/models/v1_deployment_spec.py in __init__(self, min_ready_seconds, paused, progress_deadline_seconds, replicas, revision_history_limit, selector, strategy, template)
76 if revision_history_limit is not None:
77 self.revision_history_limit = revision_history_limit
---> 78 self.selector = selector
79 if strategy is not None:
80 self.strategy = strategy

~/.local/share/virtualenvs/jupyter-2hJZ4kgI/lib/python3.8/site-packages/kubernetes/client/models/v1_deployment_spec.py in selector(self, selector)
215 """
216 if selector is None:
--> 217 raise ValueError("Invalid value for `selector`, must not be `None`") # noqa: E501
218
219 self._selector = selector

ValueError: Invalid value for `selector`, must not be `None`

我正在运行 python3.8:

$ pip freeze | grep -e kuber
kubernetes==11.0.0

$ snap list microk8s
Name Version Rev Tracking Publisher Notes
microk8s v1.18.6 1551 latest/stable canonical✓ classic

更新

将 microk8s 降级到 v1.15.11 并没有解决问题。

最佳答案

这是因为他们将验证更改为在构造函数中发生,而不是稍后发生——这不是笔记本所期望的。 他们 在构造Deployment 之前,您只需要将那些内部赋值向上移动即可:

name = "my-busybox"
spec = client.V1DeploymentSpec(
selector=client.V1LabelSelector(match_labels={"app":"busybox"}),
template=client.V1PodTemplateSpec(),
)
container = client.V1Container(
image="busybox:1.26.1",
args=["sleep", "3600"],
name=name,
)
spec.template.metadata = client.V1ObjectMeta(
name="busybox",
labels={"app":"busybox"},
)
spec.template.spec = client.V1PodSpec(containers = [container])
dep = client.V1Deployment(
metadata=client.V1ObjectMeta(name=name),
spec=spec,
)

关于python - ValueError : Invalid value for selector, 不能为 None,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63218948/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com