<p>I had installed <code>kube-prometheus-stack</code> from the helm chart repo <a href="https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack" rel="nofollow noreferrer">prometheus-community</a></p>
<pre><code>(k8s: minikube) $ kubectl get deploy,statefulset -n monitoring
NAME                                                       READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/kube-prometheus-stack-grafana              1/1     1            1           20d
deployment.apps/kube-prometheus-stack-kube-state-metrics   1/1     1            1           20d
deployment.apps/kube-prometheus-stack-operator             1/1     1            1           20d

NAME                                                               READY   AGE
statefulset.apps/alertmanager-kube-prometheus-stack-alertmanager   1/1     20d
statefulset.apps/prometheus-kube-prometheus-stack-prometheus       1/1     20d
</code></pre>
<p>As you can see, by default, grafana installed as <code>Deployment</code>, but I want to change the kind to <code>Statefulset</code> by changing it in its helm chart, instead of direct <code>kubectl edit</code> on the cluster.</p>
<p>Following is the directory structure inside the <code>kube-prometheus-stack</code> repo:</p>
<pre><code>kube-prometheus-stack vjwilson(k8s: minikube) $ ls
Chart.lock  charts  Chart.yaml  CONTRIBUTING.md  crds  README.md  templates  values.yaml

kube-prometheus-stack (k8s: minikube) $ tree -d
.
├── charts
│   ├── grafana
│   │   ├── ci
│   │   ├── dashboards
│   │   └── templates
│   │       └── tests
│   ├── kube-state-metrics
│   │   └── templates
│   └── prometheus-node-exporter
│       ├── ci
│       └── templates
├── crds
└── templates
    ├── alertmanager
    ├── exporters
    │   ├── core-dns
    │   ├── kube-api-server
    │   ├── kube-controller-manager
    │   ├── kube-dns
    │   ├── kube-etcd
    │   ├── kubelet
    │   ├── kube-proxy
    │   └── kube-scheduler
    ├── grafana
    │   └── dashboards-1.14
    ├── prometheus
    │   └── rules-1.14
    └── prometheus-operator
        └── admission-webhooks
            └── job-patch

30 directories
</code></pre>
<p>I am confused and stuck where exactly on this helm to change and tell grafana to install as <code>Statefulset</code> instead of default <code>Deployment</code>. Would be great if someone can help with it.</p>

<p>Here's how I found the answer. In a helm chart, if there is a folder named <code>charts</code>, that means that the chart is declaring chart dependencies. Looking at the <code>Chart.yaml</code>, we see the grafana dependency:</p>
<pre><code>dependencies:
- name: grafana
  version: &quot;6.21.*&quot;
  repository: https://grafana.github.io/helm-charts
  condition: grafana.enabled
</code></pre>
<p>Going to this link, We can look at their <a href="https://github.com/grafana/helm-charts/blob/main/charts/grafana/templates/statefulset.yaml" rel="nofollow noreferrer">statefulset.yaml</a>. Looking here we find that Grafana creates a stateful set using this condition:</p>
<pre><code>{{- if and .Values.persistence.enabled (not .Values.persistence.existingClaim) (eq .Values.persistence.type &quot;statefulset&quot;)}}
</code></pre>
<p>A dependent chart can still have its chart values overwritten if you have a section in your <code>values.yaml</code> that has a top level tag of the dependency name. So in this case, the dependency is named <code>grafana</code>, so we can override the <code>values.yaml</code> of the dependent chart using this configuration:</p>
<pre><code>grafana:
  enabled: true
  persistence:
    enabled: true
    type: statefulset
</code></pre>
<p>(For other configuration options <a href="https://github.com/grafana/helm-charts/tree/main/charts/grafana" rel="nofollow noreferrer">see this repo</a>. All of the <code>values.yaml</code> from this chart can be overwritten as long as they are inside of the <code>grafana:</code> block.)</p>
<p>The dependent chart is the official chart from Grafana. However, if this doesn't work for you (maybe you aren't using persistent volume claims), your second option is to disable the grafana dependency from the chart you are using and deploy a custom version of the Grafana chart.</p>
<pre><code>grafana:
  enabled: false
</code></pre>
<p>Once you disable grafana, you can then install grafana on its own and either alter the generated manifests using something like <a href="https://kustomize.io/" rel="nofollow noreferrer">Kustomize</a> or a simple <a href="https://linuxize.com/post/how-to-use-sed-to-find-and-replace-string-in-files/" rel="nofollow noreferrer">sed replace</a>, or fork the grafana helm chart and use your own custom grafana chart that is deployed as a statefulset.</p>
