Extending the timeout of a Kubernetes service in GCP


Gcp · Ingress · K8s · Timeout

1 minute

This is related to a previous post about Kubernetes services. This time, it’s about extending the timeout of an Ingress. We had a situation where we had to download a huge file from one of our exposed services. The download takes about two minutes to complete. This didn’t really worked out since by default, GCP load balancers that are associated with k8s Ingresses have a timeout value of 30s. For a time, we just did manual updates by going to the GCP k8s Services and Ingress console, opening the backend service under the Ingress, and editing the Timeout section to the desired seconds. But since we do have a cluster blue/green deployment, we had to do this every time we recreate our clusters.

Enter BackendConfig custom resource. With this, we can associate a BackendConfig resource to the service in question using GCP-specific annotations. Reusing the reverse proxy YAML from this post, we add a BackendConfig resource.

apiVersion: cloud.google.com/v1beta1
kind: BackendConfig
  name: serviceproxy-backendconfig
  timeoutSec: 7200
    drainingTimeoutSec: 60


apiVersion: v1
kind: Service
  name: serviceproxy
    beta.cloud.google.com/backend-config: '{"ports": {"80":"serviceproxy-backendconfig"}}'
  type: NodePort
  - name: http
    protocol: TCP
    port: 80
    targetPort: 80
    app: serviceproxy

Deploying this will set the timeout of the service to two hours.