Skip to main content

This Python package provides native Kubernetes CLI aliases, allowing users to manage and query Kubernetes resources directly from Python without using kubectl

Project description

release

Kubernetes CLI Aliases for Python

This Python package provides native Kubernetes CLI aliases, allowing users to manage and query Kubernetes resources directly from Python without using kubectl.

Installation

pip install k8s-cli

Usage

ku         # List all Kubernetes pods that are not Running, Complete and any of the containers not in Ready state.
kn         # List all K8S worker nodes and their details (same output as kubectl get nodes -o wide).
kp         # List all K8S pods and their details (same output as kubectl get pods -o wide -A) across all namespaces.
kpf        # Port forward to a pod; example command: kpf podname -n namespace1
kps        # Service forward to a service; example command: kps servicename -n namespace1
kd         # Drain node with --ignore-daemonsets, --delete-emptydir-data, and --chunk-size=500; example: kd worker-node-name

Example output

  • all unhealthy pods with a single command
ku
Target Kubernetes version: v1.29.2
+-------------+--------------------------------+-------+---------+----------+-------------+-------------+----------------+-----------------+
| NAMESPACE   | POD NAME                       | READY |  STATUS | RESTARTS | IP          | NODE NAME   | NOMINATED NODE | READINESS GATES |
+-------------+--------------------------------+-------+---------+----------+-------------+-------------+----------------+-----------------+
| default     | nginx-7854ff8877-dczdq         |  0/1  | Pending |    0     | None        | kind-worker |      None      |       None      |
| default     | nginx-7854ff8877-fcpjq         |  0/1  | Pending |    0     | None        | kind-worker |      None      |       None      |
| default     | nginx-7854ff8877-p6fgz         |  0/1  | Pending |    0     | None        | kind-worker |      None      |       None      |
| default     | nginx-7854ff8877-q2pf8         |  0/1  | Pending |    0     | None        | kind-worker |      None      |       None      |
| kube-system | metrics-server-98bc7f888-mqcfx |  0/1  | Running |    0     | 10.244.1.45 | kind-worker |      None      |       None      |
| namespace2  | nginx-replicaset-2-2-dbqpf     |  0/1  | Pending |    0     | None        | kind-worker |      None      |       None      |
| namespace2  | nginx-replicaset-2-2-dxpwr     |  0/1  | Pending |    0     | None        | kind-worker |      None      |       None      |
+-------------+--------------------------------+-------+---------+----------+-------------+-------------+----------------+-----------------+
  • all Kubernetes worker nodes with details
kn
Target Kubernetes version: v1.29.2
+--------------------+--------+---------------------+---------+-------------+--------------------------------+-----------------+---------------------+
| NAME               | STATUS |         AGE         | VERSION | INTERNAL-IP | OS-IMAGE                       | KERNEL-VERSION  | CONTAINER-RUNTIME   |
+--------------------+--------+---------------------+---------+-------------+--------------------------------+-----------------+---------------------+
| kind-control-plane | Ready  | 2024-03-23 17:25:55 | v1.29.2 | 172.18.0.2  | Debian GNU/Linux 12 (bookworm) | 6.6.22-linuxkit | containerd://1.7.13 |
| kind-worker        | Ready  | 2024-03-23 17:26:13 | v1.29.2 | 172.18.0.3  | Debian GNU/Linux 12 (bookworm) | 6.6.22-linuxkit | containerd://1.7.13 |
+--------------------+--------+---------------------+---------+-------------+--------------------------------+-----------------+---------------------+
  • all pods across all Kubernetes namespaces
