Home > OS >  Python Kubernetes SDK get image and pods status of Replica Set
Python Kubernetes SDK get image and pods status of Replica Set

Time:03-16

I want get image name and pods status of Replica Set name by enter image description here

I write code for get service (Replica Set) data but I didn't find any information of images or pods status of the service

config.load_kube_config()
api_instance = client.CoreV1Api()
services_items = api_instance.list_namespaced_service(namespace=namespace).items

CodePudding user response:

You are querying for a Service.

You should be using api_instance.list_namespaced_pod to get Pods and their images or list_namespaced_deployment for Replica information.

CodePudding user response:

Deployment, ReplicaSet, etc, belong to the apps/v1 API, not to the core API:

from kubernetes import client, config
config.load_kube_config()
api = client.AppsV1Api()

deployment_list = api.list_namespaced_deployment(namespace="foo")
# status of the first deployment in the list
print(deployment_list.items[0].status)

rs_list = api.list_namespaced_replica_set(namespace="bar")
# image of the first container of the first replica set in the list
print(rs_list.items[0].spec.template.spec.containers[0].image)
  • Related