Giter Site home page Giter Site logo

kubeshift's Introduction

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.

Features:

  • 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 https://github.com/cdrage/kubeshift && cd kubeshift
make install

Python requirements

▶ cat requirements.txt
PyYAML
requests

Public APIs

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

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

# Client connection
k8s_client = kubeshift.KubernetesClient(config)
oc_client = kubeshift.OpenshiftClient(config)

Named Query methods

API calls are also available via their corresponding method. Each call returns a Query object used to retrieve and filter.

Methods Sourced through discovery

  • http://localhost:8080/apis
  • http://localhost:8080/oapi

Full example:

import kubeshift
import getpass

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

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

# 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
client.namespaces().all()

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

kubeshift's People

Contributors

ashetty1 avatar cdrage avatar shad7 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.