Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

176
Views
How to replace the in-memory storage with persistent storage using kustomize

I'm trying to replace the in-memory storage of Grafana deployment with persistent storage using kustomize. What I'm trying to do is that I'm removing the in-memory storage and then mapping persistent storage. But When I'm deploying it then it is giving me an error.

Error

The Deployment "grafana" is invalid: spec.template.spec.containers[0].volumeMounts[1].name: Not found: "grafana-storage"

Kustomize version

{Version:kustomize/v4.0.5 GitCommit:9e8e7a7fe99ec9fbf801463e8607928322fc5245 BuildDate:2021-03-08T20:53:03Z GoOs:linux GoArch:amd64}

kustomization.yaml

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- https://github.com/prometheus-operator/kube-prometheus
- grafana-pvc.yaml
patchesStrategicMerge:
- grafana-patch.yaml

grafana-pvc.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: grafana-storage
  namespace: monitoring
  labels:
    billingType: "hourly"
    region: sng01
    zone: sng01
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 2Gi
  storageClassName: ibmc-file-bronze

grafana-patch.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: grafana
  name: grafana
  namespace: monitoring
spec:
  template:
    spec:
      volumes:
        # use persistent storage for storing users instead of in-memory storage
        - $patch: delete  <---- trying to remove the previous volume
          name: grafana-storage
        - name: grafana-storage
          persistentVolumeClaim:
            claimName: grafana-storage
      containers:
        - name: grafana
          volumeMounts:
            - name: grafana-storage
              mountPath: /var/lib/grafana

please help.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The $patch: delete doesn't seem to work as I would expect.

It may be nice to open an issue on kustomize github: https://github.com/kubernetes-sigs/kustomize/issues and ask developers about it.


Although here is the patch I tried, and it seems to work:

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: grafana
  name: grafana
  namespace: monitoring
spec:
  template:
    spec:
      volumes:
        - name: grafana-storage
          emptyDir: null
          persistentVolumeClaim:
            claimName: grafana-storage
      containers:
        - name: grafana
          volumeMounts:
            - name: grafana-storage
              mountPath: /var/lib/grafana

Based on https://github.com/kubernetes/community/blob/master/contributors/design-proposals/api-machinery/add-new-patchStrategy-to-clear-fields-not-present-in-patch.md

The following should also work in theory:

spec:
  volumes:
    - $retainKeys:
      - name
      - persistentVolumeClaim
      name: grafana-storage
      persistentVolumeClaim:
        claimName: grafana-storage

But in practise it doesn't, and I think that's because kustomize has its own implementaions of strategic merge (different that k8s).

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!