首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >GKE入侵域无法在一个主机下路由多条路径

GKE入侵域无法在一个主机下路由多条路径
EN

Stack Overflow用户
提问于 2019-06-22 16:30:24
回答 1查看 9.6K关注 0票数 1

我无法在- host: api.mysite.com下找到任何一条与GKE大会一起工作的路径,我不明白为什么。当我尝试这些路线时,我得到404。

通过下面的示例,我希望api.mysite.com/v1/api.mysite.com/v2/能够路由到适当的服务(我通过nodeport公开了这些服务)。不幸的是,我只得到404的回报。

代码语言:javascript
复制
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: gce-ingress
  namespace: default
  annotations:
    kubernetes.io/ingress.global-static-ip-name: my-global-ip
spec:
  rules:
  - host: mysite.com
    http:
      paths:
      - backend:
        serviceName: webserver
        servicePort: 8080
  - host: www.mysite.com
    http:
      paths:
      - backend:
        serviceName: webserver
        servicePort: 8080
  - host: api.mysite.com
    http:
      paths:
      - path: /v2/*
        backend:
          serviceName: api-v2
          servicePort: 9000
      - path: /v1/*
        backend:
          serviceName: api-v1
          servicePort: 8000

公开服务的节点:

代码语言:javascript
复制
apiVersion: v1
kind: Service
metadata:
  name: webserver
  labels:
    app: webserver
  namespace: default
spec:
  selector:
    app: webserver
  type: NodePort
  ports:
  - port: 8080
    name: http
    protocol: TCP
    targetPort: 8080
---
apiVersion: v1
kind: Service
metadata:
  name: api-v2
  labels:
    app: api-v2
  namespace: default
spec:
  selector:
    app: api-v2
  type: NodePort
  ports:
  - port: 9000
    name: http
    protocol: TCP
    targetPort: 8080
---
apiVersion: v1
kind: Service
metadata:
  name: api-v1
  labels:
    app: api-v1
  namespace: default
spec:
  selector:
    app: api-v1
  type: NodePort
  ports:
  - port: 8000
    name: http
    protocol: TCP
    targetPort: 8080

当我测试入口(真实主机名和ip被编辑)时的结果:

代码语言:javascript
复制
$ curl api.mysite.com/v1/ -v
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying 123.123.123.123...
* TCP_NODELAY set
* Connected to api.mysite.com (123.123.123.123) port 80 (#0)
> GET /v1/ HTTP/1.1
> Host: api.mysite.com
> User-Agent: curl/7.55.1
> Accept: */*
>
< HTTP/1.1 404 Not Found
< Server: gunicorn/19.9.0
< Date: Mon, 24 Jun 2019 00:01:34 GMT
< Content-Type: text/html
< X-Frame-Options: SAMEORIGIN
< Content-Length: 77
< Via: 1.1 google
<
{ [77 bytes data]
100    77  100    77    0     0     77      0  0:00:01 --:--:--  0:00:01   706
* Connection #0 to host api.mysite.com left intact
<h1>Not Found</h1><p>The requested resource was not found on this server.</p>
代码语言:javascript
复制
$ curl api.mysite.com/v2/ -v
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying 123.123.123.123...
* TCP_NODELAY set
* Connected to api.mysite.com (123.123.123.123) port 80 (#0)
> GET /v2/ HTTP/1.1
> Host: api.mysite.com
> User-Agent: curl/7.55.1
> Accept: */*
>
< HTTP/1.1 404 Not Found
< Server: gunicorn/19.9.0
< Date: Mon, 24 Jun 2019 00:01:37 GMT
< Content-Type: text/html
< X-Frame-Options: SAMEORIGIN
< Content-Length: 77
< Via: 1.1 google
<
{ [77 bytes data]
100    77  100    77    0     0     77      0  0:00:01 --:--:--  0:00:01   987
* Connection #0 to host api.mysite.com left intact
<h1>Not Found</h1><p>The requested resource was not found on this server.</p>
代码语言:javascript
复制
$ curl api.mysite.com/v1 -v
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying 123.123.123.123...
* TCP_NODELAY set
* Connected to api.mysite.com (123.123.123.123) port 80 (#0)
> GET /v1 HTTP/1.1
> Host: api.mysite.com
> User-Agent: curl/7.55.1
> Accept: */*
>
< HTTP/1.1 404 Not Found
< Date: Mon, 24 Jun 2019 00:01:40 GMT
< Content-Length: 21
< Content-Type: text/plain; charset=utf-8
< Via: 1.1 google
<
{ [21 bytes data]
100    21  100    21    0     0     21      0  0:00:01 --:--:--  0:00:01   269
* Connection #0 to host api.mysite.com left intact
default backend - 404
代码语言:javascript
复制
$ curl api.mysite.com/v2 -v
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying 123.123.123.123...
* TCP_NODELAY set
* Connected to api.mysite.com (123.123.123.123) port 80 (#0)
> GET /v2 HTTP/1.1
> Host: api.mysite.com
> User-Agent: curl/7.55.1
> Accept: */*
>
< HTTP/1.1 404 Not Found
< Date: Mon, 24 Jun 2019 00:01:44 GMT
< Content-Length: 21
< Content-Type: text/plain; charset=utf-8
< Via: 1.1 google
<
{ [21 bytes data]
100    21  100    21    0     0     21      0  0:00:01 --:--:--  0:00:01   333
* Connection #0 to host api.mysite.com left intact
default backend - 404
EN

回答 1

Stack Overflow用户

发布于 2019-06-25 13:53:49

为了重现这个问题,我遵循了下面的文档,该文档解释了如何设置HTTP负载平衡,然后作为一个可选的东西,您可以保留一个静态IP地址,并在同一个负载均衡器上为多个应用程序提供服务。

按照上面的URL一步一步地操作对我来说很好:

https://cloud.google.com/kubernetes-engine/docs/tutorials/http-balancer

希望它对你有用。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56717214

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档