Skip to main content

pykube

http://slack.kelproject.com/badge.svg https://img.shields.io/travis/kelproject/pykube.svg https://img.shields.io/pypi/dm/pykube.svg https://img.shields.io/pypi/v/pykube.svg https://img.shields.io/badge/license-apache-blue.svg

Python client library for Kubernetes

https://storage.googleapis.com/kel-assets/kel_full-02_200.jpg

Kel is an open source Platform as a Service (PaaS) from Eldarion, Inc. that makes it easy to manage web application deployment and hosting through the entire lifecycle from development through testing to production. It adds components and tools on top of Kubernetes that help developers manage their application infrastructure. Kel builds on Eldarion’s 7+ years experience running one of the leading Python and Django PaaSes.

For more information about Kel, see kelproject.com, follow us on Twitter @projectkel, and join our Slack team.

Features

  • HTTP interface using requests using kubeconfig for authentication

  • Python native querying of Kubernetes API objects

Installation

To install pykube, use pip:

pip install pykube

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)

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")
    .filter(field_selector={"metadata.name":"my-job"})
    .watch()

# watch is a generator:
for watch_event in watch:
    print(watch.type) # 'ADDED', 'DELETED', 'MODIFIED'
    print(watch.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

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).

Code of Conduct

In order to foster a kind, inclusive, and harassment-free community, the Kel Project follows the Contributor Covenant Code of Conduct.

Commercial Support

Commercial support for Kel is available through Eldarion, please contact info@eldarion.com.

Release files for pykube 0.15.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pykube 0.15.0
File Size Uploaded
pykube-0.15.0.tar.gz 18.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pykube 0.15.0
File Interpreter ABI Platform
pykube-0.15.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 41.3 kB

Release files / pykube-0.15.0.tar.gz

Download URL pykube-0.15.0.tar.gz
Size 18.1 kB
Tags Source
SHA-256 checksum
How to use checksums
e53800d0d45f13911aa4ebca8463ae5cc82afad461f6575a0a217d2fce5f088b
BLAKE2b-256 checksum
How to use checksums
a24059fe3425a3d4ac4a41f8d99e71f4862b1c3aaaa99f61afd50ff37f39dae2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / pykube-0.15.0-py2.py3-none-any.whl

Download URL pykube-0.15.0-py2.py3-none-any.whl
Size 23.2 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
8d50b09b63d5e754f3379032be58bed035692e2e308a0b35e57b0074b3f90bb9
BLAKE2b-256 checksum
How to use checksums
9fc53e8fe74618f1ca5a4b7735a163ad0479e24a26137b99ea1739d9d32602f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.15.0 This release

2 release files

0.14.0

2 release files

0.13.0

2 release files

0.11.3

2 release files

0.11.2

2 release files

0.11.1

2 release files

0.11.0

2 release files

0.9.0

1 release file

0.8.2

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.3

2 release files

0.7.2

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.1

2 release files

0.6.0

1 release file

0.5.1

1 release file

0.5.0

1 release file

0.4.0

1 release file

0.3.0

1 release file

0.2.0

1 release file

0.1.0

1 release file

0.1a1

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page