I had installed kube-prometheus-stack
from the helm chart repo prometheus-community
(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
As you can see, by default, grafana installed as Deployment
, but I want to change the kind to Statefulset
by changing it in its helm chart, instead of direct kubectl edit
on the cluster.
Following is the directory structure inside the kube-prometheus-stack
repo:
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
I am confused and stuck where exactly on this helm to change and tell grafana to install as Statefulset
instead of default Deployment
. Would be great if someone can help with it.
Here's how I found the answer. In a helm chart, if there is a folder named charts
, that means that the chart is declaring chart dependencies. Looking at the Chart.yaml
, we see the grafana dependency:
dependencies:
- name: grafana
version: "6.21.*"
repository: https://grafana.github.io/helm-charts
condition: grafana.enabled
Going to this link, We can look at their statefulset.yaml. Looking here we find that Grafana creates a stateful set using this condition:
{{- if and .Values.persistence.enabled (not .Values.persistence.existingClaim) (eq .Values.persistence.type "statefulset")}}
A dependent chart can still have its chart values overwritten if you have a section in your values.yaml
that has a top level tag of the dependency name. So in this case, the dependency is named grafana
, so we can override the values.yaml
of the dependent chart using this configuration:
grafana:
enabled: true
persistence:
enabled: true
type: statefulset
(For other configuration options see this repo. All of the values.yaml
from this chart can be overwritten as long as they are inside of the grafana:
block.)
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.
grafana:
enabled: false
Once you disable grafana, you can then install grafana on its own and either alter the generated manifests using something like Kustomize or a simple sed replace, or fork the grafana helm chart and use your own custom grafana chart that is deployed as a statefulset.