Giter VIP home page Giter VIP logo

kr8s's Introduction

Test Codecov pre-commit.ci status Read the Docs PyPI PyPI - Python Version Kubernetes Version Support PyPI - Wheel PyPI - License

A simple, extensible Python client library for Kubernetes that feels familiar for folks who already know how to use kubectl.

Highlights

  • API inspired by kubectl to reduce developer learning curve.
  • Sensible defaults to reduce boiler plate.
  • No swagger generated code, human readable code only.
  • Also has an asynchronous API that can be used with asyncio and trio.
  • Client caching to reduce passing API objects around.
  • Batteries included by providing useful utilities and methods inspired by kubectl.

Quickstart

Installation

$ pip install kr8s

Examples

See the Examples Documentation for a full set of examples including asyncio examples.

List Nodes

Print out all of the node names in the cluster.

import kr8s

for node in kr8s.get("nodes"):
    print(node.name)

Create a Pod

Create a new Pod.

from kr8s.objects import Pod

pod = Pod({
        "apiVersion": "v1",
        "kind": "Pod",
        "metadata": {
            "name": "my-pod",
        },
        "spec": {
            "containers": [{"name": "pause", "image": "gcr.io/google_containers/pause",}]
        },
    })

pod.create()

Scale a Deployment

Scale the Deployment metrics-server in the Namespace kube-system to 1 replica.

from kr8s.objects import Deployment

deploy = Deployment.get("metrics-server", namespace="kube-system")
deploy.scale(1)

List Pods by label selector

Get all Pods from all Namespaces matching a label selector.

import kr8s

selector = {'component': 'kube-scheduler'}

for pod in kr8s.get("pods", namespace=kr8s.ALL, label_selector=selector):
    print(pod.namespace, pod.name)

Add a label to a Pod

Add the label foo with the value bar to an existing Pod.

from kr8s.objects import Pod

pod = Pod("kube-apiserver", namespace="kube-system")
pod.label({"foo": "bar"})

Cordon a Node

Cordon a Node to mark it as unschedulable.

from kr8s.objects import Node

node = Node("k8s-node-1")

node.cordon()
# Is equivalent to
# node.patch({"spec": {"unschedulable": True}})

kr8s's People

Contributors

jacobtomlinson avatar pre-commit-ci[bot] avatar kr8s-bot avatar droctothorpe avatar bpartridge avatar saghen avatar

Watchers

 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.