# N8N - Simple Stateful Deployment

> For the complete documentation index, see [llms.txt](https://iqbalaissaoui.com/llms.txt).

Small update to the ephemeral deployment of n8n that we covered in [Deploy n8n on K8s with the 8gears chart](deploy-n8n-on-k8s-with-8gears-chart.html)

We will be making it stateful in this article by attaching a persistent volume using Oracle Block Volumes.

## Create Low-Cost Storage Class

I'm already using the 200GB that comes with Oracle's free tier to run the k8s 4-node cluster. Unfortunately, you can't make a block volume with a smaller size than 50GB

It's probably overkill for this, but you can reduce cost by dropping the VPUs to 0. For this reason, we'll define a low-cost storage class:

```HCL
############################
# (2b) Custom StorageClass tuned for 0 VPUs
############################
resource "kubernetes_storage_class_v1" "oci_bv_lower_cost" {
  metadata {
    name = "oci-bv-lower-cost"
  }

  storage_provisioner    = "blockvolume.csi.oraclecloud.com"
  reclaim_policy         = "Delete"
  volume_binding_mode    = "WaitForFirstConsumer"
  allow_volume_expansion = true

  parameters = {
    vpusPerGB = "0"
  }
}
```

We can then use it with 8gears chart:

## n8n Stateful Deployment

Snippet from the chart

```HCL
# === Persistence managed by the chart ===
persistence:
  enabled: true
  type: dynamic             # chart creates a PVC for you
  storageClass: ${kubernetes_storage_class_v1.oci_bv_lower_cost.metadata[0].name}
  accessModes:
    - ReadWriteOnce
  size: ${var.n8n_pvc_size}
  # optional: keep the PVC during helm uninstall
  # annotations:
  #   helm.sh/resource-policy: keep
# Ensure single replica with SQLite
replicaCount: 1
```

## Source Code

> **Tip:**
> References
>
>
>
> The source code for the examples mentioned in this article can be found here:
>
>
>
> [GitLab: n8n.tf Terraform configuration](https://gitlab.com/iaissaoui/examples/-/blob/main/deployments/n8n.tf?ref_type=heads)

