簡體   English   中英

.Net Core API Minikube 上的容器未運行

[英].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 上下文,它就不再運行。

我不確定如何准確地調試容器並獲得更有意義的錯誤詳細信息。

我嘗試了以下方法:

  1. 檢查部署狀態 (platforms-depl)

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
  1. 檢查 Pod 的狀態 (platforms-depl-84d7f5bdc6-sgxcp)

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
  1. 運行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
  1. 當我運行docker ps時,我看不到容器,它也沒有出現在 VS Code Docker/Containers 擴展中的運行容器列表中。

  2. 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM