Kubernetes Python Client

Build Status PyPI version codecov pypi status pypi supported versions

Python client for the kubernetes API.

Installation

From source:

git clone https://github.com/kubernetes-incubator/client-python.git
cd client-python
python setup.py install

From PyPi directly:

pip install kubernetes

Example

list all pods:

from kubernetes import client, config

# Configs can be set in Configuration class directly or using helper utility
config.load_kube_config()

v1=client.CoreV1Api()
print("Listing pods with their IPs:")
ret = v1.list_pod_for_all_namespaces(watch=False)
for i in ret.items:
    print("%s\t%s\t%s" % (i.status.pod_ip, i.metadata.namespace, i.metadata.name))

watch on namespace object:

from kubernetes import client, config, watch

# Configs can be set in Configuration class directly or using helper utility
config.load_kube_config()

v1 = client.CoreV1Api()
count = 10
w = watch.Watch()
for event in w.stream(v1.list_namespace, _request_timeout=60):
    print("Event: %s %s" % (event['type'], event['object'].metadata.name))
    count -= 1
    if not count:
        w.stop()

print("Ended.")

More examples can be found in examples folder. To run examples, run this command:

python -m examples.example1

(replace example1 with the example base filename)

Documentation

All APIs and Models' documentation can be found at the Generated client's README file

Community, Support, Discussion

You can reach the maintainers of this project at SIG API Machinery. If you have any problem with the package or any suggestions, please file an issue.

Code of Conduct

Participation in the Kubernetes community is governed by the CNCF Code of Conduct.

Kubernetes Incubator

This is a Kubernetes Incubator project.

Troubleshooting

SSLError on macOS

If you get an SSLError, you likely need to update your version of python. The version that ships with macOS may not be supported.

Install the latest version of python with brew:

brew install python

Once installed, you can query the version of OpenSSL like so:

python -c "import ssl; print ssl.OPENSSL_VERSION"

You'll need a version with OpenSSL version 1.0.0 or later.

Hostname doesn't match

If you get an ssl.CertificateError complaining about hostname match, your installed packages does not meet version requirements. Specifically check ipaddress and urllib3 package versions to make sure they met requirements in requirements.txt file.



Kubernetes Python Client

构建状态data-canonical-src codecov 状态的PyPI PyPI中支持的版本

kubernetes API的Python客户端。

安装

来源:

git clone https://github.com/kubernetes-incubator/client-python.git
cd client-python
python setup.py install

直接从 PyPi

pip install kubernetes

示例

列出所有pod:

from kubernetes import client, config

# Configs can be set in Configuration class directly or using helper utility config.load_kube_config()

v1=client.CoreV1Api() print("Listing pods with their IPs:") ret = v1.list_pod_for_all_namespaces(watch=False) for i in ret.items: print("%s\t%s\t%s" % (i.status.pod_ip, i.metadata.namespace, i.metadata.name))

观看命名空间对象:

from kubernetes import client, config, watch

# Configs can be set in Configuration class directly or using helper utility config.load_kube_config()

v1 = client.CoreV1Api() count = 10 w = watch.Watch() for event in w.stream(v1.list_namespace, _request_timeout=60): print("Event: %s %s" % (event['type'], event['object'].metadata.name)) count -= 1 if not count: w.stop()

print("Ended.")

可以在示例文件夹中找到更多示例。要运行示例,请运行以下命令:

python -m examples.example1

(将example1替换为示例基本文件名)

文件

所有API和模型的文档可以在生成的客户端的README文件找到

社区,支持讨论

您可以通过 SIG API机械与本项目的维护人员联系。如果您对该软件包有任何问题或任何建议,请提交问题

行为准则

参与Kubernetes社区由 CNCF行为准则管理。

Kubernetes孵化器

这是 Kubernetes孵化器项目

故障排除

关于macOS的SSLError

如果您获得SSLError,您可能需要更新您的Python版本。的 MacOS附带的版本可能不受支持。

使用 brew 安装最新版本的python:

brew install python

安装完成后,您可以查询OpenSSL的版本:

python -c "import ssl; print ssl.OPENSSL_VERSION"

您将需要具有OpenSSL 1.0.0或更高版本的版本。

主机名不’ t匹配

如果您收到主机名匹配的 ssl.CertificateError ,则您安装的软件包不符合版本要求。 具体检查 ipaddress urllib3 包版本,以确保他们符合 requirements.txt 文件。




相关问题推荐