kr8s


Namekr8s JSON
Version 0.18.0 PyPI version JSON
download
home_pageNone
SummaryA Kubernetes API library
upload_time2024-11-03 10:35:17
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseBSD-3-Clause
keywords kubectl kubernetes
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <div style="text-align: center; width: 100%;"><img src="https://github.com/kr8s-org/kr8s/raw/v0.17.2/branding/logo-wide.png" style="max-height: 200px;" /></div>

[![Test](https://github.com/kr8s-org/kr8s/actions/workflows/test-kr8s.yaml/badge.svg)](https://github.com/kr8s-org/kr8s/actions/workflows/test.yaml)
[![Codecov](https://img.shields.io/codecov/c/gh/kr8s-org/kr8s?logo=codecov&logoColor=ffffff)](https://app.codecov.io/gh/kr8s-org/kr8s)
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/kr8s-org/kr8s/main.svg)](https://results.pre-commit.ci/latest/github/kr8s-org/kr8s/main)
[![Read the Docs](https://img.shields.io/readthedocs/kr8s?logo=readthedocs&logoColor=white)](https://docs.kr8s.org/en/stable/)
[![EffVer Versioning](https://img.shields.io/badge/version_scheme-EffVer-0097a7)](https://jacobtomlinson.dev/effver)
[![PyPI](https://img.shields.io/pypi/v/kr8s)](https://pypi.org/project/kr8s/)
[![Python Version Support](https://img.shields.io/badge/Python%20support-3.8%7C3.9%7C3.10%7C3.11%7C3.12-blue)](https://pypi.org/project/kr8s/)
[![Kubernetes Version Support](https://img.shields.io/badge/Kubernetes%20support-1.29%7C1.30%7C1.31-blue)](https://docs.kr8s.org/en/stable/installation.html#supported-kubernetes-versions)
[![PyPI - Wheel](https://img.shields.io/pypi/wheel/kr8s)](https://pypi.org/project/kr8s/)
[![PyPI - License](https://img.shields.io/pypi/l/kr8s)](https://pypi.org/project/kr8s/)

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` for a shallow learning curve.
- [Sensible defaults](https://docs.kr8s.org/en/stable/authentication.html) to reduce boiler plate.
- No swagger generated code, human readable code only.
- Has both a standard and an [async API](https://docs.kr8s.org/en/stable/asyncio.html) that can be used with `asyncio` and `trio`.
- [Client caching](https://docs.kr8s.org/en/stable/client.html#client-caching) to reduce passing API objects around.
- Batteries included by providing [useful utilities and methods](https://docs.kr8s.org/en/stable/examples/pod_operations.html) inspired by `kubectl`.

## Quickstart

### Installation

```console
$ pip install kr8s
```

## Examples

> [!TIP]
> See the [Examples Documentation](https://docs.kr8s.org/en/stable/examples/) for a full set of examples including `asyncio` examples.

### List Nodes

Print out all of the node names in the cluster.

```python
import kr8s

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

### Create a Pod

Create a new Pod.

```python
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.

```python
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.

```python
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.

```python
from kr8s.objects import Pod

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

### Generate a Pod

Generate a simple Pod with a couple of keyword arguments.

```python
from kr8s.objects import Pod

pod = Pod.gen(name="example-1", image="nginx:latest")
pod.create()
```

### Cordon a Node

Cordon a Node to mark it as unschedulable.

```python
from kr8s.objects import Node

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

node.cordon()
```

### Pod Exec

Exec a command in a Pod.

```python
from kr8s.objects import Pod

pod = Pod.get("my-pod")

command = pod.exec(["uptime"])
print(command.stdout.decode())
# 13:49:05 up 23:03,  0 users,  load average: 0.66, 0.87, 0.85
```

### Port forward a Pod

Open a port forward to a Pod as a background task/thread.

```python
from kr8s.objects import Pod

pod = Pod.get("my-pod")
pf = pod.portforward(remote_port=1234, local_port=5678)

# Starts the port forward in a background thread
pf.start()

# Your other code goes here

# Optionally stop the port forward thread (it will exit with Python anyway)
pf.stop()
```

> [!TIP]
> See the [Examples Documentation](https://docs.kr8s.org/en/stable/examples/) for a full set of examples including `asyncio` examples.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "kr8s",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "kubectl, kubernetes",
    "author": null,
    "author_email": "Jacob Tomlimson <jacob@tomlinson.email>",
    "download_url": "https://files.pythonhosted.org/packages/42/04/9f3270f1ce981370b97cd29db187d5d7b5881dd1f4b650458ac2fe581945/kr8s-0.18.0.tar.gz",
    "platform": null,
    "description": "<div style=\"text-align: center; width: 100%;\"><img src=\"https://github.com/kr8s-org/kr8s/raw/v0.17.2/branding/logo-wide.png\" style=\"max-height: 200px;\" /></div>\n\n[![Test](https://github.com/kr8s-org/kr8s/actions/workflows/test-kr8s.yaml/badge.svg)](https://github.com/kr8s-org/kr8s/actions/workflows/test.yaml)\n[![Codecov](https://img.shields.io/codecov/c/gh/kr8s-org/kr8s?logo=codecov&logoColor=ffffff)](https://app.codecov.io/gh/kr8s-org/kr8s)\n[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/kr8s-org/kr8s/main.svg)](https://results.pre-commit.ci/latest/github/kr8s-org/kr8s/main)\n[![Read the Docs](https://img.shields.io/readthedocs/kr8s?logo=readthedocs&logoColor=white)](https://docs.kr8s.org/en/stable/)\n[![EffVer Versioning](https://img.shields.io/badge/version_scheme-EffVer-0097a7)](https://jacobtomlinson.dev/effver)\n[![PyPI](https://img.shields.io/pypi/v/kr8s)](https://pypi.org/project/kr8s/)\n[![Python Version Support](https://img.shields.io/badge/Python%20support-3.8%7C3.9%7C3.10%7C3.11%7C3.12-blue)](https://pypi.org/project/kr8s/)\n[![Kubernetes Version Support](https://img.shields.io/badge/Kubernetes%20support-1.29%7C1.30%7C1.31-blue)](https://docs.kr8s.org/en/stable/installation.html#supported-kubernetes-versions)\n[![PyPI - Wheel](https://img.shields.io/pypi/wheel/kr8s)](https://pypi.org/project/kr8s/)\n[![PyPI - License](https://img.shields.io/pypi/l/kr8s)](https://pypi.org/project/kr8s/)\n\nA simple, extensible Python client library for Kubernetes that feels familiar for folks who already know how to use `kubectl`.\n\n## Highlights\n\n- API inspired by `kubectl` for a shallow learning curve.\n- [Sensible defaults](https://docs.kr8s.org/en/stable/authentication.html) to reduce boiler plate.\n- No swagger generated code, human readable code only.\n- Has both a standard and an [async API](https://docs.kr8s.org/en/stable/asyncio.html) that can be used with `asyncio` and `trio`.\n- [Client caching](https://docs.kr8s.org/en/stable/client.html#client-caching) to reduce passing API objects around.\n- Batteries included by providing [useful utilities and methods](https://docs.kr8s.org/en/stable/examples/pod_operations.html) inspired by `kubectl`.\n\n## Quickstart\n\n### Installation\n\n```console\n$ pip install kr8s\n```\n\n## Examples\n\n> [!TIP]\n> See the [Examples Documentation](https://docs.kr8s.org/en/stable/examples/) for a full set of examples including `asyncio` examples.\n\n### List Nodes\n\nPrint out all of the node names in the cluster.\n\n```python\nimport kr8s\n\nfor node in kr8s.get(\"nodes\"):\n    print(node.name)\n```\n\n### Create a Pod\n\nCreate a new Pod.\n\n```python\nfrom kr8s.objects import Pod\n\npod = Pod({\n        \"apiVersion\": \"v1\",\n        \"kind\": \"Pod\",\n        \"metadata\": {\n            \"name\": \"my-pod\",\n        },\n        \"spec\": {\n            \"containers\": [{\"name\": \"pause\", \"image\": \"gcr.io/google_containers/pause\",}]\n        },\n    })\n\npod.create()\n```\n\n### Scale a Deployment\n\nScale the Deployment `metrics-server` in the Namespace `kube-system` to `1` replica.\n\n```python\nfrom kr8s.objects import Deployment\n\ndeploy = Deployment.get(\"metrics-server\", namespace=\"kube-system\")\ndeploy.scale(1)\n```\n\n### List Pods by label selector\n\nGet all Pods from all Namespaces matching a label selector.\n\n```python\nimport kr8s\n\nselector = {'component': 'kube-scheduler'}\n\nfor pod in kr8s.get(\"pods\", namespace=kr8s.ALL, label_selector=selector):\n    print(pod.namespace, pod.name)\n```\n\n### Add a label to a Pod\n\nAdd the label `foo` with the value `bar` to an existing Pod.\n\n```python\nfrom kr8s.objects import Pod\n\npod = Pod(\"kube-apiserver\", namespace=\"kube-system\")\npod.label({\"foo\": \"bar\"})\n```\n\n### Generate a Pod\n\nGenerate a simple Pod with a couple of keyword arguments.\n\n```python\nfrom kr8s.objects import Pod\n\npod = Pod.gen(name=\"example-1\", image=\"nginx:latest\")\npod.create()\n```\n\n### Cordon a Node\n\nCordon a Node to mark it as unschedulable.\n\n```python\nfrom kr8s.objects import Node\n\nnode = Node(\"k8s-node-1\")\n\nnode.cordon()\n```\n\n### Pod Exec\n\nExec a command in a Pod.\n\n```python\nfrom kr8s.objects import Pod\n\npod = Pod.get(\"my-pod\")\n\ncommand = pod.exec([\"uptime\"])\nprint(command.stdout.decode())\n# 13:49:05 up 23:03,  0 users,  load average: 0.66, 0.87, 0.85\n```\n\n### Port forward a Pod\n\nOpen a port forward to a Pod as a background task/thread.\n\n```python\nfrom kr8s.objects import Pod\n\npod = Pod.get(\"my-pod\")\npf = pod.portforward(remote_port=1234, local_port=5678)\n\n# Starts the port forward in a background thread\npf.start()\n\n# Your other code goes here\n\n# Optionally stop the port forward thread (it will exit with Python anyway)\npf.stop()\n```\n\n> [!TIP]\n> See the [Examples Documentation](https://docs.kr8s.org/en/stable/examples/) for a full set of examples including `asyncio` examples.\n",
    "bugtrack_url": null,
    "license": "BSD-3-Clause",
    "summary": "A Kubernetes API library",
    "version": "0.18.0",
    "project_urls": {
        "Changelog": "https://github.com/kr8s-org/kr8s/releases",
        "Documentation": "https://docs.kr8s.org/en/stable",
        "Issues": "https://github.com/kr8s-org/kr8s/issues",
        "Repository": "https://github.com/kr8s-org/kr8s.git"
    },
    "split_keywords": [
        "kubectl",
        " kubernetes"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ba07211062c36f9e7c2d2df8fd72c34a6c779b6d2acc1bc41e2db423decfe104",
                "md5": "91c78b6737374d46e9072bb06672ff30",
                "sha256": "2edb2496fed4e4501b4e8de66067302ddd5be7e576c6f62aec7289839148e002"
            },
            "downloads": -1,
            "filename": "kr8s-0.18.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "91c78b6737374d46e9072bb06672ff30",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 71212,
            "upload_time": "2024-11-03T10:35:14",
            "upload_time_iso_8601": "2024-11-03T10:35:14.897325Z",
            "url": "https://files.pythonhosted.org/packages/ba/07/211062c36f9e7c2d2df8fd72c34a6c779b6d2acc1bc41e2db423decfe104/kr8s-0.18.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "42049f3270f1ce981370b97cd29db187d5d7b5881dd1f4b650458ac2fe581945",
                "md5": "e6ce8acdcbebd3c52efba39bf99f59d6",
                "sha256": "00a1517bfe3b05d9c245885f08961d17e2fbd816c2e31f5ff910d5f3788393c0"
            },
            "downloads": -1,
            "filename": "kr8s-0.18.0.tar.gz",
            "has_sig": false,
            "md5_digest": "e6ce8acdcbebd3c52efba39bf99f59d6",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 2852501,
            "upload_time": "2024-11-03T10:35:17",
            "upload_time_iso_8601": "2024-11-03T10:35:17.421703Z",
            "url": "https://files.pythonhosted.org/packages/42/04/9f3270f1ce981370b97cd29db187d5d7b5881dd1f4b650458ac2fe581945/kr8s-0.18.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-03 10:35:17",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "kr8s-org",
    "github_project": "kr8s",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "kr8s"
}
        
Elapsed time: 3.39951s