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
502部署在K8群集上的Angular应用上的网关错误_Angular_Kubernetes_Traefik_Traefik Ingress_Bad Gateway - Fatal编程技术网

502部署在K8群集上的Angular应用上的网关错误

502部署在K8群集上的Angular应用上的网关错误,angular,kubernetes,traefik,traefik-ingress,bad-gateway,Angular,Kubernetes,Traefik,Traefik Ingress,Bad Gateway,我在使用流量入口控制器的k8集群上部署了3个服务。访问我的Angular构建的前端时,我得到了一个502坏网关错误,但后端节点服务器和mongo db工作正常 我已经尝试过一个Nginx入口控制器设置了相同的问题。我知道该应用程序的生产版本对于最终版本会更好,但就我所知,开发人员访问仍然是可能的。Traefik入口根据IP和端口正确路由,但途中某个地方出现故障。我已将exec'd放入“frontend”pod中,curl确认页面正在localhost:4200上托管,这与预期相符 我的docke

我在使用流量入口控制器的k8集群上部署了3个服务。访问我的Angular构建的前端时,我得到了一个502坏网关错误,但后端节点服务器和mongo db工作正常

我已经尝试过一个Nginx入口控制器设置了相同的问题。我知道该应用程序的生产版本对于最终版本会更好,但就我所知,开发人员访问仍然是可能的。Traefik入口根据IP和端口正确路由,但途中某个地方出现故障。我已将exec'd放入“frontend”pod中,curl确认页面正在localhost:4200上托管,这与预期相符

我的docker compose文件如下所示:

version: '3.7'

services:
    frontend:
        image: [image location]
        ports:
            - "4200"
        volumes:
            - ./frontend:/app

    s3-server:
        image: [image location]
        ports:
            - "3000"
        links:
            - database

    database:
        image: mongo
        ports:
            - "27017"
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: frontend
  annotations:
    kubernetes.io/ingress.class: traefik
spec:
  rules:
  - host: [domainname] 
    http:
      paths:
      - path: /
        backend:
          serviceName: frontend
          servicePort: 4200
      - path: /api
        backend:
          serviceName: s3-server
          servicePort: 3000
      - path: /db
        backend:
          serviceName: database
          servicePort: 27017
我的traefik yaml如下:

version: '3.7'

services:
    frontend:
        image: [image location]
        ports:
            - "4200"
        volumes:
            - ./frontend:/app

    s3-server:
        image: [image location]
        ports:
            - "3000"
        links:
            - database

    database:
        image: mongo
        ports:
            - "27017"
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: frontend
  annotations:
    kubernetes.io/ingress.class: traefik
spec:
  rules:
  - host: [domainname] 
    http:
      paths:
      - path: /
        backend:
          serviceName: frontend
          servicePort: 4200
      - path: /api
        backend:
          serviceName: s3-server
          servicePort: 3000
      - path: /db
        backend:
          serviceName: database
          servicePort: 27017
前端服务(使用compose创建)yaml:

入口显示:

Host              Path  Backends
  ----              ----  --------
  api.cailean.tech  
                    /      frontend:4200 (192.168.1.27:4200)
                    /api   s3-server:3000 (192.168.2.20:3000)
                    /db    database:27017 (192.168.2.14:27017)
播客节目:

pod/database-798b8df4bd-zzxpx    1/1     Running   0          17h   192.168.2.14   kube-node-ea4d   <none>           <none>
pod/s3-server-76dd6b6b57-pq9lp   1/1     Running   0          15h   192.168.2.20   kube-node-ea4d   <none>           <none>
pod/nginx-86c57db685-qbcd4       1/1     Running   0          47m   192.168.1.26   kube-node-f94c   <none>           <none>
pod/frontend-5b8c7979d8-fggr6    1/1     Running   0          18m   192.168.1.27   kube-node-f94c   <none>           <none>
前端吊舱内部的卷曲给了我:

