0

I have a test Kubernetes cluster (Minikube) running in a Docker container.

I want to write some Python code to start jobs on that cluster. If I go inside the container:

$ docker exec -it kubernetes /bin/sh
#/ apk add python3
#/ apk add py3-pip
#/ pip install kubernertes
#/ pyhton3
>>> from kubernetes import config, client

>>> config.load_kube_config()

It works, and I can then create a client and do my stuff.

However, if I run the same Python commands from the host machine:

>>> config.load_kube_config()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/path/to/python/kubernetes/config/kube_config.py", line 814, in load_kube_config
    loader = _get_kube_config_loader(
  File "/path/to/python/kubernetes/config/kube_config.py", line 773, in _get_kube_config_loader
    raise ConfigException(
kubernetes.config.config_exception.ConfigException: Invalid kube-config file. No configuration found.

That sort of makes sense, since kubernetes is not running on the machine. How do I go around this ? Is there another way to fetch the config file ?

Gaëtan
  • 779
  • 1
  • 8
  • 26

1 Answers1

-1

config should be in ~/.kube/config path

mkdir -p ~/.kube/
cp <current config path> ~/.kube/config
#below steps verify  if your config is proper
export KUBECONFIG=~/.kube/config 
kubectl get pods

once above steps are working fine you could try running the python script

Sai Teja Pakalapati
  • 746
  • 1
  • 11
  • 30
  • Kubernetes is NOT on the machine. It runs in a container. My question is about using Python to send queries to that instance from outside the container. – Gaëtan Nov 15 '21 at 16:02