Skip to main content

Kubectl wrapper in Python with OAuth token auth

Project description

PyPI Downloads Latest PyPI version License

Kubernetes CLI (kubectl) wrapper in Python with OAuth token authentication.

This wrapper script zkubectl serves as a drop-in replacement for the kubectl binary:

  • it downloads the current kubectl binary from Google

  • it generates a new ~/.kube/config with an OAuth Bearer token acquired via zign.

  • it passes through commands to the kubectl binary

Installation

Requires Python 3.6+.

$ sudo pip3 install --upgrade zalando-kubectl

Usage

You can directly login to a known Kubernetes API server endpoint:

$ zkubectl login https://my-api-server.example.org
$ zkubectl cluster-info

You can also configure a Cluster Registry to look up clusters by ID:

$ zkubectl configure --cluster-registry=https://cluster-registry.example.org
$ zkubectl login my-cluster-id

The Cluster Registry needs to provide the following HTTP API for this to work:

$ curl -H "Authorization: Bearer $(zign tok)" https://cluster-registry.example.org/kubernetes-clusters/my-cluster-id
{
    "api_server_url": "https://my-api-server.example.org"
}

There is an additional convenience command to open the kube-web-view dashboard in the browser:

$ zkubectl dashboard
Opening https://kube-web-view.zalando.net/ ..

Unit Tests

Run unit tests with Tox:

$ sudo pip3 install tox
$ tox

Local Changes

It’s recommended to have a virtualenv for the project. The project uses Black for code formatting, please configure your editor to use it.

Go to the project dir and install dependencies into virtual test environment

$ cd <project-path>
# create new virtual environment if not yet
$ python -m venv test_environment
# enter virtual environment
$ source ./test_environment/bin/activate
# check pip is executed fron this virtual environment
(test_environment) $ which pip
<project-path>/test_environment/bin/pip

(test_environment) $ pip install -r requirements.txt
(test_environment) $ pip install --editable .

Now the code change will just be reflected in the zkubectl binary

(test_environment) $ zkubectl <whatever>

As an alternative for creating an environment you can run local changes from zalando_kubectl

$ cd <project-path>
$ python -m zalando_kubectl <whatever>

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

zalando_kubectl-1.32.5.248.tar.gz (50.2 kB view details)

Uploaded Source

Built Distribution

zalando_kubectl-1.32.5.248-py3-none-any.whl (53.1 kB view details)

Uploaded Python 3

File details

Details for the file zalando_kubectl-1.32.5.248.tar.gz.

File metadata

  • Download URL: zalando_kubectl-1.32.5.248.tar.gz
  • Upload date:
  • Size: 50.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.20

File hashes

Hashes for zalando_kubectl-1.32.5.248.tar.gz
Algorithm Hash digest
SHA256 9b67dbc377b76d51067dc5aa58fa0fb0ec888f789d6f6467ca87ff80da10d32d
MD5 e059414a43a69de754242b2a75e86cef
BLAKE2b-256 0a9cdfedba96ea9f635a60360bd61ac79cf7bf4e919fcf2afbb7e8bf0a6cbf63

See more details on using hashes here.

File details

Details for the file zalando_kubectl-1.32.5.248-py3-none-any.whl.

File metadata

File hashes

Hashes for zalando_kubectl-1.32.5.248-py3-none-any.whl
Algorithm Hash digest
SHA256 8b0efeee199180068d5f386631847f7dc7cbe01590142dd8e1b06946d97da260
MD5 2edfb2f7bcad4317e5f1c9df5b76a869
BLAKE2b-256 f2bbee7e0ddf6f5c47b32548e905642f21a308190911b82a5bedef6172c87ee0

See more details on using hashes here.

Supported by

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