Seeking assistance with Terraform for GKE ingress in n8n deployment

I’m trying to set up n8n on a GKE cluster using its Helm chart. The main issue is that the ingress keeps dropping the session when pointing to the app. It works fine when I access the pod directly, so it seems to be an ingress problem.

I want to add session affinity to the ingress, but I’m not sure how to do this with Terraform. Another option might be using an Nginx ingress, but I’m new to that.

Here’s a simplified version of my Terraform config:

resource "google_compute_managed_ssl_certificate" "custom_ssl" {
  name = "my-app-ssl"
  managed {
    domains = ["myapp.example.com"]
  }
}

resource "helm_release" "my_app" {
  chart = "my-custom-chart"
  name  = "my-release"
  
  set {
    name  = "config.database.host"
    value = "db.example.com"
  }
}

resource "kubernetes_ingress" "my_app_ingress" {
  metadata {
    name = "my-app-ingress"
    annotations = {
      "ingress.gcp.kubernetes.io/pre-shared-cert" = google_compute_managed_ssl_certificate.custom_ssl.name
    }
  }
  spec {
    backend {
      service_name = helm_release.my_app.name
      service_port = 80
    }
  }
}

Any ideas on how to add session affinity or improve this setup? Thanks!

hey tom, i’ve had similar issues. try adding this annotation to ur ingress:

kubernetes.io/ingress.class: gce”
networking.gce.io/v1beta1.FrontendConfig: my-frontendconfig”

Then create a FrontendConfig resource with sessionAffinity. that should help with the session drops. gl!

I’ve encountered similar challenges with GKE ingress and n8n deployments. One effective solution is to implement a Network Load Balancer (NLB) instead of the default HTTP(S) Load Balancer. This approach often resolves session persistence issues.

To achieve this, you’ll need to modify your Terraform configuration. Add the following annotation to your kubernetes_ingress resource:

kubernetes.io/ingress.class”: “gce-internal”

Additionally, create a new kubernetes_service resource with type: LoadBalancer and annotation:

cloud.google.com/load-balancer-type”: “Internal”

This setup should provide better session handling and improve overall performance. Remember to adjust your firewall rules accordingly to accommodate the NLB.

I’ve dealt with similar ingress issues in GKE, and one approach that worked well for me was switching to the NGINX Ingress Controller. It offers more flexibility and better session management right out of the box.

To implement this, you’ll first need to install the NGINX Ingress Controller in your cluster using Helm. Once installed, update your Terraform configuration to specify the NGINX ingress class and add relevant annotations for session affinity. For example, your ingress resource could include annotations like:

kubernetes.io/ingress.class”: “nginx”
nginx.ingress.kubernetes.io/affinity”: “cookie”
nginx.ingress.kubernetes.io/session-cookie-name”: “route”
nginx.ingress.kubernetes.io/session-cookie-expires”: “172800”
nginx.ingress.kubernetes.io/session-cookie-max-age”: “172800”

This setup provided a more robust method to maintain session persistence in my deployments, and it might work well for your use case too.