3.4. 第 4 步 - 设置网关


要连接链接,以便在两个或多个集群中使用 DNS 来平衡流量,您必须使用共享主机定义网关。您将使用基于根域的通配符主机名的 HTTPS 侦听器来定义此定义。如前文所述,您必须将这些资源应用到所有集群。

注意

现在,网关设置为只接受来自同一命名空间的 HTTPRoute。这样,您可以限制谁可以使用网关,直到它准备好常规使用。

流程

  1. 输入以下命令来创建网关:

    kubectl apply -f - <<EOF
    apiVersion: gateway.networking.k8s.io/v1
    kind: Gateway
    metadata:
      name: ${gatewayName}
      namespace: ${gatewayNS}
      labels:
        kuadrant.io/gateway: "true"
    spec:
        gatewayClassName: istio
        listeners:
        - allowedRoutes:
            namespaces:
              from: Same
          hostname: "*.${rootDomain}"
          name: api
          port: 443
          protocol: HTTPS
          tls:
            certificateRefs:
            - group: ""
              kind: Secret
              name: api-${gatewayName}-tls
            mode: Terminate
    EOF
    Copy to Clipboard Toggle word wrap
  2. 检查网关的状态,如下所示:

    kubectl get gateway ${gatewayName} -n ${gatewayNS} -o=jsonpath='{.status.conditions[?(@.type=="Accepted")].message}'
    kubectl get gateway ${gatewayName} -n ${gatewayNS} -o=jsonpath='{.status.conditions[?(@.type=="Programmed")].message}'
    Copy to Clipboard Toggle word wrap

    您的网关应被接受并编程,这意味着有效并分配一个外部地址。

  3. 但是,如果您检查 HTTPS 侦听器状态,您会看到它尚未编程,或者准备好因为错误的 TLS 配置接受流量:

    kubectl get gateway ${gatewayName} -n ${gatewayNS} -o=jsonpath='{.status.listeners[0].conditions[?(@.type=="Programmed")].message}'
    Copy to Clipboard Toggle word wrap

    连接链接可使用 TLSPolicy 来帮助解决这个问题,该策略在下一步中描述。

3.4.1. 可选:配置从网关实例中提取的指标

如果您在集群中设置了 Prometheus,您可以将 PodMonitor 配置为直接从 Gateway pod 中提取指标。指标需要此配置,如 istio_requests_total。您必须在运行网关的命名空间中添加以下配置:

kubectl apply -f - <<EOF
apiVersion: monitoring.coreos.com/v1
kind: PodMonitor
metadata:
  name: istio-proxies-monitor
  namespace: ${gatewayNS}
spec:
  selector:
    matchExpressions:
      - key: istio-prometheus-ignore
        operator: DoesNotExist
  podMetricsEndpoints:
    - path: /stats/prometheus
      interval: 30s
      relabelings:
        - action: keep
          sourceLabels: ["__meta_kubernetes_pod_container_name"]
          regex: "istio-proxy"
        - action: keep
          sourceLabels:
            ["__meta_kubernetes_pod_annotationpresent_prometheus_io_scrape"]
        - action: replace
          regex: (\d+);(([A-Fa-f0-9]{1,4}::?){1,7}[A-Fa-f0-9]{1,4})
          replacement: "[\$2]:\$1"
          sourceLabels:
            [
              "__meta_kubernetes_pod_annotation_prometheus_io_port",
              "__meta_kubernetes_pod_ip",
            ]
          targetLabel: "__address__"
        - action: replace
          regex: (\d+);((([0-9]+?)(\.|$)){4})
          replacement: "\$2:\$1"
          sourceLabels:
            [
              "__meta_kubernetes_pod_annotation_prometheus_io_port",
              "__meta_kubernetes_pod_ip",
            ]
          targetLabel: "__address__"
        - action: labeldrop
          regex: "__meta_kubernetes_pod_label_(.+)"
        - sourceLabels: ["__meta_kubernetes_namespace"]
          action: replace
          targetLabel: namespace
        - sourceLabels: ["__meta_kubernetes_pod_name"]
          action: replace
          targetLabel: pod_name
EOF
Copy to Clipboard Toggle word wrap

有关配置指标的更多信息,请参阅 连接链接 Observability 指南

返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat