Apache 我能';t使用CGI访问kubernetes python客户端

Apache 我能';t使用CGI访问kubernetes python客户端,apache,kubernetes,cgi,Apache,Kubernetes,Cgi,我试图通过CGI编程使用python客户端访问kubernetes API,我得到的错误是 FileNotFoundError: [Errno 2] No such file or directory: '/usr/share/httpd/.kube/config' 但是Kube配置文件在主目录中 这是我的源代码 from kubernetes import client, config def main(): activate_this = '/root/env/bin

我试图通过CGI编程使用python客户端访问kubernetes API,我得到的错误是

FileNotFoundError: [Errno 2] No such file or directory: '/usr/share/httpd/.kube/config'
但是Kube配置文件在主目录中

这是我的源代码

from kubernetes import client, config

   def main():
       activate_this = '/root/env/bin/activate_this.py'
       with open(activate_this) as file_:
           exec(file_.read(), dict(__file__=activate_this))
       contexts_data, active_context = config.list_kube_config_contexts()
       print(contexts_data)
   if __name__ == '__main__':
       main()

无法获取kubernetes的配置文件。检查您的配置文件路径

KUBE_CONFIG_DEFAULT_LOCATION = os.environ.get('KUBECONFIG', '~/.kube/config')

您也可以在这里进行检查,正如我在代码os.environ中提到的那样,以获取该文件。

您必须将配置文件路径设置为环境变量

os.environ["KUBECONFIG"]=your_config_file_path