各种 Istio 端口是如何使用的?

2024-05-08

Question

我正在尝试学习 Istio,并且正在设置我的 Istio Ingress-Gateway。当我设置它时,有以下端口选项(如此处所示 https://istio.io/latest/docs/reference/config/istio.operator.v1alpha1/#ServicePort):

  • Port
  • NodePort
  • 目标端口

NodePort我感觉合理。这是 Ingress-Gateway 将在 Kubernetes 集群中的每个工作节点上侦听的端口。到达那里的请求将使用 Ingress Gateway CRD 路由到 Kubernetes 集群。

在示例中,Port通常设置为其匹配流量的公共端口(http 为 80,https 为 443 等)。我不明白 Istio 需要这个端口做什么,因为我没有看到任何流量使用除 NodePort 之外的任何东西。

TargetPort对我来说是个谜。我看过一些关于普通 Istio 网关的文档(说它是仅在使用 ServiceEntries 时适用 https://istio.io/latest/docs/reference/config/networking/gateway/#Port),但对于 Ingress-Gateway 来说没有任何意义。

我的问题是,相对于入口网关(不是普通网关),什么是入口网关?TargetPort?

更多细节

最后,我试图调试为什么我的入口流量收到“连接被拒绝”响应。

我设置了 Istio Operator按照本教程 https://istio.io/latest/docs/setup/install/operator/使用此配置:

apiVersion: install.istio.io/v1alpha1
kind: IstioOperator
metadata:
  name: istio-controlplane
  namespace: istio-system
spec:
  components:    
    ingressGateways:
    - enabled: true
      k8s:
        service:
          ports:
          - name: http2
            port: 80
            nodePort: 30980            
        hpaSpec:
          minReplicas: 2
      name: istio-ingressgateway
    pilot:
      enabled: true
      k8s:
        hpaSpec:
          minReplicas: 2
  profile: default

我省略了TargetPort从我的配置中因为我发现本发行说明 https://istio.io/latest/news/releases/1.7.x/announcing-1.7/upgrade-notes/#gateways-run-as-non-root也就是说,Istio 将选择安全的默认值。

我尝试按照中找到的步骤进行操作本教程 https://istio.io/latest/docs/tasks/traffic-management/ingress/ingress-control/.

我尝试了该教程中指示的curl命令:

curl -s -I -H Host:httpbin.example.com "http://10.20.30.40:30980/status/200"

我得到的答复是Failed to connect to 10.20.30.40 port 30980: Connection refused

但我可以 ping 通10.20.30.40很好,获取 NodePort 的命令返回30980.

所以我开始思考这也许是一个问题TargetPort我不明白的设置。

的检查istiod日志暗示我可能走在正确的轨道上。我跑:

kubectl logs -n istio-system -l app=istiod

在我发现的日志中:

warn    buildGatewayListeners: skipping privileged gateway port 80 for node istio-ingressgateway-dc748bc9-q44j7.istio-system as it is an unprivileged pod
warn    gateway has zero listeners for node istio-ingressgateway-dc748bc9-q44j7.istio-system

所以,如果你已经走到这一步了,那么哇!我感谢您阅读全部内容。如果您对我需要将 TargetPort 设置为什么有任何建议,或者如果我遗漏了其他内容,我很想听听。


Port、Nodeport 和 TargetPort 不是 Istio 的概念,而是 Kubernetes 的概念,更具体地说是 Kubernetes Services 的概念,这就是为什么 Istio Operator API 中没有对此进行详细描述。

Istio Operator API 公开了用于配置 Ingress Gateway 的 (Kubernetes) 服务的选项。

有关这些概念的说明,请参阅以下文档库伯内特服务 https://kubernetes.io/docs/concepts/services-networking/service/.

也可以看看Kubernetes 服务定义中 targetPort 和 port 的区别 https://stackoverflow.com/questions/49981601/difference-between-targetport-and-port-in-kubernetes-service-definition

因此,目标端口是 Ingress Gateway 的 Pod 容器接收流量的位置。

因此我认为,端口和目标端口的配置是特定于应用程序的,并且映射 80->8080 或多或少是任意的,即应用程序的“决定”。

额外细节:

Istio Operator 描述了 Ingress Gateway,它本身由 Kubernetes 服务和 Kubernetes 部署组成。通常部署在 istio-system 中。您可以检查 istio-ingressgateway 的 Kubernetes 服务,它将与该 YAML 的规范相匹配。

因此,Istio Ingress Gateway 实际上是在与其容器进行通信。 然而,这主要是 Istio Ingress Gateway 的实现细节,与您为应用程序定义的 Service 和 VirtualService 无关。

Ingressgateway 本身是一个服务,在您定义的端口(即 80)上接收流量,并将其转发到其容器上的 8080。然后它根据网关和VirtualServices配置的规则处理流量并将其发送到应用程序的服务。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

各种 Istio 端口是如何使用的? 的相关文章

随机推荐