Home > OS >  How-To: Access local minikube cluster, with kubectl running inside VSCode Development Container?
How-To: Access local minikube cluster, with kubectl running inside VSCode Development Container?

Time:03-31

I have minikube cluster running on Windows WSL2, and I have a Dev Container https://code.visualstudio.com/docs/remote/create-dev-container) running my React Application and Kubernetes CLI tools. My goal is to containerize the application and run that on the minikube cluster.

So now I have exposed the local configurations and certifications of minikube to my Dev Container, and I am using that as a default KUBECONFIG. I have a deployment, and Docker Image ready - so next step is to try to use deployment and have that running on the cluster.

When I am running a kubectl command inside the Dev Container, I am getting error message like this:

The connection to the server 127.0.0.1:51515 was refused - did you specify the right host or port?

When I am inspecting the minikube container, I see that its listening only to localhost

gcr.io/k8s-minikube/kicbase:v0.0.28                          "/usr/local/bin/entr…"   3 hours ago          Up 3 hours          127.0.0.1:58892->22/tcp, 127.0.0.1:58893->2376/tcp, 127.0.0.1:58895->5000/tcp, 127.0.0.1:58896->8443/tcp, 127.0.0.1:58894->32443/tcp   minikube

So as far as I know, these requests fail, because request from Dev Container is not considered as a localhost request (I am able to ping localhost.). I am running the Dev Container with network=host flag.

So atleast one way to get this setup working it to bind minikube's ports to listen to 0.0.0.0, instead of localhost - is there any other way? How could I get that 0.0.0.0 bind working? I am having a feeling that this could be Docker Desktop settings related - that I need to somehow change some kind of default settings from 127.0.0.1 -> 0.0.0.0.

Running minikube with this command didn't do the trick.

minikube start --driver=docker --listen-address='0.0.0.0'

Versions:

  • Docker Desktop 4.6.0 (75818)
  • Docker 20.10.13, build a224086
  • minikube v1.24.0
  • kubectl 1.21.5

Thank you in advance!

EDIT:

I also tried different alternatives to localhost, without changing the configuration in minikube, with the same port that is on host computer - these didn't do the trick. I can however ping every address from Container.

kubernetes.docker.internal, host.docker.internal, 192.168.49.2 (Minikube's IP on localhost), minikubeCA, control-plane.minikube.internal, kubernetes.default.svc.cluster.local, kubernetes.default.svc, kubernetes.default, kubernetes, localhost

Here is my minikube's KUBECONFIG.

- cluster:
    certificate-authority-data: Removed for Security.
    extensions:
    - extension:
        last-update: Mon, 28 Mar 2022 17:30:48 EEST
        provider: minikube.sigs.k8s.io
        version: v1.24.0
      name: cluster_info
    server: https://localhost:58896
  name: minikube

CodePudding user response:

I managed to solve this. Docker Desktop requires to use host.docker.internal instead of localhost inside Kubernetes Config YAML.

Problem is that first address is not allowed by Minikubes Certificate. Running kubectl commands with flag --insecure-skip-tls-verify - so for example

kubectl get nodes -A --insecure-skip-tls-verify

works, with setup defined above.

Found also some documentation: https://github.com/Microsoft/vscode-dev-containers/tree/main/containers/kubernetes-helm

  • Related