I am trying to use Kubernetes in a django app in my PC (Ubuntu 20.04 LTS) but after going through a lot of different errors I went and tried a simple example (Deploy Pod from YAML file) from the kubernetes python library. Even though the example is very straightforward I keep getting the same error:
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='192.168.139.242', port=6443):
Max retries exceeded with /apis/apps/v1/namespaces/default/deployments
(Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fef64215430>:
Failed to establish a new connection: [Errno 111] Connection refused'))
My code looks like the example (I've only changed the yaml file):
from kubernetes import client,config,utils
def main():
config.load_kube_config()
k8s_client = client.ApiClient()
yaml_file = 'video_capturer.yaml'
utils.create_from_yaml(k8s_client,yaml_file,verbose=True)
if __name__ == "__main__":
main()
And I get the previous error in the create_from_yaml function, the IP and port should be right.
If I try to do the equivalent in a new ubuntu terminal (microk8s kubectl apply -f video_capturer.yaml) it works perfectly fine.
Do you know what might be wrong with my k8s installation?
EDIT: After trying different approaches I have noticed that what works fine is using microk8s to deploy the pod, but when I simply use kubectl I get the following error:
~$ kubectl get all
The connection to the server 192.168.139.242:6443 was refused -
did you specify the right host or port?
I think that something in my kubectl might be broken.