Skip to main content
Warning: You are using the test version of PyPI. This is a pre-production deployment of Warehouse. Changes made here affect the production instance of TestPyPI (testpypi.python.org).
Help us improve Python packaging - Donate today!

A python module for Kubernetes.

Project Description

A python module to use Kubernetes. Currently based on the version 1 of the API.

Currently supported Kubernetes objects:

  • Pod
  • ReplicationController
  • Secret
  • Service

Usage

Until proper documentation is made, please find some code snippets to help understand how to use this module.

Pod

Creating a pod:

from kubernetes import K8sConfig
from kubernetes import K8sPod
from kubernetes import K8sContainer

that_cfg = K8sConfig(api_host='somehost:8888')
that_pod = K8sPod(config=that_cfg, name='redis')
that_pod.add_container(container=K8sContainer(name='redis', image='library/redis:2')
                      .add_port(container_port=6379, host_port=31010, name='redismasterport'))
that_pod.create()

Fetching a pod:

from kubernetes import K8sConfig
from kubernetes import K8sPod

that_cfg = K8sConfig(api_host='somehost:8888')
that_pod = K8sPod(config=that_cfg, name='redis')
that_pod.get()

Deleting a pod:

from kubernetes import K8sConfig
from kubernetes import K8sPod

that_cfg = K8sConfig(api_host='somehost:8888')
that_pod = K8sPod(config=that_cfg, name='redis')
that_pod.get()
that_pod.delete()

ReplicationController

Creating a replication controller:

from kubernetes import K8sConfig
from kubernetes import K8sReplicationController

that_cfg = K8sConfig(api_host='somehost:8888')
that_rc = K8sReplicationController(config=that_cfg, name='redis', image='library/redis:2', replicas=1)
that_rc.create()

Fetching a replication controller:

from kubernetes import K8sConfig
from kubernetes import K8sReplicationController

that_cfg = K8sConfig(api_host='somehost:8888')
that_rc = K8sReplicationController(config=that_cfg, name='redis')
that_rc.get()

Deleting a replication controller:

from kubernetes import K8sConfig
from kubernetes import K8sReplicationController

that_cfg = K8sConfig(api_host='somehost:8888')
that_rc = K8sReplicationController(config=that_cfg, name='redis')
that_rc.get()
that_rc.delete()

Service

Creating a service:

from kubernetes import K8sConfig
from kubernetes import K8sService

that_cfg = K8sConfig(api_host='somehost:8888')
that_svc = K8sService(config=that_cfg, name='redis')\
    .add_port(name='redisport', port=31010, target_port='redisport')\
    .add_selector(selector=dict(name='redis'))\
    .set_cluster_ip('192.168.1.100')
that_svc.create()

Fetching a service:

from kubernetes import K8sConfig
from kubernetes import K8sService

that_cfg = K8sConfig(api_host='somehost:8888')
that_svc = K8sService(config=that_cfg, name='redis')
that_svc.get()

Deleting a service:

from kubernetes import K8sConfig
from kubernetes import K8sService

that_cfg = K8sConfig(api_host='somehost:8888')
that_svc = K8sService(config=that_cfg, name='redis')
that_svc.get()
that_svc.delete()

Secret

Creating a secret:

from kubernetes import K8sConfig
from kubernetes import K8sSecret

that_cfg = K8sConfig(api_host='somehost:8888')
that_secret = K8sSecret(config=that_cfg, name='myregistry')\
    .set_dockercfg_secret(data='{"somehost":{"auth":"bW81Ym8fZG7ja2HyOmMvY2tlcmZvhm1UdWovMJIR",'
                               '"email":"email@company.com"}}')
that_secret.create()

Fetching a secret:

from kubernetes import K8sConfig
from kubernetes import K8sSecret

that_cfg = K8sConfig(api_host='somehost:8888')
that_secret = K8sSecret(config=that_cfg, name='myregistry')
that_secret.get()

Deleting a secret:

from kubernetes import K8sConfig
from kubernetes import K8sSecret

that_cfg = K8sConfig(api_host='somehost:8888')
that_secret = K8sSecret(config=that_cfg, name='myregistry')
that_secret.get()
that_secret.delete()
Release History

Release History

This version
History Node

0.1

Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
kubernetes-py-0.1.tar.gz (12.9 kB) Copy SHA256 Checksum SHA256 Source Jan 23, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting