Seeking advice on GKE ingress configuration for n8n deployment via Terraform

I’m trying to set up n8n on a GKE cluster using its Helm chart. The main issue I’m facing is with the ingress. When I configure it to point to the app, the session keeps dropping. It seems to be an ingress-related problem because accessing the pod directly works fine.

I want to enable session affinity on the ingress, but I’m not sure how to do this with Terraform. Another option I’m considering is setting up an Nginx ingress, but I’m new to that. Any help or suggestions for a better ingress solution would be great!

Here’s a simplified version of my Terraform config for n8n:

resource "google_compute_managed_ssl_certificate" "n8n_cert" {
  name = "my-n8n-cert"
  managed {
    domains = ["n8n.example.com"]
  }
}

resource "helm_release" "n8n_app" {
  chart      = "n8n"
  name       = "my-n8n"
  namespace  = "n8n-namespace"
  values     = [file("n8n_config.yaml")]
  
  set {
    name  = "db.host"
    value = "my-db-host"
  }
}

resource "kubernetes_ingress" "n8n_ingress" {
  metadata {
    name = "n8n-ingress"
    annotations = {
      "ingress.gcp.kubernetes.io/pre-shared-cert" = google_compute_managed_ssl_certificate.n8n_cert.name
    }
  }
  spec {
    backend {
      service_name = helm_release.n8n_app.name
      service_port = 80
    }
  }
}

Any ideas on how to improve this setup or implement session affinity?

As someone who’s deployed n8n on GKE multiple times, I can share a few insights that might help. The session dropping issue you’re experiencing is quite common with the default GKE ingress when dealing with stateful applications like n8n.

One approach that’s worked well for me is using the Nginx Ingress Controller instead of the default GKE ingress. It offers more flexibility and better session management out of the box. You can install it via Helm and then configure your ingress resource to use the Nginx class.

To implement this, you’d need to add the Nginx Ingress Controller to your Terraform config, then update your kubernetes_ingress resource to use the Nginx class. You can also easily enable session affinity with a simple annotation.

Another option worth considering is using Google Cloud Armor in conjunction with your current setup. It can provide additional layer 7 protection and help with session management.

Regardless of the approach you choose, make sure to properly configure health checks and readiness probes for your n8n pods. This can significantly improve the stability of your deployment.

I’ve encountered similar issues with GKE ingress and n8n deployments. One effective solution I’ve found is to use the Google Cloud Load Balancer (GCLB) instead of the default GKE ingress. GCLB provides better session affinity and more control over traffic routing.

To implement this, you’ll need to modify your Terraform configuration. Add a google_compute_backend_service resource and configure it with session affinity. Then, create a google_compute_url_map and google_compute_target_https_proxy to route traffic to your backend service.

For the Helm release, ensure you’re exposing the n8n service as a NodePort. This allows the GCLB to reach your service directly.

If you prefer sticking with Kubernetes ingress, consider using the nginx-ingress controller. It offers more flexibility and better session management. You can install it via Helm and then configure your ingress resource to use the nginx class.

Remember to adjust your security groups and firewall rules accordingly when implementing these changes.

hey, i’ve had similar probs with n8n on GKE. have u tried using nginx ingress controller? it’s way better for handling sessions. just add it to ur terraform and update the ingress resource. also, make sure ur health checks are set up right. that can make a big difference. good luck!