Skip to main content
Help us improve Python packaging – donate today!

Opinionated interface for the Kubernetes API

Project Description

Opinionated Python interface for the Kubernetes API

This package provides a Pythonic interface to use the Kubernetes API from within Python code. It is hand-crafted and opinionated in an attempt to hide the edge cases and cumbersome parts of the raw API which would be exposed by a client using the swagger definitions.

This package is far from finished, the current major features are:

  • Major resources wrapped: - Nodes - Namespaces - Pods - ReplicaSets/ReplicationControllers - Services - Secrets
  • Good labelling support
  • Both blocking and non-blocking support for the WATCH API.
  • Low-level API to use Kubernetes API more directly.
  • Write tests without needing a real cluster

Installation

pip install kube

Usage

To use the API one has to authenticate to the Kubernetes apiserver. Currently only the recommended approach of using kubectl in proxy mode is supported. Simply run kubectl proxy on the localhost and the connection will work. When running in a cluster itself this can be easily achieved by running the kubectl proxy in an other container in the same pod.

The central object to work with the Kubernetes cluster is the Cluster object:

import kube

cluster = kube.Cluster()
rs = cluster.replicasets.fetch('proxy', namespace='default')
pods = cluster.pods.filter(labels=rs.meta.labels,
                           filter={'metadata.namespace': 'default'})
for pod in pods:
   assert pod.phase is pod.PodPhase.Running

For more details on the API and concepts used please refer to the documentation included.

Contributing

The project is still in it’s early stages, feel free to submit suggestions, issues or pull requests to the project. https://bitbucket.org/cobeio/kube All feedback is welcome.

Deveopment Dependencies

When developing kube you will need some extra dependencies:

  • pytest
  • pytest-cov
  • pylint
  • invoke

Testing Kube

The tests can both be run with a stubbed-out API server as against a real Kubernetes cluster. The former runs very fast and will not mess around with a real cluster. The later is a bit slower but can be used to verify that the code behaves correctly against a real Kubernetes cluster. By default the tests will use the stubbed-out apiserver, to run the tests against a real cluster ensure you have kubectl proxy running and invoke the tests with py.test --verify. The tests will try to not break your cluster or leave any artefacts around after the test run, but use at your own risk obviously.

Release history Release notifications

History Node

0.10.0

History Node

0.9.1

History Node

0.9.0

This version
History Node

0.8.0

History Node

0.1.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
kube-0.8.0-py3-none-any.whl (38.8 kB) Copy SHA256 hash SHA256 Wheel py3 May 17, 2016
kube-0.8.0.tar.gz (40.1 kB) Copy SHA256 hash SHA256 Source None May 17, 2016

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page