Rebuilt URL to: localhost:4200/
*   Trying ::1...
* TCP_NODELAY set
* connect to ::1 port 4200 failed: Connection refused
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 4200 (#0)
> GET / HTTP/1.1
> Host: localhost:4200
> User-Agent: curl/7.52.1
> Accept: */*
> 
< HTTP/1.1 200 OK
< X-Powered-By: Express
< Access-Control-Allow-Origin: *
< Accept-Ranges: bytes
< Content-Type: text/html; charset=UTF-8
< Content-Length: 761
< ETag: W/"2f9-Ft4snhWFNqmPXU8vVB/M50CiWRU"
< Date: Tue, 14 Apr 2020 12:54:50 GMT
< Connection: keep-alive
< 
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>S3 Manoeuvre Selector</title>
  <base href="/">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
  <link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500&display=swap" rel="stylesheet">
  <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
</head>
<body class="mat-typography">
  <app-root></app-root>
<script src="runtime.js" type="module"></script><script src="polyfills.js" type="module"></script><script src="styles.js" type="module"></script><script src="vendor.js" type="module"></script><script src="main.js" type="module"></script></body>
</html>
* Curl_http_done: called premature == 0
* Connection #0 to host localhost left intact
重建的URL到:localhost:4200/
*正在尝试::1。。。
*TCP_节点集
*连接到::1端口4200失败:连接被拒绝
*正在尝试127.0.0.1。。。
*TCP_节点集
*已连接到本地主机(127.0.0.1)端口4200(#0)
>GET/HTTP/1.1
>主机:localhost:4200
>用户代理:curl/7.52.1
>接受:*/*
> 
正如您所看到的,它最初失败,但解决正确。有什么解决办法吗

你知道为什么angular前端的网关不好,而mongo db或express api不好吗

更新:
对服务yaml进行任意更改4-6次并使用“kubectl apply-f”将不会导致网关错误并按预期工作,即使服务yaml与最初用于启动服务的yaml完全相同。无法发现任何原因,这可能是…

似乎您将前端与s3服务器机架混为一谈。该服务看起来不错,因为它已填充了
端点。拒绝连接到pod IP通常意味着pod中没有容器侦听您正在对其执行curl的端口(4200)。

您似乎已将服务定义为LoadBalancer类型。LoadBalancer类型是您在“最外层”范围内使用并向外部网络公开的类型,而
ClusterIp
服务更适合集群本身


您的实际入口控制器将为您负责负载平衡和路由(如果您在使用该服务的平台上,则该控制器应实际拥有负载平衡服务)。

添加kubectl的输出描述svc前端。您是否能够通过从集群上的另一个pod访问pod ip来访问前端应用程序?根据请求添加前端说明。如果我卷曲在另一个吊舱内,我会得到404错误?连接被拒绝:连接到192.168.2.20端口4200失败:连接被拒绝您正在192.168.2.20上执行curl,它不是前端的IP,而是s3的IP。pod是否正在侦听端口4200…这是nodejs应用程序吗?如果是nodejs,那么它是否应该更新端口3000,相同的结果,我只是在原始帖子时复制了错误的curl结果。更新后的帖子。吊舱内的卷曲最初似乎失败了,这似乎是问题所在?这里有决议吗?吊舱正在监听4200端口?你能添加吊舱/部署吗。在docker文件中显示端口,就像我在nodes服务器中所做的一样。以下内容:kubectl exec frontend-5b8c7979d8-lxqnn——printenv|grep服务[…]FRONTEND_SERVICE_HOST=192.168.229.217 FRONTEND_SERVICE_PORT_4200=4200 FRONTEND_SERVICE_PORT=4200请确保应用程序绑定到0.0.0.0而不是localhost或127.0.0.1ng SERVICE——主机0.0.0和ng SERVICE——disableHostCheck——主机0.0.0.0已被试用kubectl描述服务显示除traefik入口外的所有服务都是“类型:ClusterIP”。
Rebuilt URL to: localhost:4200/
*   Trying ::1...
* TCP_NODELAY set
* connect to ::1 port 4200 failed: Connection refused
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 4200 (#0)
> GET / HTTP/1.1
> Host: localhost:4200
> User-Agent: curl/7.52.1
> Accept: */*
> 
< HTTP/1.1 200 OK
< X-Powered-By: Express
< Access-Control-Allow-Origin: *
< Accept-Ranges: bytes
< Content-Type: text/html; charset=UTF-8
< Content-Length: 761
< ETag: W/"2f9-Ft4snhWFNqmPXU8vVB/M50CiWRU"
< Date: Tue, 14 Apr 2020 12:54:50 GMT
< Connection: keep-alive
< 
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>S3 Manoeuvre Selector</title>
  <base href="/">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
  <link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500&display=swap" rel="stylesheet">
  <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
</head>
<body class="mat-typography">
  <app-root></app-root>
<script src="runtime.js" type="module"></script><script src="polyfills.js" type="module"></script><script src="styles.js" type="module"></script><script src="vendor.js" type="module"></script><script src="main.js" type="module"></script></body>
</html>
* Curl_http_done: called premature == 0
* Connection #0 to host localhost left intact