kp
Target Kubernetes version: v1.29.2
+--------------------+--------------------------------------------+-------+---------+----------+-------------+--------------------+----------------+-----------------+
| NAMESPACE          | POD NAME                                   | READY |  STATUS | RESTARTS | IP          | NODE NAME          | NOMINATED NODE | READINESS GATES |
+--------------------+--------------------------------------------+-------+---------+----------+-------------+--------------------+----------------+-----------------+
| default            | nginx-7854ff8877-66mt2                     |  1/1  | Running |    0     | 10.244.1.23 | kind-worker        |      None      |       None      |
| default            | nginx-7854ff8877-6zf5v                     |  1/1  | Running |    0     | 10.244.1.21 | kind-worker        |      None      |       None      |
| default            | nginx-7854ff8877-bm4zw                     |  1/1  | Running |    0     | 10.244.1.24 | kind-worker        |      None      |       None      |
| default            | nginx-7854ff8877-cv8zm                     |  1/1  | Running |    0     | 10.244.1.22 | kind-worker        |      None      |       None      |
| default            | nginx-7854ff8877-hrk8s                     |  1/1  | Running |    0     | 10.244.1.20 | kind-worker        |      None      |       None      |
| kube-system        | coredns-76f75df574-87hnn                   |  1/1  | Running |    0     | 10.244.1.27 | kind-worker        |      None      |       None      |
| kube-system        | coredns-76f75df574-dzpfx                   |  1/1  | Running |    0     | 10.244.1.25 | kind-worker        |      None      |       None      |
| kube-system        | etcd-kind-control-plane                    |  1/1  | Running |    1     | 172.18.0.2  | kind-control-plane |      None      |       None      |
| kube-system        | kindnet-5r5lr                              |  1/1  | Running |    0     | 172.18.0.2  | kind-control-plane |      None      |       None      |
| kube-system        | kindnet-g88vs                              |  1/1  | Running |    0     | 172.18.0.3  | kind-worker        |      None      |       None      |
| kube-system        | kube-apiserver-kind-control-plane          |  1/1  | Running |    1     | 172.18.0.2  | kind-control-plane |      None      |       None      |
| kube-system        | kube-controller-manager-kind-control-plane |  1/1  | Running |    8     | 172.18.0.2  | kind-control-plane |      None      |       None      |
| kube-system        | kube-proxy-67msl                           |  1/1  | Running |    0     | 172.18.0.3  | kind-worker        |      None      |       None      |
| kube-system        | kube-proxy-f95rg                           |  1/1  | Running |    0     | 172.18.0.2  | kind-control-plane |      None      |       None      |
| kube-system        | kube-scheduler-kind-control-plane          |  1/1  | Running |    7     | 172.18.0.2  | kind-control-plane |      None      |       None      |
| kube-system        | metrics-server-98bc7f888-xg2j9             |  1/1  | Running |    0     | 10.244.1.26 | kind-worker        |      None      |       None      |
| local-path-storage | local-path-provisioner-7577fdbbfb-wnv88    |  1/1  | Running |    0     | 10.244.0.6  | kind-control-plane |      None      |       None      |
| namespace2         | nginx-replicaset-2-2-mxvsv                 |  1/1  | Running |    0     | 10.244.1.28 | kind-worker        |      None      |       None      |
| namespace2         | nginx-replicaset-2-2-r885r                 |  1/1  | Running |    0     | 10.244.1.29 | kind-worker        |      None      |       None      |
+--------------------+--------------------------------------------+-------+---------+----------+-------------+--------------------+----------------+-----------------+

Step 3: Build and Upload to PyPi

Follow these steps to build and upload your package to PyPi:

  1. Build the distribution package:
python setup.py sdist bdist_wheel
  1. Upload the package to PyPi using twine:
pip install twine
twine upload dist/*

Project details


Download files

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

Source Distribution

k8s-cli-1.2.5.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

k8s_cli-1.2.5-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file k8s-cli-1.2.5.tar.gz.

File metadata

  • Download URL: k8s-cli-1.2.5.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.4

File hashes

Hashes for k8s-cli-1.2.5.tar.gz
Algorithm Hash digest
SHA256 5b0efc2799a7c882d97d5a74c9972cf41273c46395dbe7f3c6fd6d51bd74de0a
MD5 0cee71e52d8df6b73b0b69bd81ebd2b2
BLAKE2b-256 c16d3f58307fe6bfe24c3c03b9768da288495a6a4110f9464ed44505b59512da

See more details on using hashes here.

File details

Details for the file k8s_cli-1.2.5-py3-none-any.whl.

File metadata

  • Download URL: k8s_cli-1.2.5-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.4

File hashes

Hashes for k8s_cli-1.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 b7a09e13cd0b4de33fed4595ba753b2c1b34a7101cce33d8bc723f7100a1c5e7
MD5 a43b51dc167a709ae1c08ee68c21dff5
BLAKE2b-256 23c2a722f8290417fd3c588c98480f4f195ea5a57e973ade41adc1c8baf32c01

See more details on using hashes here.

Supported by

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