【问题标题】:GCP GKE Ingress Health ChecksGCP GKE 入口运行状况检查
【发布时间】:2021-07-18 23:20:06
【问题描述】:

我有一个使用部署管理器在 GKE 中运行的部署和服务。除了我创建的入口报告服务处于永久不健康状态之外,我的服务的所有内容都正常工作。

需要明确的是,除了运行状况检查(以及因此,入口)之外,有关部署的所有内容都有效。这在之前(大约 2019 年末)有效,显然大约一年前,GKE 增加了一些对入口目标服务进行健康检查的额外要求,而我一直无法理解它们。

我已经对服务进行了明确的健康检查,它报告健康,但入口无法识别它。该服务使用 NodePort,但在部署时还打开了 containerPort 80,它确实使用 HTTP 200 响应本地 :80 上的请求,但显然这对部署的服务没有帮助。

集群本身与Deployment Manager example几乎完全相同

这是部署:

- name: {{ DEPLOYMENT }}
  type: {{ CLUSTER_TYPE }}:{{ DEPLOYMENT_COLLECTION }}
  metadata:
    dependsOn:
    - {{ properties['clusterType'] }}
  properties:
    apiVersion: apps/v1
    kind: Deployment
    namespace: {{ properties['namespace'] | default('default') }}
    metadata:
      name: {{ DEPLOYMENT }}
      labels:
        app: {{ APP }}
        tier: resters
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: {{ APP }}
          tier: resters
      template:
        metadata:
          labels:
            app: {{ APP }}
            tier: resters
        spec:
          containers:
          - name: rester
            image: {{ IMAGE }}
            resources:
              requests:
                cpu: 100m
                memory: 250Mi
            ports:
            - containerPort: 80
            env:
            - name: GCP_PROJECT
              value: {{ PROJECT }}
            - name: SERVICE_NAME
              value: {{ APP }}
            - name: MODE
              value: rest
            - name: REDIS_ADDR
              value: {{ properties['memorystoreAddr'] }}

...服务:

- name: {{ SERVICE }}
  type: {{ CLUSTER_TYPE }}:{{ SERVICE_COLLECTION }}
  metadata:
    dependsOn:
    - {{ properties['clusterType'] }}
    - {{ APP }}-cluster-nodeport-firewall-rule
    - {{ DEPLOYMENT }}
  properties:
    apiVersion: v1
    kind: Service
    namespace: {{ properties['namespace'] | default('default') }}
    metadata:
      name: {{ SERVICE }}
      labels:
        app: {{ APP }}
        tier: resters
    spec:
      type: NodePort
      ports:
      - nodePort: {{ NODE_PORT }}
        port: {{ CONTAINER_PORT }}
        targetPort: {{ CONTAINER_PORT }}
        protocol: TCP
      selector:
        app: {{ APP }}
        tier: resters

...明确的健康检查:

- name: {{ SERVICE }}-healthcheck
  type: compute.v1.healthCheck
  metadata:
    dependsOn:
    - {{ SERVICE }}
  properties:
    name: {{ SERVICE }}-healthcheck
    type: HTTP
    httpHealthCheck:
      port: {{ NODE_PORT }}
      requestPath: /healthz
      proxyHeader: NONE
    checkIntervalSec: 10
    healthyThreshold: 2
    unhealthyThreshold: 3
    timeoutSec: 5

...防火墙规则:

- name: {{ CLUSTER_NAME }}-nodeport-firewall-rule
  type: compute.v1.firewall
  properties:
    name: {{ CLUSTER_NAME }}-nodeport-firewall-rule
    network: projects/{{ PROJECT }}/global/networks/default
    sourceRanges:
    - 130.211.0.0/22
    - 35.191.0.0/16
    targetTags:
    - {{ CLUSTER_NAME }}-node
    allowed:
    - IPProtocol: TCP
      ports:
      - 30000-32767
      - 80

【问题讨论】:

  • 您是否使用共享 VPC? GKE 日志显示什么?

标签: google-cloud-platform google-kubernetes-engine google-deployment-manager


【解决方案1】:

您可以尝试在 Deployment 中的容器上定义 readinessProbe

这也是入口用来创建健康检查的指标(请注意,这些健康检查探测来自 GKE 外部)

根据我的经验,这些就绪性探测可以很好地让入口运行状况检查正常工作,

为此,您可以创建类似这样的东西,这是一个 TCP 探测器,我已经看到 TCP 探测器的性能更好。

readinessProbe:
          tcpSocket:
            port: 80
          initialDelaySeconds: 10
          periodSeconds: 10
  

所以这个探针会检查端口:80,这是我看到的这个服务中的 pod 使用的端口,这也有助于配置入口健康检查以获得更好的结果。

这里有一些helpful documentation 介绍如何创建入口健康检查可以基于的 TCP 就绪探测。

【讨论】:

    猜你喜欢
    • 2019-04-23
    • 2021-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-05
    相关资源
    最近更新 更多