【发布时间】:2021-12-29 04:43:10
【问题描述】:
设置:
我有一个 minikube 设置和一个 docker-compose 设置并排运行。通过这种方式,我可以轻松地在 docker/docker-compose 中开发我的应用程序,并在 minikube 中运行其他服务。我正在使用 Linux (Ubuntu)。
问题:
我想使用 cURL 在 docker-compose 内运行的 docker 容器中访问 minikube API。
我尝试过的:
- 使用代理设置访问 minikube:
curl http://localhost:8080/api(当使用 kubectl 代理kubectl proxy --port=8080时)但这当然行不通,因为 localhost 是容器的本地主机。这导致curl: (7) Failed to connect to localhost port 8080: Connection refused - 通过 docker 内部主机访问 minikube:
curl http://host.docker.internal:8080/api。这也导致curl: (7) Failed to connect to host.docker.internal port 8080: Connection refused。 - 通过以下脚本中的 api/credentials 访问 minikube:
APISERVER=$(kubectl config view --minify | grep server | cut -f 2- -d ":" | tr -d " ")
SECRET_NAME=$(kubectl get secrets | grep ^default | cut -f1 -d ' ')
TOKEN=$(kubectl describe secret $SECRET_NAME | grep -E '^token' | cut -f2 -d':' | tr -d " ")
curl $APISERVER/api --header "Authorization: Bearer $TOKEN" --insecure
但这一切都失败了。
我也将它添加到我的 docker-compose.yml 文件中:
extra_hosts:
- "host.docker.internal:host-gateway"
当我在 docker 容器外尝试上述命令时,一切正常。 如何从 docker 容器内访问 minikube?
提前致谢!
【问题讨论】:
标签: docker kubernetes curl minikube