pykubeks
This is a fork of pykube which is no longer maintained. If you are interested in who brought that lovely little library into the world, please check out The Kel Project.
The reason for this fork is to release the AWS EKS support I wrote for
the original project, before it was abandoned. The new name pykubeks
is a portmanteau of pykube and EKS.
The python package name is still the same to make it simpler to "upgrade" to this new version which supports user credentials supplied from client-go credential plugins. See k8s documentation for details.
Features
- HTTP interface using requests using kubeconfig for authentication
- Python native querying of Kubernetes API objects
Installation
To install pykubeks, use pip:
pip install pykubeks
Usage
Query for all ready pods in a custom namespace:
import operator
import pykube
api = pykube.HTTPClient(pykube.KubeConfig.from_file("/Users/<username>/.kube/config"))
pods = pykube.Pod.objects(api).filter(namespace="gondor-system")
ready_pods = filter(operator.attrgetter("ready"), pods)
Access any attribute of the Kubernetes object:
pod = pykube.Pod.objects(api).filter(namespace="gondor-system").get(name="my-pod")
pod.obj["spec"]["containers"][0]["image"]
Selector query:
pods = pykube.Pod.objects(api).filter(
namespace="gondor-system",
selector={"gondor.io/name__in": {"api-web", "api-worker"}},
)
pending_pods = pykube.objects.Pod.objects(api).filter(
field_selector={"status.phase": "Pending"}
)
Watch query:
watch = pykube.Job.objects(api, namespace="gondor-system")
watch = watch.filter(field_selector={"metadata.name": "my-job"}).watch()
# watch is a generator:
for watch_event in watch:
print(watch_event.type) # 'ADDED', 'DELETED', 'MODIFIED'
print(watch_event.object) # pykube.Job object
Create a ReplicationController:
obj = {
"apiVersion": "v1",
"kind": "ReplicationController",
"metadata": {
"name": "my-rc",
"namespace": "gondor-system"
},
"spec": {
"replicas": 3,
"selector": {
"app": "nginx"
},
"template": {
"metadata": {
"labels": {
"app": "nginx"
}
},
"spec": {
"containers": [
{
"name": "nginx",
"image": "nginx",
"ports": [
{"containerPort": 80}
]
}
]
}
}
}
}
pykube.ReplicationController(api, obj).create()
Delete a ReplicationController:
obj = {
"apiVersion": "v1",
"kind": "ReplicationController",
"metadata": {
"name": "my-rc",
"namespace": "gondor-system"
}
}
pykube.ReplicationController(api, obj).delete()
Check server version:
api = pykube.HTTPClient(pykube.KubeConfig.from_file("/Users/<username>/.kube/config"))
api.version
HTTPie
pykube can be used together with HTTPie for Kubernetes command line querying goodness. For example:
pip install httpie
http pykube://minikube/api/v1/services
The above example will construct an HTTP request to the cluster behind the minikube context and
show you the response containing all services.
Requirements
- Python 2.7 or 3.3+
- requests (included in
install_requires) - PyYAML (included in
install_requires)
License
The code in this project is licensed under the Apache License, version 2.0 (included in this repository under LICENSE).
Contributing
By making a contribution to this project, you are agreeing to the Developer Certificate of Origin v1.1 (also included in this repository under DCO.txt).
Developer Certificate of Origin v1.1
Code of Conduct
Contributor Covenant Code of Conduct
Commercial Support
No commercial support is available for this project.
Metadata
Release files for pykubeks 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pykubeks-0.1.0.tar.gz | 19.1 kB | Without provenance | Details for pykubeks-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pykubeks-0.1.0-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for pykubeks-0.1.0-py2.py3-none-any.whl |
Total release size: 46.6 kB
Release files / pykubeks-0.1.0.tar.gz
| Download URL | pykubeks-0.1.0.tar.gz |
|---|---|
| Size | 19.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0791b3f7fe1f5c8c8bb2685ec217498d30990f47292b5715b106f9390210010c
|
|
BLAKE2b-256 checksum How to use checksums |
9f23a43f15421a22efa46390990a93b3124193e2c7e50bfc90d2300a3401ba31
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6
|
Release files / pykubeks-0.1.0-py2.py3-none-any.whl
| Download URL | pykubeks-0.1.0-py2.py3-none-any.whl |
|---|---|
| Size | 27.5 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
a5ce56d5ebcf8c6c663ddd5f26683556bb4bacc3aceb3e71a0b0834bdb081e24
|
|
BLAKE2b-256 checksum How to use checksums |
629f65df7f2fad12d30a56a41f5a7504e58683d5ba687af550d398a9b8c95391
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6
|
Security for pykubeks 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.