Open Jicming opened 1 month ago
Issue https://github.com/kubernetes-client/python/issues/1662 can resolve this problem by disabling the client side validation Why not follow this example
@Jicming Could you clarify which example you were using? Is it one of the following?
When I use the examples in the document to execute, I report an error The code is as follows:
from kubernetes import client, config config.load_kube_config(config_file='config/config_14b') apps_api = client.AppsV1Api() deployment = client.V1Deployment() deployment.api_version = "apps/v1" deployment.kind = "Deployment" deployment.metadata = client.V1ObjectMeta(name="nginx-deployment")
spec = client.V1DeploymentSpec() spec.replicas = 3
spec.template = client.V1PodTemplateSpec() spec.template.metadata = client.V1ObjectMeta(labels={"app": "nginx"})
spec.template.spec = client.V1PodSpec() container = client.V1Container() container.name="nginx" container.image="nginx:1.7.9" container. ports = [client.V1ContainerPort(container_port=80)] spec.template.spec.containers = [container] deployment.spec = spec apps_api.create_namespaced_deployment(namespace="default", body=deployment) deployment.spec.template.spec.containers[0].image = "nginx:1.9.1" apps_api.replace_namespaced_deployment(name="nginx-deployment", namespace="default", body=deployment) apps_api.delete_namespaced_deployment(name="nginx-deployment", namespace="default", body=client.V1DeleteOptions(propagation_policy="Foreground", grace_period_seconds=5))
The error is as follows:
D:\ProgramFiles(x86)\Python\python3.10.2\python.exe "D:/ProgramData/爬虫/电信培训/k8s python 客户端/deployment_test1.py" Traceback (most recent call last): File "D:\ProgramData\爬虫\电信培训\k8s python 客户端\deployment_test1.py", line 30, in
spec.template.spec = client.V1PodSpec()
File "D:\ProgramFiles(x86)\Python\python3.10.2\lib\site-packages\kubernetes\client\models\v1_pod_spec.py", line 172, in init
self.containers = containers
File "D:\ProgramFiles(x86)\Python\python3.10.2\lib\site-packages\kubernetes\client\models\v1_pod_spec.py", line 332, in containers
raise ValueError("Invalid value for
containers
, must not beNone
") # noqa: E501 ValueError: Invalid value forcontainers
, must not beNone
Process finished with exit code 1
Environment:
kubectl version
):python --version
)