kubernetes-client / python

Official Python client library for kubernetes
http://kubernetes.io/
Apache License 2.0
6.6k stars 3.25k forks source link

Support for Ephemeral Containers in Running Pods via Python Kubernetes Client 通过Python Kubernetes客户端在运行中的Pods里支持临时容器 #2207

Open cdxiaodong opened 4 months ago

cdxiaodong commented 4 months ago

Title(标题): Support for Ephemeral Containers in Running Pods via Python Kubernetes Client

通过Python Kubernetes客户端在运行中的Pods里支持临时容器

Background(背景): In the current Kubernetes Python client library, there seems to be no straightforward method to add ephemeral containers to running Pods. The existing method patch_namespaced_pod does not dynamically create an ephemeral container in the running Pods as expected. This feature is crucial for debugging purposes and aligns with Kubernetes' evolving capabilities.

在当前的Kubernetes Python客户端库中,似乎没有直接的方法可以在运行中的Pods中添加临时容器。现有的方法patch_namespaced_pod并不像预期那样在运行中的Pods中动态创建一个临时容器。这个功能对于调试目的非常关键,并且符合Kubernetes不断发展的能力。

Issue(问题): Currently, attempting to use patch_namespaced_pod to add ephemeral containers does not result in the containers being created in the running Pods. This limits the debugging capabilities and deviates from the expected functionality provided by Kubernetes natively.

当前,尝试使用patch_namespaced_pod来添加临时容器并不会导致在运行中的Pods创建这些容器。这限制了调试能力,并且偏离了Kubernetes原生提供的预期功能。

Conclusion(结论): It would be beneficial for the Python Kubernetes client to support a dedicated method for adding ephemeral containers to running Pods, similar to the kubectl debug command, enhancing the debugging process and maintaining alignment with Kubernetes' native features.

如果Python Kubernetes客户端能支持一个专门的方法来向运行中的Pods添加临时容器,类似于kubectl debug命令,将有助于增强调试过程,并保持与Kubernetes原生功能的一致性,这将是非常有益的。

image

roycaihw commented 4 months ago

Is this feature supported on the server side? This doesn't seem to be a client issue.

abhitrip07 commented 3 months ago

+1, I think the author is referring to the kubectl debug API https://kubernetes.io/docs/reference/kubectl/generated/kubectl_debug/

roycaihw commented 3 months ago

/help

Thanks for the explanation. This project is mainly a client library. We didn't aim for feature parity comparing to kubectl which is a CLI tool. We do have some utility methods which support enhanced experience: https://github.com/kubernetes-client/python/tree/master/kubernetes/utils

k8s-ci-robot commented 3 months ago

@roycaihw: This request has been marked as needing help from a contributor.

Guidelines

Please ensure that the issue body includes answers to the following questions:

For more details on the requirements of such an issue, please see here and ensure that they are met.

If this request no longer meets these requirements, the label can be removed by commenting with the /remove-help command.

In response to [this](https://github.com/kubernetes-client/python/issues/2207): >/help > >Thanks for the explanation. This project is mainly a client library. We didn't aim for feature parity comparing to kubectl which is a CLI tool. We do have some utility methods which support enhanced experience: https://github.com/kubernetes-client/python/tree/master/kubernetes/utils Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.
hjzccc commented 1 month ago

Hi, I think the api actually works, the "ephemeralContainers" field should be in the "spec" field:

patch_body = {
    "spec": {
        "ephemeralContainers": [
            body
        ]
    }
}

response=v1.patch_namespaced_pod_ephemeralcontainers(
    name=pod_name,
    namespace=pod_namespace,
    body=patch_body
)
cdxiaodong commented 3 weeks ago

yes actually i resolve this question on APril. sorry for what i havent said that