Skip to main content

kubernetes client code

Project description


The goal of this image is to be able to reach clusters and use their API's from a pod programmatically with python. In order for the image to use the correct settings it has to be rebuilt everytime the cluster have been updated with:

- access privileges
- tokens
- hosts
- ~/.kube/config

If the cluster has been reset the image will have to be rebuilt because the tokens have been renewed. To prevent using kubectl as a sidecar in a pod when accessing a local cluster, we just copy over the local settings and let python kubernetes lib use those.


  • Build
  • Deploy
  • exec
  • manually call python code in dev. phase


In order to build the image correctly follow the instructions below (regular docker build / docker-compose build cannot be used due to needed args in the build process)


docker build --no-cache -f aikpy/pykube/Dockerfile -t pykube:1 --build-arg KUBE_CONFIG="$(cat ~/.kube/config)" --build-arg API_TOKEN="$(kubectl describe secret default | grep -e '^token' | cut -f 2 -d ':' | tr -d ' \t')" --build-arg HOSTLIST="$(kubectl config view -o jsonpath='{range .clusters[*]}{.cluster.server}{","}{end}' | sed 's/,$/ /g')" aikpy/pykube


docker build --no-cache -f .\aikpy\pykube\Dockerfile -t pykube:1 --build-arg KUBE_CONFIG="$(cat $env:USERPROFILE\.kube\config)" --build-arg API_TOKEN="$(kubectl describe secret default | findstr /B token | %{$_.split(':')[1]
} | %{$_ -replace ' ', ''})" --build-arg HOSTLIST="$(kubectl config view -o jsonpath='{range .clusters[*]}{.cluster.server}{\",\"}{end}' | %{$_ -replace ",$",''})" .\aikpy\pykube\


cd kubernetes-dev; 
kubectl create -f pykube-deployment.yaml;


kubectl exec -it pykube-<pod-id> bash

Manually call python


Then choose list of cluster hosts to connect to.

Project details

Release history Release notifications

This version


Download files

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

Files for broentech-pykube, version 0.5
Filename, size File type Python version Upload date Hashes
Filename, size broentech_pykube-0.5-py3-none-any.whl (19.6 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size broentech-pykube-0.5.tar.gz (5.7 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page