Skip to main content

A universal python library for container orchestrators

Project description

# Kubeshift
[![Build Status](](
[![Coverage Status](](

## Introduction

_Kubeshift_ is a multi-provider Python library for Kubernetes (Kube) and Openshift (shift). We connect and communicate with each container orchestator 100% through their TLS (if available) HTTP API.


- 100% HTTP API
- Auto-parsing of `~/.kube/config`
- `.kube/config` generation
- TLS authentication
- 100% test coverage with functional and integration tests

## Library installation

#### Pip
sudo pip install kubeshift

#### Manual / development
git clone && cd kubeshift
make install

## Python requirements

▶ cat requirements.txt

## Methods and examples

#### Configuration import

The configuration file used with the provider must be an _object_. Currently we support the import and generation of Kubernetes and OpenShift configuration files .

import kubeshift

# Import the configuration, this can be either from a file
config = kubeshift.Config.from_file("/home/user/.kube/config")
client = kubeshift.Client(config, "kubernetes")

# Or generated via a set of parameters
config_params = kubeshift.Config.from_params(api="https://localhost:8080", auth="foobar", ca="/home/user/.kube/ca.cert", verify=True)
client = kubeshift.Client(config_params, "kubernetes")

#### Implemented methods

**The main methods for each provider are:**
.scale(object, namespace="default", replicas=0)

API calls are also available via their corresponding method. Each call returns a dictionary object container all information. These methods are created from the list of calls at `http://localhost:8080/apis`. Some calls *require* namespace to be provided. Otherwise, 'default' will be used.

**API call methods:**

**Namespaced API call methods:**

**These API calls can further be filtered via these methods:**
.filter(namespace="foo", status="Running")

**Full example:**
import kubeshift
import getpass

# Example k8s object
k8s_object = {"apiVersion": "v1", "kind": "Pod", "metadata": {"labels": {"app": "helloapache"}, "name": "helloapache"}, "spec": {
"containers": [{"image": "nginx", "name": "helloapache", "ports": [{"containerPort": 80, "hostPort": 80, "protocol": "TCP"}]}]}}

# Client configuration
user = getpass.getuser()
config = kubeshift.Config.from_file("/home/%s/.kube/config" % user)
client = kubeshift.Client(config, "kubernetes")

# Main methods
client.create(k8s_object) # Creates the k8s object
# client.scale(k8s_object, replicas=3) # Scales the k8s object (if it's a service)
client.delete(k8s_object) # Deletes the k8s object

# API calls

# Namespaces

# Pods
client.pods().filter(namespace="default", status="Running")

Project details

Download files

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

Source Distribution

kubeshift-0.0.4.tar.gz (13.8 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page