![](/img/trans.png)
[英]Front end [running in docker container] not able to access ASP.Net core API [running in another container]
[英].Net Core API container on Minikube not running
我在 Minikube 上部署了一个 .Net Core 5 API,当我尝试从 Postman 调用它时,它没有返回响应。当我从 Postman 运行 GET 到暴露的端口(32580)和端点http:// localhost:32580/api/platforms/
我得到:
Error: getaddrinfo ENOTFOUND
奇怪的是,我之前遇到了Connection refused
的情况(在我重新启动 Docker 桌面之前)。 当我使用 Docker 时,该容器运行良好,但一旦我将其部署到 Kube.netes 上下文,它就不再运行。
我不确定如何准确地调试容器并获得更有意义的错误详细信息。
我尝试了以下方法:
NAME READY UP-TO-DATE AVAILABLE AGE
hello-minikube 1/1 1 1 134d
ping-google 0/1 1 0 2d2h
platforms-depl 1/1 1 1 115m
NAME READY STATUS RESTARTS AGE
hello-minikube-6ddfcc9757-6mfmf 1/1 Running 21 134d
ping-google-5f84d66fcc-kbb7j 0/1 ImagePullBackOff 151 2d2h
platforms-depl-84d7f5bdc6-sgxcp 1/1 Running 1 115m
kubectl describe pod platforms-depl-84d7f5bdc6-sgxcp
给出以下 output(截断):Status: Running
IP: 172.17.0.3
IPs:
IP: 172.17.0.3
Controlled By: ReplicaSet/platforms-depl-84d7f5bdc6
Containers:
platformservice:
Container ID: docker://a73ce2dc737206e502df94066247299a6dcb6a038087d0f42ffc6e3b9dd194dd
Image: golide/platformservice:latest
Image ID: docker-pullable://golide/platformservice@sha256:bbed5f1d7238d2c466a6782333f8512d2e464f94aa64d8670214646a81b616c7
Port: <none>
Host Port: <none>
State: Running
Started: Tue, 28 Sep 2021 15:12:22 +0200
Ready: True
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-rl5kf (ro)
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
当我运行docker ps
时,我看不到容器,它也没有出现在 VS Code Docker/Containers 扩展中的运行容器列表中。
kubectl get services
给我以下信息:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
hello-minikube NodePort 10.99.23.44 <none> 8080:31378/TCP 134d
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 134d
paymentsapi NodePort 10.111.243.3 <none> 5000:30385/TCP 108d
platformnpservice-srv NodePort 10.98.131.95 <none> 80:32580/TCP 2d2h
然后尝试 ping ClusterIP:
Pinging 10.98.131.95 with 32 bytes of data:
Request timed out.
Request timed out.
Ping statistics for 10.98.131.95:
Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),
我错过了什么?
我阅读了一些建议,我必须执行到 pod 中,这样我才能得到有意义的 output 但我不确定要运行的确切命令。 我试过:
kubectl exec POD -p platforms-depl-84d7f5bdc6-sgxcp
只会得到错误:
kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.
Error from server (NotFound): pods "POD" not found
我的环境 Docker Linux Windows 10 上带有 WSL2 的容器。
我错过了什么?
首先值得注意的是,通常 minikube 有很多可能的驱动程序可供选择——在我的例子中,我发现docker
驱动器是最容易使用的。
我的设置是:
我使用以下命令启动 minikube: minikube start --driver=docker
。 如果您使用的是其他驱动程序,我建议您转到docker
驱动程序。
回答你的问题:
我错过了什么?
通过设置 nodePort 服务类型,您将使用节点 IP 地址公开您的部署/副本集,该地址无法从 Windows 主机访问(使用docker
驱动程序时)。 这是因为所有 Kube.netes 集群资源都设置在 Docker 容器内,该容器是隔离的。
但是,minikube 提供了简单的解决方案,使指定的 nodePort 服务对您的 Windows 主机可用。 只需运行将创建隧道的minikube service
命令。 让我们检查一下。
您设置platformnpservice-srv
服务,因此您需要在minikube service
命令中使用此名称,而不是我使用的testmini
:
minikube service --url testmini
🏃 Starting tunnel for service testmini.
|-----------|----------|-------------|------------------------|
| NAMESPACE | NAME | TARGET PORT | URL |
|-----------|----------|-------------|------------------------|
| default | testmini | | http://127.0.0.1:33849 |
|-----------|----------|-------------|------------------------|
http://127.0.0.1:33849
❗ Because you are using a Docker driver on linux, the terminal needs to be open to run it.
请注意最后一句话 - 我们需要保持此终端 window 处于打开状态,否则将无法建立隧道。 现在,在我的 Windows 主机上,我在浏览器中打开: http://127.0.0.1:33849/api/platforms
网站。 output 如下:
[{"id":1,"name":"Dot Net","publisher":"Microsoft","cost":"Free"},{"id":2,"name":"Linux","publisher":"Ubuntu","cost":"Free"},{"id":3,"name":"Kubernetes","publisher":"CNCF","cost":"Free"},{"id":4,"name":"SQL Express","publisher":"Microsoft","cost":"Free"}]
瞧。 似乎一切正常。
另外,其他注意事项:
尝试 ping ClusterIP
ClusterIP 是只能从集群访问的内部地址,因此您无法从 Windows 主机或 WSL2 ping 通它。
kubectl exec POD -p platforms-depl-84d7f5bdc6-sgxcp
正如 output 所建议的那样,您需要指定要在 pod 上执行的命令。 如果您只想获得 bash shell,请使用以下命令:
kubectl exec -it platforms-depl-84d7f5bdc6-sgxcp -- sh
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.