Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to create deployment #2230

Open
Jicming opened this issue May 14, 2024 · 4 comments
Open

Failed to create deployment #2230

Jicming opened this issue May 14, 2024 · 4 comments
Labels
kind/bug Categorizes issue or PR as related to a bug. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.

Comments

@Jicming
Copy link

Jicming commented May 14, 2024

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 be None") # noqa: E501
ValueError: Invalid value for containers, must not be None

Process finished with exit code 1

Environment:

  • Kubernetes version (kubectl version):
  • OS (e.g., windows10):
  • Python 3.10.2 (python --version)
  • kubernetes 27.2.0
@Jicming Jicming added the kind/bug Categorizes issue or PR as related to a bug. label May 14, 2024
@showjason
Copy link
Contributor

showjason commented May 14, 2024

Issue #1662 can resolve this problem by disabling the client side validation
Why not follow this example

@roycaihw
Copy link
Member

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle stale
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Aug 20, 2024
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle rotten
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.
Projects
None yet
Development

No branches or pull requests

5 participants