【问题标题】:GCP GKE - Healthcheck for native GKE ingress for the same application with 2 exposed portsGCP GKE - 具有 2 个暴露端口的同一应用程序的原生 GKE 入口的健康检查
【发布时间】:2021-09-14 23:15:12
【问题描述】:

我有一个应该公开 2 个端口的应用程序,并且该应用程序没有返回 200 的默认运行状况检查端点 /,所以目前,我只为 1 个端口提供自定义运行状况检查端点.我还没有公开其他端口,因为我不知道如何为同一个应用程序提供另一个自定义运行状况检查端点。

这就是我的 Terraform 配置的样子。

resource "kubernetes_deployment" "core" {
  metadata {
    name = "core"
    labels = {
      app = "core"
    }
  }

  spec {
    replicas = 1

    selector {
      match_labels = {
        app = "core"
      }
    }

    template {
      metadata {
        labels = {
          app = "core"
        }
      }
      spec {
        container {
          name = "core"
          image = "asia.gcr.io/admin/core:${var.app_version}"

          port {
            container_port = 8069
          }

          readiness_probe {
            http_get {
              path = "/web/database/selector"
              port = "8069"
            }
            initial_delay_seconds = 15
            period_seconds = 30
          }

          image_pull_policy = "IfNotPresent"
        }
      }
    }
  }
}

resource "kubernetes_service" "core_service" {
  metadata {
    name = "core-service"
  }
  spec {
    type = "NodePort"
    selector = {
      app = "core"
    }
    port {
      port = 8080
      protocol = "TCP"
      target_port = "8069"
    }
  }
}

如何告诉 GKE 公开另一个端口 (8072) 并为两个端口使用自定义运行状况检查端点?

【问题讨论】:

    标签: kubernetes google-cloud-platform terraform google-kubernetes-engine


    【解决方案1】:

    有一个名为FrontendConfigBackendConfig custom resource definitions (CRDs)GKE Ingress feature 允许您进一步自定义负载均衡器,您可以使用Unique BackendConfig per Service port 为特定端口指定自定义BackendConfig服务或MultiClusterService,使用与端口名称或端口号匹配的密钥。 Ingress 控制器在为引用的服务端口创建负载均衡器后端服务时使用特定的BackendConfig

    当使用BackendConfig 提供custom load balancer health check 时,您用于负载均衡器健康检查的端口号可能与服务的spec.ports[].port 号码不同,以下是服务和自定义健康检查的示例:

    服务:

    apiVersion: v1
    kind: Service
    metadata:
    annotations:
    cloud.google.com/backend-config: '{"ports": {
    "service-reference-a":"backendconfig-reference-a",
    "service-reference-b":"backendconfig-reference-b"
    }}'
    spec:
      ports:
      - name: port-name-1
         port: port-number-1
         protocol: TCP
         targetPort: 50000
      - name: port-name-2
         port: port-number-2
         protocol: TCP
         targetPort: 8080
    

    自定义健康检查:

    apiVersion: cloud.google.com/v1
    kind: BackendConfig
    metadata:
    name: my-backendconfig
     spec:
        healthCheck:
        checkIntervalSec: interval
        timeoutSec: timeout
        healthyThreshold: health-threshold
        unhealthyThreshold: unhealthy-threshold
        type: protocol
        requestPath: path
        port: port
    

    【讨论】:

    • 我们如何使用 terraform 创建这些自定义健康检查?我读到现在不支持这个,但是有什么解决方法吗?
    猜你喜欢
    • 1970-01-01
    • 2022-06-24
    • 1970-01-01
    • 1970-01-01
    • 2020-01-03
    • 2022-11-25
    • 1970-01-01
    • 2023-01-24
    • 1970-01-01
    相关资源
    最近更新 更多