kubernetes - 将 GCloud 中 GKE 中的运行状况检查从 HTTP 更改为 TCP 后重置

标签 kubernetes google-cloud-platform

我正在开发一个 Kubernetes 集群,我将服务从 GCloud Ingress 引导到我的服务。服务端点之一作为 HTTP 的健康检查失败,但作为 TCP 传递。

当我将 GCloud 中的健康检查选项更改为 TCP 时,健康检查通过,我的端点工作,但几分钟后,GCloud 上的健康检查将该端口重置为 HTTP,健康检查再次失败,给了我一个我的端点上的 502 响应。

我不知道这是 Google Cloud 内部的错误还是我在 Kubernetes 中做错了什么。我在这里粘贴了我的 YAML 配置:

命名空间

apiVersion: v1
kind: Namespace
metadata:
  name: parity
  labels:
    name: parity

存储类
apiVersion: storage.k8s.io/v1
metadata:
  name: classic-ssd
  namespace: parity
provisioner: kubernetes.io/gce-pd
parameters:
  type: pd-ssd
  zones: us-central1-a
reclaimPolicy: Retain

secret
apiVersion: v1
kind: Secret
metadata:
    name: tls-secret 
    namespace: ingress-nginx 
data:
    tls.crt: ./config/redacted.crt
    tls.key: ./config/redacted.key

有状态集
apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
  name: parity
  namespace: parity
  labels:
    app: parity
spec:
  replicas: 3 
  selector:
    matchLabels:
      app: parity
  serviceName: parity
  template:
    metadata:
      name: parity
      labels:
        app: parity
    spec:
      containers:
        - name: parity
          image: "etccoop/parity:latest"
          imagePullPolicy: Always
          args:
          - "--chain=classic"
          - "--jsonrpc-port=8545"
          - "--jsonrpc-interface=0.0.0.0"
          - "--jsonrpc-apis=web3,eth,net"
          - "--jsonrpc-hosts=all"
          ports:
            - containerPort: 8545
              protocol: TCP
              name: rpc-port
            - containerPort: 443
              protocol: TCP
              name: https
          readinessProbe:
            tcpSocket:
              port: 8545
            initialDelaySeconds: 650
          livenessProbe:
            tcpSocket:
              port: 8545
            initialDelaySeconds: 650
          volumeMounts:
            - name: parity-config
              mountPath: /parity-config
              readOnly: true
            - name: parity-data
              mountPath: /parity-data
      volumes:
      - name: parity-config
        secret:
          secretName: parity-config
  volumeClaimTemplates:
    - metadata:
        name: parity-data
      spec:
        accessModes: ["ReadWriteOnce"]
        storageClassName: "classic-ssd"
        resources:
          requests:
            storage: 50Gi

服务
apiVersion: v1
kind: Service
metadata:
  labels:
    app: parity
  name: parity
  namespace: parity
  annotations:
    cloud.google.com/app-protocols: '{"my-https-port":"HTTPS","my-http-port":"HTTP"}'
spec:
  selector:
    app: parity
  ports:
  - name: default
    protocol: TCP
    port: 80
    targetPort: 80
  - name: rpc-endpoint
    port: 8545
    protocol: TCP
    targetPort: 8545
  - name: https
    port: 443
    protocol: TCP
    targetPort: 443
  type: LoadBalancer

入口
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
    name: ingress-parity
    namespace: parity
    annotations:
        #nginx.ingress.kubernetes.io/rewrite-target: /
        kubernetes.io/ingress.global-static-ip-name: cluster-1
spec:
    tls:
      secretName: tls-classic
      hosts:
        - www.redacted.com
    rules:
    - host: www.redacted.com
      http:
        paths:
        - path: /
          backend:
            serviceName: web
            servicePort: 8080
        - path: /rpc
          backend:
            serviceName: parity 
            servicePort: 8545

问题

我已经编辑了主机名等,但这是我的基本配置。我还从这里的文档中运行了一个 hello-app 容器进行调试:https://cloud.google.com/kubernetes-engine/docs/tutorials/hello-app

这是 / 上的入口端点指向 hello-app 的端口 8080服务。这很好用,不是问题,但只是为了澄清而在此提及。

所以,这里的问题是,在使用 GKE 和我在 Google Cloud 上的入口 LoadBalancer(入口文件中的 cluster-1 全局静态 IP 名称)创建集群之后,然后在上面的文件中创建 Kubernetes 配置,Health- /rpc 的检查失败当我转到 Google Compute Engine -> Health Check -> Specific Health-Check for the /rpc 时,Google Cloud 上的端点端点。

当我编辑该健康检查以不使用 HTTP 协议(protocol)而是使用 TCP 协议(protocol)时,/rpc 的健康检查通过端点,然后我可以很好地 curl 它,它会返回正确的响应。

问题是几分钟后,即使我将其编辑为 TCP,相同的运行状况检查也会返回 HTTP 协议(protocol),然后运行状况检查失败,当我再次 curl 时收到 502 响应。

在 kubernetes 中创建 Ingress 之前,我不确定是否有办法将 Google Cloud Health Check 配置附加到我的 Kubernetes Ingress。也不知道为什么要重置它,不知道它是 Google Cloud 上的错误还是我在 Kubernetes 中做错了什么。如果你注意到我的 statefulset部署,我指定了livenessProbereadinessProbe使用 TCP 检查端口 8545。

650 秒的延迟是由于这里的票证问题,通过将延迟增加到大于 600 秒(以避免提到的竞争条件)解决了这个问题:https://github.com/kubernetes/ingress-gce/issues/34

我真的不确定为什么 Google Cloud 运行状况检查在我将其指定为 TCP 后会重置回 HTTP。任何帮助,将不胜感激。

最佳答案

我找到了一个解决方案,我在/healthz 端点上的有状态集上添加了一个新的健康检查容器,并配置了入口的健康检查以检查 kubernetes 分配的 8080 端口上的端点作为 HTTP 类型的健康检查,这使它工作。

当它是 TCP 时,为什么会发生重置并不是很明显。

关于kubernetes - 将 GCloud 中 GKE 中的运行状况检查从 HTTP 更改为 TCP 后重置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55283804/

相关文章:

google-cloud-platform - GCP Api Gateway 是否可以更新配置文件的代码,或者我是否需要每次都创建一个全新的配置?

load-balancing - Google Cloud HTTP 平衡器和 gzip

scala - 带有 IntelliJ 和 SBT 的自定义文件夹结构的 Uber jar

kubernetes - AKS 不创建 KUBERNETES_SERVICE_HOST 和 KUBERNETES_SERVICE_PORT 环境变量

azure - 在缩小 Azure Kubernetes 服务 (AKS) 中的节点后如何重新安排我的 pod?

node.js - nginx 响应 "301 moved permanently"

python - Google Cloud - 收到无效的 JSON 负载。未知名称 "encoding"at 'config' : Proto field is not repeating, 无法启动列表

javascript - 在 Google App Engine 上重命名 index.html

kubernetes - 获取最近创建的 Pod 的名称

Kubernetes:无法删除 PersistentVolumeClaim (pvc)