kubernetes python客户端在使用watch.stream方法运行时挂起
我正在尝试使用kubernetes python客户端(版本9.0)观看kubernetes资源类的pods,但几分钟后观看k8s资源时,watch.stream()方法似乎被挂起kubernetes python客户端在使用watch.stream方法运行时挂起,python,python-3.x,kubernetes,Python,Python 3.x,Kubernetes,我正在尝试使用kubernetes python客户端(版本9.0)观看kubernetes资源类的pods,但几分钟后观看k8s资源时,watch.stream()方法似乎被挂起 v1=client.CoreV1Api() w=手表。手表() 对于w.stream中的资源(v1.list\u namespaced\u pod): 剂量测定(资源) 我怎样才能一直关注kebernetes吊舱呢?您可能正在点击此按钮,如本文所述,您可以尝试以下方法: from kubernetes import
v1=client.CoreV1Api()
w=手表。手表()
对于w.stream中的资源(v1.list\u namespaced\u pod):
剂量测定(资源)
我怎样才能一直关注kebernetes吊舱呢?您可能正在点击此按钮,如本文所述,您可以尝试以下方法:
from kubernetes import client, config, watch
from urllib3.exceptions import ProtocolError
config.load_kube_config()
api_instance = client.CoreV1Api()
while True:
w = watch.Watch()
try:
for event in w.stream(api_instance.list_namespaced_pod, namespace="default"):
print("Event: %s %s %s" % (event['type'],event['object'].kind, event['object'].metadata.name))
except ProtocolError:
print("watchPodEvents ProtocolError, continuing..")
希望有帮助 thx,但是
虽然True
循环不起作用,可能是防火墙切断了连接,我要重新部署kubernetes客户端,防火墙切断了连接