Skip to content

danielloeh/pykube

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pykube

image

image

image

image

image

Python client library for Kubernetes

image

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"}},
)

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

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.

About

Python client library for Kubernetes

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%