如何修复'没有这样的文件或目录:'/ home / jenkins / .kube / config''在python openshift休息客户端使用load_incluster_config时

问题描述 投票:0回答:2

我编写了一个脚本来检查OpenShift集群中的一些秘密。我为Openshift使用了python rest-client库,脚本在集群中执行。但我总是得到IOError:[Errno 2]没有这样的文件或目录:'/ home / jenkins / .kube / config'

我知道我在pod中没有kube配置,因此我尝试使用kubernetes.config.load_incluster_config()方法启用集群配置。

from kubernetes import client, config
from openshift.dynamic import DynamicClient

config.load_incluster_config()

k8s_client = config.new_client_from_config()
dyn_client = DynamicClient(k8s_client)

我假设不再需要使用load_incluster_config调用提供kube配置。是否有人通过服务帐户解决了其他客户端和集群执行中的openshift问题?

我感谢任何帮助,谢谢。

python kubernetes openshift rest-client kubeconfig
2个回答
0
投票

我的意思是,你可能已经检查了这个,但确定你在正确的目录中?因为从错误的目录运行文件可能会导致错误“没有这样的文件或目录”。


0
投票

我解决了以下问题:

if os.getenv('KUBERNETES_SERVICE_HOST'):
    config.load_incluster_config()
else:
    config.load_kube_config()

dyn_client = DynamicClient(ApiClient())

ApiClient正在使用默认配置。

© www.soinside.com 2019 - 2024. All rights reserved.