返回到文章

采纳

编辑于 2年前

为什么ingress servicePort设置service的"port" 和 "targetPort"都可以?

ingress kubernetes k8s

今天我遇到了一个关于servicePort的误解。

我以为服务可以与ingress链接,只指定servicePort: 80,但是servicePort: 80servicePort: 8080 也都可以。

谁能帮助我理解为什么服务同时暴露porttargetPort,而不是只有port

Service (app)

spec:
  type: ClusterIP
  ports:
    - port: 80
      targetPort: 8080

Ingress (ingress-nginx)

spec:
  rules:
  - host: example.com
    http:
      paths:
      - path: /
        backend:
          serviceName: app
          servicePort: 8080