skip to Main Content

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()

2

Answers


  1. 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.

    Login or Signup to reply.
  2. You have to set the config file path as environment variable

    os.environ["KUBECONFIG"]=your_config_file_path
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search