Visual studio Visual Studio应用程序未使用Kubernetes服务公开 背景
我正在使用Docker for WindowsVisual studio Visual Studio应用程序未使用Kubernetes服务公开 背景,visual-studio,kubernetes,networking,service,port,Visual Studio,Kubernetes,Networking,Service,Port,我正在使用Docker for Windowsv20.10.6(启用Kubernetes) 我创建了两个简单的现成的.NET 5.0应用程序: 1.Web API(通过HTTP访问,在端口7070上侦听) 2.显示Web API解析表的Web应用程序(MVC)(侦听端口80) A.✔️ 使用Docker Swarm模式在应用程序之间创建连接 使用docker swarm init创建群 创建了名为personal overlay的“overlay”驱动程序网络 使用docker service
v20.10.6
(启用Kubernetes)
我创建了两个简单的现成的.NET 5.0应用程序:
1.Web API(通过HTTP
访问,在端口7070
上侦听)
2.显示Web API解析表的Web应用程序(MVC)(侦听端口80
)
A.✔️ 使用Docker Swarm模式在应用程序之间创建连接
personal overlay
的“overlay”驱动程序网络docker service create–-network personal overlay--name API webapi
docker service create--name Web–-network personal overlay-p 30080:80 webapp创建Web应用服务
- 部署:
- 服务:
http://localhost:30080
没有问题(使用web浏览器)
❌ 我目前面临的问题
test/api
和test/web
- 部署:
- 服务:
http://localhost:30080
编辑[1]:
我试图通过web浏览器访问它,但收到一个HTTP错误500
:“加载资源失败:服务器响应状态为500(内部服务器错误)。”
每当我使用curl-I时http://localhost:30080
我得到以下回应:
HTTP/1.1 500 Internal Server Error
Date: Thu, 13 May 2021 08:20:25 GMT
Server: Kestrel
Content-Length: 0
编辑[2]:
我甚至试着把它缩小到一个pod(web应用程序)
- 吊舱:
- 服务:
YAML
文件中的ports
部分)。
这些是我使用kubectl logs web pod-
命令获得的日志(该命令表示它实际上正在侦听端口80
):
我还应该提到,使用kubectl cluster info dump
我得到了以下一行代码(但是对于服务
,而不是pod
本身):
您无法访问
http://localhost:30080
。你犯了什么错误?暂停?找不到?你怎么查的?用浏览器?或者从终端命令-curl
?你用过Docker桌面吗?请通过编辑您的问题来澄清这一点。@MikołajGłodziak感谢您的澄清。我正在使用Docker for Windows(启用Kubernetes)。我正在尝试使用web浏览器访问它,得到HTTP错误500
。感谢添加更多信息。你查过了吗?你可以在这里找到更多关于这个问题的信息。请再次编辑您的问题,并粘贴部署和服务的日志输出。@MikołajGłodziak已进行相应编辑(编辑[2])。如果您想通过NodePort
访问您的应用程序,您需要使用:http://{node ip}:{node port}
。这是一个类似的问题。您是否尝试将NodePort
更改为LoadBalancer
?您的.NET应用程序中也可能存在此问题。
apiVersion: v1
kind: Pod
metadata:
name: consumer-pod
labels:
name: consumer-pod
app: api-and-consumer
spec:
containers:
- name: consumer
image: test/web
imagePullPolicy: Never
ports:
- containerPort: 80
apiVersion: v1
kind: Service
metadata:
name: consumer-external-svc
labels:
name: consumer-external-svc
app: api-and-consumer
spec:
type: NodePort
ports:
- port: 80
targetPort: 80
nodePort: 30080
selector:
name: consumer-pod
app: api-and-consumer
←[40m←[1m←[33mwarn←[39m←[22m←[49m: Microsoft.AspNetCore.DataProtection.Repositories.FileSystemXmlRepository[60]
Storing keys in a directory '/root/.aspnet/DataProtection-Keys' that may not be persisted outside of the container. Protected data will be unavailable when container is destroyed.
←[40m←[1m←[33mwarn←[39m←[22m←[49m: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35]
No XML encryptor configured. Key {70ddc140-9846-4052-b869-8bcc5250d39e} may be persisted to storage in unencrypted form.
←[40m←[32minfo←[39m←[22m←[49m: Microsoft.Hosting.Lifetime[0]
Now listening on: http://[::]:80
←[40m←[32minfo←[39m←[22m←[49m: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
←[40m←[32minfo←[39m←[22m←[49m: Microsoft.Hosting.Lifetime[0]
Hosting environment: Production
←[40m←[32minfo←[39m←[22m←[49m: Microsoft.Hosting.Lifetime[0]
Content root path: /app
time="2021-05-13T10:56:35Z" level=error msg="Port 30080 for service web-external-svc is already opened by another service"