大网数据广告活动
服务器运维问答

How can I get the status of multiple kubernetes resources in a single API call?

· 52CE 我爱测

I'm using the python kubernetes client to control deployment of resources. I'd like to poll the status of multiple resources at once to provide near-realtime feedback on when a given set of resources is available. Right now I hav…

问题原文

原帖链接 · Ben Davis · CC BY-SA 4.0

I'm using the python kubernetes client to control deployment of resources. I'd like to poll the status of multiple resources at once to provide near-realtime feedback on when a given set of resources is available. Right now I have to query each resources individually, which seems excessive on a system where each set of resources scales by N users (so if there are 6 resources there would be N(6) requests for a status check).

Is there way to query the API and get the status of all resources that match a given label selector? If not, is there another approach I should consider?

已采纳解答

原帖链接 · mdaniel · CC BY-SA 4.0

get the status of all resources that match a given label selector?

I started out by seeing how kubectl does it, because at high enough verbosity levels, it shows the actual underlying HTTP transactions:

kubectl --v=8 get deploy,pod  -l app.kubernetes.io/name=something

seems to issue two separate GET calls, so I believe it is just putting them in flight concurrently and then awaiting the threads.

As for the other half of your question,

kubectl --v=8 get all -l app.kubernetes.io/name=something

does the same thing as the CSV version, but instead appears to do something akin to kubectl api-resources (or maybe has a hard-coded list of what it considers all?) and then does the same thing: putting multiple GET in flight and awaiting the threads

You may be interested in exploring how kubectl rollout status operates, to see if that might help you. I also tried adding --watch to the get all and was informed:

F0730 21:55:36.819494 2887268 helpers.go:115] error: you may only specify a single resource type

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-07-30)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。