kompatible
This package exposes a subset of the Kubernetes Python Client with an interface which matches that of the Docker SDK for Python.
Examples
First, checkout this project, and install dependencies:
pip install -r requirements-dev.txt.
Then, make sure you have installed and started
Docker
and/or Minikube
With those tools in place, either
import docker as sdk or import kompatible as sdk
and the following examples will work, although in the first case
it's Docker containers starting up,
and in the latter it's Kubernetes pods.
"Hello World!": Run, list, remove
>>> client = sdk.from_env()
>>> [client.containers.run(
... "alpine", "echo hello world",
... name='foobar',
... labels={'foo': 'bar'})]
[...'hello world\n']
>>> def not_kube(containers): # Only needed for Docker, on Travis, with k8s started.
... return [c for c in containers if 'kube' not in c.name]
>>> containers = not_kube(client.containers.list(all=True, filters={}))
>>> [c.name for c in containers]
[...'foobar']
>>> c = containers[0]
>>> c.remove(force=True, v=True)
>>> containers = not_kube(client.containers.list(all=True, filters={}))
>>> assert len(containers) == 0
Container properties
>>> assert c.id
>>> assert c.image
>>> c.labels
{...'foo': ...'bar'}
>>> assert c.short_id
>>> assert c.status
containers.run kwargs
Subclients
>>> assert client.api
>>> assert client.containers
>>> assert client.images
>>> assert client.volumes
TODO
client.api.base_url
client.containers.run(image_name,
name=container_spec.container_name,
ports={'{}/tcp'.format(container_spec.container_port): None},
detach=True,
labels=labels,
volumes=volumes,
nano_cpus=int(container_spec.cpus * 1e9),
environment=environment,
mem_reservation='{}M'.format(new_mem_reservation_mb))
client.containers.get(name_or_id)
container.logs(timestamps=True)
container.attrs['NetworkSettings']
container.attrs['Config']['Labels']
container.remove(force=True, v=True)
client.containers.list(all=True, filters=filters)
client.images
client.images.pull # Used by script, but not used by runtime.
# For Kubernetes, consider https://kubernetes.io/docs/concepts/containers/images/#pre-pulling-images
# We would need to make sure that every image is on every node we start up.
# Mayber other Container registries are faster than DockerHub, in which
# case pre-caching might be less important?
client.volumes
client.volumes.create(driver='local').name
Metadata
Release files for kompatible 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| kompatible-0.0.2.tar.gz | 5.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| kompatible-0.0.2-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Total release size: 11.3 kB
Release files / kompatible-0.0.2.tar.gz
| Download URL | kompatible-0.0.2.tar.gz |
|---|---|
| Size | 5.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
aafecbc5ffb3319d8d2fb1faa4fa1babef2fa5fa5a0a0cbc41f2786ff9fe4f3f
|
|
BLAKE2b-256 checksum How to use checksums |
fce212a51e86a74e76d0e5363b10d6c480ad81d483a18d65cbb0c482bbffc7c6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.3
|
Release files / kompatible-0.0.2-py2.py3-none-any.whl
| Download URL | kompatible-0.0.2-py2.py3-none-any.whl |
|---|---|
| Size | 6.2 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
f7a7cd56e07371e6bd69a559e7009906bb6da5dfe7e01f97b43ceee3da675201
|
|
BLAKE2b-256 checksum How to use checksums |
a8017af3cdb10a5de0f0b1138d97592f2581da3236ffe027abedb058105b5943
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.3
|