<p>I have an application that is supposed to expose 2 x ports and the application does not have the default healthcheck endpoint of <code>/</code> that returns <code>200</code>, so at the moment, I supply a custom healthcheck endpoint just for 1 port. I haven't exposed the other port yet as I don't know how to provide another custom healthcheck endpoint for the same application.</p>
<p>This is how my Terraform configuration looks like.</p>
<pre><code>resource &quot;kubernetes_deployment&quot; &quot;core&quot; {
  metadata {
    name = &quot;core&quot;
    labels = {
      app = &quot;core&quot;
    }
  }

  spec {
    replicas = 1

    selector {
      match_labels = {
        app = &quot;core&quot;
      }
    }

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

          port {
            container_port = 8069
          }

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

          image_pull_policy = &quot;IfNotPresent&quot;
        }
      }
    }
  }
}

resource &quot;kubernetes_service&quot; &quot;core_service&quot; {
  metadata {
    name = &quot;core-service&quot;
  }
  spec {
    type = &quot;NodePort&quot;
    selector = {
      app = &quot;core&quot;
    }
    port {
      port = 8080
      protocol = &quot;TCP&quot;
      target_port = &quot;8069&quot;
    }
  }
}
</code></pre>
<p>How do I tell GKE to expose the other port (8072) and use a custom healthcheck endpoint for both ports?</p>

billydh
<p>There are a <a href="https://cloud.google.com/kubernetes-engine/docs/how-to/ingress-features#configuring_ingress_features" rel="nofollow noreferrer">GKE Ingress feature</a> called <code>FrontendConfig</code> and <code>BackendConfig</code> <a href="https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/" rel="nofollow noreferrer">custom resource definitions (CRDs)</a> that allow you to further customize the load balancer, you can use a <a href="https://cloud.google.com/kubernetes-engine/docs/how-to/ingress-features#unique_backendconfig_per_service_port" rel="nofollow noreferrer">Unique BackendConfig per Service port</a> to specify a custom <code>BackendConfig</code> for a specific port or ports of a Service or <code>MultiClusterService</code>, using a key that matches the port's name or port's number. The Ingress controller uses the specific <code>BackendConfig</code> when it creates a load balancer backend service for a referenced Service port</p>
<p>When using a <code>BackendConfig</code> to provide a <a href="https://cloud.google.com/kubernetes-engine/docs/how-to/ingress-features#direct_health" rel="nofollow noreferrer">custom load balancer health check</a>, the port number you use for the load balancer's health check can differ from the Service's <code>spec.ports[].port</code> number, here's an example of the service and the custom health check:</p>
<p>Service:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
annotations:
cloud.google.com/backend-config: '{&quot;ports&quot;: {
&quot;service-reference-a&quot;:&quot;backendconfig-reference-a&quot;,
&quot;service-reference-b&quot;:&quot;backendconfig-reference-b&quot;
}}'
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
</code></pre>
<p>Custom Health Check:</p>
<pre><code>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
</code></pre>
