By default, the Deployment in Kubernetes retains 10 ReplicaSets [1]. This number can be configured by setting the .spec.revisionHistoryLimit to a desired number.

The following is an example on how to retain just 3 old ReplicaSets in my ‘’n8n’’ Deployment.

➜ k get replicasets -n n8n
NAME             DESIRED   CURRENT   READY   AGE
n8n-57c89d6b7d   0         0         0       91d
n8n-5f9fb9c459   0         0         0       80d
n8n-666b9476f    0         0         0       80d
n8n-66cd6bd8c6   1         1         1       74d
n8n-6888cc89bd   0         0         0       91d
n8n-7466c456f8   0         0         0       91d
n8n-74dfd6cb8c   0         0         0       80d
n8n-f8f8f6d7b    0         0         0       237d

Let set .spec.revisionHistoryLimit to 3:

➜ git diff 15.n8n-deployment.yaml

apps/n8n/15.n8n-deployment.yaml

──────────┐
12: spec: │
──────────┴──────────────────────────────────────────────────────────────────────────────────────────────────────
│ 12 │      service: n8n                                 │ 12 │      service: n8n
│ 13 │  strategy:                                        │ 13 │  strategy:
│ 14 │    type: Recreate                                 │ 14 │    type: Recreate
│    │                                                   │ 15 │  revisionHistoryLimit: 3
│ 15 │  template:                                        │ 16 │  template:
│ 16 │    metadata:                                      │ 17 │    metadata:
│ 17 │      labels:                                      │ 18 │      labels:
➜ kubeclt apply -f 15.n8n-deployment.yaml

Verify the result:

➜ k get replicasets -n n8n
NAME             DESIRED   CURRENT   READY   AGE
n8n-5f9fb9c459   0         0         0       80d
n8n-666b9476f    0         0         0       80d
n8n-66cd6bd8c6   1         1         1       74d
n8n-74dfd6cb8c   0         0         0       80d

References: