I can't access kubernetes python-client using CGI

3/20/2019

I'm trying to access kubernetes API using python-client through CGI programming, the error which I get is,

FileNotFoundError: [Errno 2] No such file or directory: '/usr/share/httpd/.kube/config'

but the Kube config file is in the home directory.

This is my source code

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()
--
apache
cgi
kubernetes

2 Answers

8/20/2019

You have to set the config file path as environment variable

os.environ["KUBECONFIG"]=your_config_file_path
-- mohammed wazeem
Source: StackOverflow

3/20/2019

It is not able to get the config file of kubernetes. check for your config file path

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

also you can check here as i have mention on code os.environ to get the file.

-- Harsh Manvar
Source: StackOverflow