Home > database >  is it possible to add lables for services when deploying helm charts?
is it possible to add lables for services when deploying helm charts?

Time:06-02

I am trying to deploy mysql server with the help of bitnami helm chart.

The chart seems to create two services (mysql & mysql-headless) and I want to add a unique lable to the mysql-headless

with kubectl it is straight forward as following:

kubectl label service mysql-headless consul.hashicorp.com/service-ignore="true"

I did try to change the podLables for the values.ymal but it didn't work. Adding in commonLabels did work, but then it is added to both services.

values.yml

commonLabels: { "consul.hashicorp.com/service-ignore": "true" }

secondary:
  podAntiAffinityPreset: hard
  podLabels: { "consul.hashicorp.com/service-ignore": "true" }

is there anyway to achive this by editing values file for the helm chart?

Please note that I am deploying the charts with terraform.

resource "helm_release" "mysql" {

  name          = "mysql"
  repository    = "https://charts.bitnami.com/bitnami"
  chart         = "mysql"
  version       = "9.1.2"
  values        = [file("${path.module}/helm/values.yml")]
  namespace     = var.namespace
  recreate_pods = true

}

CodePudding user response:

If you actually look at the Helm template for the headless service it only has the standard labels and the .Values.commonLabels

  labels: {{- include "common.labels.standard" . | nindent 4 }}
    app.kubernetes.io/component: primary
    {{- if .Values.commonLabels }}
    {{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
    {{- end }}

So without modifying the chart or using a post renderer, there's no way to set a label for the headless service but not the main service.

  • Related