1

我正在尝试将 v1Ingress 对象转换为标准 yaml 文件。但是,将保存的文件与其清单文件进行比较会kubectl get ing example -o yaml显示不同的文件。解决这个问题的任何指针

from kubernetes import client, config
import kubernetes.client
from kubernetes.client.rest import ApiException
import yaml
 

config.load_kube_config("k8s.yml")
v1 = client.NetworkingV1Api()
api_client = client.ApiClient()

namespace = "sample"

try:
    api_response = v1.list_namespaced_ingress(namespace)
 
    for ing in api_response.items:
        name = ing.metadata.name
        with open("{}.yml".format(name), "w") as f:
            yaml.dump(api_client.sanitize_for_serialization(ing), f, default_flow_style=False)

except ApiException as e:
    print("Exception when calling NetworkingV1Api->list_namespaced_ingress:", str(e), "\n")
4

0 回答 0