kubernetes 如何分享GKE LB IP?[已关闭]

lf3rwulv  于 2023-02-11  发布在  Kubernetes
关注(0)|答案(2)|浏览(173)

此问题似乎与a specific programming problem, a software algorithm, or software tools primarily used by programmers无关。如果您认为此问题与another Stack Exchange site的主题有关,您可以留下评论,说明在何处可以回答此问题。
2天前关闭。
Improve this question
我有2组Pod。一组侦听80/443,另一组侦听其他端口。我希望使用来自外部负载均衡器的单个IP根据端口路由到这两组中的任何一组。我已经查看了入口,但它希望根据路径路由。路径在/中是相同的,只是端口不同。这可能吗?
这是我的想法:

apiVersion: v1
kind: Service
metadata:
  name: website-service
spec:
  type: LoadBalancer
  selector:
    app: website
  ports:
  - protocol: TCP
    port: 80
    targetPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: test
spec:
  type: LoadBalancer
  selector:
    app.kubernetes.io/name: test
  ports:
  - name: port1
    nodePort: 32600
    port: 1800
    protocol: TCP
    targetPort: 1801
  - name: port1
    nodePort: 31060
    port: 12582
    protocol: TCP
    targetPort: 12583

入口配置:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: ingress-resource
  annotations:
    kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
spec:
  rules:
  - host: myhost.gcp.io
    http:
      paths:
      - backend:
          serviceName: app1
          servicePort: 80
        path: /
      - backend:
          serviceName: app2
          servicePort: 14789
        path: /
8dtrkrch

8dtrkrch1#

不幸的是,这样做是不可能的。只有当多个服务在不同的主机上列出时,入口才允许您监听同一路径上的多个服务。例如:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: ingress-resource
  annotations:
    kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
spec:
  rules:
  - host: foo.bar.com
    http:
      paths:
      - backend:
          serviceName: app1
          servicePort: 80
  - host: bar.foo.com
    http:
      paths:
      - backend:
          serviceName: app2
          servicePort: 14789

因此,只有当您可以使用两台主机时,它才能正常工作。
有关入口的更多详细信息,请参见here

j8yoct9x

j8yoct9x2#

我最终使用Traefik来处理路由,并按预期工作。如上所述的Nginx入口不会在不同端口上处理同一主机的同一路径

相关问题