Aviv Monika
Aviv Monika

Reputation: 21

Python Kubernetes SDK get image and pods status of Replica Set

I want get image name and pods status of Replica Set name by python k8s SDK

Currently I get the data manually from k8s UI dashboard: 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

Upvotes: 0

Views: 1899

Answers (2)

anemyte
anemyte

Reputation: 20196

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)

Upvotes: 2

OneCricketeer
OneCricketeer

Reputation: 191743

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.

Upvotes: 0

Related Questions