3.4. 第 4 步 - 设置网关
要连接链接,以便在两个或多个集群中使用 DNS 来平衡流量,您必须使用共享主机定义网关。您将使用基于根域的通配符主机名的 HTTPS 侦听器来定义此定义。如前文所述,您必须将这些资源应用到所有集群。
注意
现在,网关设置为只接受来自同一命名空间的 HTTPRoute。这样,您可以限制谁可以使用网关,直到它准备好常规使用。
流程
输入以下命令来创建网关:
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检查网关的状态,如下所示:
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}'您的网关应被接受并编程,这意味着有效并分配一个外部地址。
但是,如果您检查 HTTPS 侦听器状态,您会看到它尚未编程,或者准备好因为错误的 TLS 配置接受流量:
kubectl get gateway ${gatewayName} -n ${gatewayNS} -o=jsonpath='{.status.listeners[0].conditions[?(@.type=="Programmed")].message}'连接链接可使用 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
有关配置指标的更多信息,请参阅 连接链接 Observability 指南。