Automate All the Boring Kubernetes Operations with Python

This page summarizes the projects mentioned and recommended in the original post on dev.to

Our great sponsors
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • WorkOS - The modern identity platform for B2B SaaS
  • SaaSHub - Software Alternatives and Reviews
  • kind

    Kubernetes IN Docker - local clusters for testing Kubernetes

    # https://github.com/kubernetes-sigs/kind/issues/398 # kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/download/v0.5.0/components.yaml # kubectl patch -n kube-system deployment metrics-server --type=json \ # -p '[{"op":"add","path":"/spec/template/spec/containers/0/args/-","value":"--kubelet-insecure-tls"}]' from kubernetes import client api_client = client.ApiClient(configuration) custom_api = client.CustomObjectsApi(api_client) response = custom_api.list_cluster_custom_object("metrics.k8s.io", "v1beta1", "nodes") # also works with "pods" instead of "nodes" for node in response["items"]: print(f"{node['metadata']['name']: <30} CPU: {node['usage']['cpu']: <10} Memory: {node['usage']['memory']}") # api-playground-control-plane CPU: 148318488n Memory: 2363504Ki # api-playground-worker CPU: 91635913n Memory: 1858680Ki # api-playground-worker2 CPU: 75473747n Memory: 1880860Ki # api-playground-worker3 CPU: 105692650n Memory: 1881560Ki

  • python

    Official Python client library for kubernetes (by kubernetes-client)

    As you can imagine, that's a lot of functions to choose from, luckily all of them are listed in docs and you can click on any one of them to get an example of its usage.

  • InfluxDB

    Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.

  • metrics-server

    Scalable and efficient source of container resource metrics for Kubernetes built-in autoscaling pipelines.

    # https://github.com/kubernetes-sigs/kind/issues/398 # kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/download/v0.5.0/components.yaml # kubectl patch -n kube-system deployment metrics-server --type=json \ # -p '[{"op":"add","path":"/spec/template/spec/containers/0/args/-","value":"--kubelet-insecure-tls"}]' from kubernetes import client api_client = client.ApiClient(configuration) custom_api = client.CustomObjectsApi(api_client) response = custom_api.list_cluster_custom_object("metrics.k8s.io", "v1beta1", "nodes") # also works with "pods" instead of "nodes" for node in response["items"]: print(f"{node['metadata']['name']: <30} CPU: {node['usage']['cpu']: <10} Memory: {node['usage']['memory']}") # api-playground-control-plane CPU: 148318488n Memory: 2363504Ki # api-playground-worker CPU: 91635913n Memory: 1858680Ki # api-playground-worker2 CPU: 75473747n Memory: 1880860Ki # api-playground-worker3 CPU: 105692650n Memory: 1881560Ki

  • kopf

    A Python framework to write Kubernetes operators in just a few lines of code

    If you're looking for more examples beyond what was shown and referenced above, I recommend exploring other popular tools that make use Python Kubernetes client, such kopf - the library for creating Kubernetes operators. I also find it very useful to take a look at tests of the library itself, as it showcases its intended usage such this client test suite.

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts