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

时间:2021-05-25 00:18:11

标签: kubernetes istio istio-gateway

问题

我正在尝试学习 Istio,并且正在设置我的 Istio Ingress-Gateway。当我进行设置时,有以下端口选项 (as indicated here):

  • 端口
  • 节点端口
  • 目标端口

NodePort 对我来说很有意义。这是 Ingress-Gateway 将在 Kubernetes 集群中的每个工作节点上侦听的端口。到达那里的请求将使用 Ingress Gateway CRD 路由到 Kubernetes 集群。

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

TargetPort 对我来说是个谜。我已经看到一些关于它的文档,用于普通的 Istio 网关(说它是 only applicable when using ServiceEntries),但对于 Ingress-Gateway 没有任何意义。

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

更多详情

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

我使用以下配置设置了 Istio Operator following this tutorial

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,因为我发现 this release notes 表示 Istio 将选择安全的默认值。

我尝试按照this tutorial中的步骤进行操作。

我尝试了该教程中指示的 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 设置为什么有任何建议,或者如果我遗漏了其他内容,我很乐意听到。

2 个答案:

答案 0 :(得分:2)

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

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

有关这些概念的说明,请参阅 Kubernetes Service 的文档。

另见 Difference between targetPort and port in Kubernetes Service definition

所以目标端口是 Ingress Gateway 的 Pod 的容器接收流量的地方。

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

其他详细信息:

Istio Operator 描述了 Ingress Gateway,它本身由一个 Kubernetes Service 和一个 Kubernetes Deployment 组成。通常它部署在 istio-system 中。您可以检查 istio-ingressgateway 的 Kubernetes Service,它会匹配该 YAML 的规范。

因此,Istio Ingress Gateway 实际上是在与其容器对话。 但是,这主要是 Istio Ingress Gateway 的实现细节,与您为应用定义的 Service 和 VirtualService 无关。

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

答案 1 :(得分:0)

我仍然不太明白 TargetPort 在做什么,但我已经完成了教程。

我返回了一个卸载的 Istio(通过删除操作员配置然后删除 istio 命名空间)。然后我重新安装了它,但我将指定节点端口的配置部分取出。

然后我运行了一个 kubectl get namespace istio-ingressgateway -o yaml -n istio-system。这向我展示了 istio 入口网关使用的端口默认值。然后我去更新了我的 yaml 以便操作员匹配(除了我想要的自定义 NodePort)。那行得通。

最后,yaml 看起来是这样的:

apiVersion: install.istio.io/v1alpha1
kind: IstioOperator
metadata:
  name: istio-controlplane
  namespace: istio-system
spec:
  components:    
    ingressGateways:
    - enabled: true
      k8s:
        service:
          ports:
          - name: status-port
            nodePort: 32562
            port: 15021
            protocol: TCP
            targetPort: 15021
          - name: http2
            nodePort: 30980
            port: 80
            protocol: TCP
            targetPort: 8080
          - name: https
            nodePort: 32013
            port: 443
            protocol: TCP
            targetPort: 8443           
        hpaSpec:
          minReplicas: 2
      name: istio-ingressgateway
    pilot:
      enabled: true
      k8s:
        hpaSpec:
          minReplicas: 2
  profile: default

我仍然想了解 TargetPort 在做什么。因此,如果有人可以回答这个问题(同样,在 Istio Ingress Gateway 服务(不是 istio 网关)的上下文中),那么我会接受这个答案。