使用 Istio 和 Cloud Armor 的 GKE 集群中的后端不健康

问题描述

我正在尝试在 GKE 集群前使用 Cloud Armor Adaptive protection。我从 this guide from contino-engineering 找到了 always up always on 和这个。但是,这两个都使用了一个简单的 hello world 示例,我正在尝试使用 istio 中的 bookinfo 示例来部署(希望?)更现实的部署。 (我也使用 onlineboutique 得到了类似的结果。)

问题是后端永远不会健康。我假设这是因为健康检查员无法访问健康检查服务,但我对这一切都不熟悉,不确定如何验证。

这是我部署集群的TF。请注意,ip_allocation_policy 相当于 --enable-ip-aliases gcloud 参数......我认为。我在这里启用 CloudRun 并不是为了简化事情。

集群 tf

resource "google_container_cluster" "primary" {
  provider = google-beta
  name     = "my-gke-cluster"
  location = "us-central1"

  # We can't create a cluster with no node pool defined,but we want to only use
  # separately managed node pools. So we create the smallest possible default
  # node pool and immediately delete it.
  remove_default_node_pool = true
  initial_node_count       = 4

  networking_mode = "VPC_NATIVE"
  ip_allocation_policy {
    // Set to blank to have a range chosen with the default size
    cluster_ipv4_cidr_block = ""
  }

  addons_config {
    istio_config {
      disabled = false
      auth = "AUTH_MUTUAL_TLS"
    }
  }
}

获得信用后,我应用我的后端配置来允许(?)/启用(?)健康检查。

cat <<EOF > /tmp/backendconfig.yaml
apiVersion: cloud.google.com/v1
kind: BackendConfig
Metadata:
  name: my-backendconfig
spec:
  healthCheck:
    requestPath: /healthz/ready
    port: 15021
    type: HTTP
  securityPolicy:
    name: my-security-policy
EOF

kubectl apply -n istio-system -f /tmp/backendconfig.yaml

然后我修补 ingressgateway:


cat <<EOF > /tmp/patch.yaml
spec:
   type: NodePort
Metadata:
  annotations:
    cloud.google.com/neg: '{"ingress": true}'
    cloud.google.com/backend-config: '{"default": "my-backendconfig"}'
status: null
EOF
kubectl patch svc istio-ingressgateway -n istio-system --patch-file /tmp/patch.yaml

最后,应用入口资源

cat <<EOF > /tmp/istio-ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
Metadata:
  name: my-ingress
spec:
  rules:
    - http:
        paths:
          - path: /*
            pathType: ImplementationSpecific
            backend:
              service:
                name: istio-ingressgateway
                port: 
                  number: 80
EOF

kubectl apply -n istio-system -f /tmp/istio-ingress.yaml

推出新的 Pod 以取得良好的效果

kubectl rollout restart deploy -n istio-system

等待 10 多分钟后,我在 Google 控制台中看到新的负载均衡器显示不健康的后端:

Load balancer

解决方法

@Anant Swaraj 我追踪到我的 VirtualService 的端口不匹配:

# ---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: health
spec:
  hosts:
  - "*"
  gateways:
  - bookinfo-gateway
  http:
  - match:
    - headers:
        user-agent:
          prefix: GoogleHC
      method:
        exact: GET
      uri:
        exact: /
    rewrite:
      authority: istio-ingressgateway:15020
      uri: /healthz/ready
    route:
      - destination:
          host: istio-ingressgateway
          port:
            number: 15020

我在那里使用了 15020,但在我的 BackendConfig 中使用了 15021。看了这么多帖子,我也不太确定我从哪里得到的。

但正如@Anant Swaraj 提到的,另外还需要一个防火墙规则。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...