Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Visual studio Visual Studio应用程序未使用Kubernetes服务公开 背景_Visual Studio_Kubernetes_Networking_Service_Port - Fatal编程技术网

Visual studio Visual Studio应用程序未使用Kubernetes服务公开 背景

Visual 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

我正在使用Docker for Windows
v20.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 create–-network personal overlay--name API webapi
  • 使用
    docker service create--name Web–-network personal overlay-p 30080:80 webapp创建Web应用服务
  • B✔️ 创建了通用NGINX部署和服务
    • 部署:
    apiVersion:apps/v1 种类:部署 元数据: 名称:nginx部署 标签: 层:前端 规格: 选择器: 火柴标签: 应用程序:myapp 副本:1份 模板: 元数据: 姓名:nginx 标签: 应用程序:myapp 规格: 容器: -姓名:nginx 图片:nginx
    • 服务:
    apiVersion:v1 种类:服务 元数据: 名称:nginx服务 规格: 类型:节点端口 端口: -目标港:80 港口:80 节点端口:30080 选择器: 应用程序:myapp 我可以通过
    http://localhost:30080
    没有问题(使用web浏览器)

    ❌ 我目前面临的问题
  • 标记图像
    test/api
    test/web
  • 使用这些Visual Studio图像创建了相同的文件:
    • 部署:
    apiVersion:apps/v1 种类:部署 元数据: 名称:测试部署 标签: 层:前端 规格: 选择器: 火柴标签: 应用程序:myapp 副本:1份 模板: 元数据: 名称:测试吊舱 标签: 应用程序:myapp 规格: 容器: -名称:api 图片:测试/api 政策:绝不 -名称:网站 图片:测试/网络 政策:绝不
    • 服务:
    apiVersion:v1 种类:服务 元数据: 名称:测试服务 规格: 类型:节点端口 端口: -目标港:80 港口:80 节点端口:30080 选择器: 应用程序:myapp 然而,我无法访问
    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应用程序)

    • 吊舱:
    • 服务:
    但是它不起作用(无论是否有pod
    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"