29

I could find both fullnameOverride and nameOverride in Helm chart.Please help clarifying what is the difference between these two with an example.

Rad4
  • 1,936
  • 8
  • 30
  • 50

2 Answers2

48

nameOverride replaces the name of the chart in the Chart.yaml file, when this is used to construct Kubernetes object names. fullnameOverride completely replaces the generated name.

These come from the template provided by Helm for new charts. A typical object in the templates is named

name: {{ include "<CHARTNAME>.fullname" . }}

If you install a chart with a deployment with this name, and where the Chart.yaml file specifies name: chart-name...

  • helm install release-name ., the Deployment will be named release-name-chart-name
  • helm install release-name . --set nameOverride=name-override, the Deployment will be named release-name-name-override
  • helm install release-name . --set fullnameOverride=fullname-override, the Deployment will be named fullname-override

The generated ...fullname template is (one code branch omitted, still from the above link)

{{- define "<CHARTNAME>.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}

So if fullnameOverride is provided, that completely replaces the rest of the logic in the template. Otherwise the name is constructed from the release name and the chart name, where nameOverride overrides the chart name.

PrasadK
  • 778
  • 6
  • 17
David Maze
  • 130,717
  • 29
  • 175
  • 215
  • Is it (always) considered a bad-practice to override it? – trallnag Jan 25 '21 at 15:40
  • 7
    Feels like this is trying to cover all possible use cases, turning into a needlessly confusing complication for most deployments. – Marcello Romani Jan 21 '22 at 15:40
  • 1
    The charts I generally work on were written before this was part of the standard template, and don't have this option. That having been said, I also get a lot of requests for various parts of the chart to be overridden in various ways, and the only way to allow this is via settings in the `values.yaml`. If you don't need to specify this (and I agree, you usually won't) just don't provide the value. – David Maze Jan 21 '22 at 16:05
-1

I tried (almost) all the options, my Helm version is 3 (v3.12.1);

Create a default image in a temporary local directory: C:\_tmp\my-example>helm create my-stuff

  • Case 1: leave values.yaml with empty values

nameOverride: ""

fullnameOverride: ""

From the folder created by Helm, execute the install command with the ‘generate-name’ option:

C:\_tmp\my-example\my-stuff>helm install --generate-name ./ --values ./values.yaml

This will install the nginx basic example; the Deployment and Service name are automatically generated, e.g. chart-1687255131-my-stuff

  • Case 2: leave values.yaml with empty values but specify the name in the command: C:\_tmp\my-example\my-stuff>helm install case2 ./ --values ./values.yaml

The difference from before is that the first part is not generated but the ‘case2’ value is used; from console or k8s command (kubectl get services) the generated service has been named case2-my-stuff

  • Case 3: execute

    C:\_tmp\my-example\my-stuff>helm install case3-from-command-line ./ --values ./values.yaml

The result (deployment & service) is case3-from-command-line-my-stuff

  • Case 4: override ‘name’ in values.yaml:

nameOverride: "case4"

fullnameOverride: ""

and execute

C:\_tmp\my-example\my-stuff>helm install case4-from-command-line ./ --values ./values.yaml

The result is case4-from-command-line (the nameOverride is ignored)

  • Case 5: override ‘full name’ in values.yaml:

    nameOverride: ""

    fullnameOverride: "case5"

and execute

`C:\_tmp\my-example\my-stuff>helm install case5-from-command-line ./ --values ./values.yaml`

The result is case5 (full name wins)

  • Case 6: override both

    nameOverride: "case6"

    fullnameOverride: "case6full"

and execute

`C:\_tmp\my-example\my-stuff>helm install case6-from-command-line ./ --values ./values.yaml`

Like before, full name wins: case6full

  • Case 7: override both but use --generate-name

    nameOverride: "case7"

    fullnameOverride: "case7full"

and execute

`C:\_tmp\my-example\my-stuff>helm install --generate-name ./ --values ./values.yaml`

The generate name option is ignored, case7full wins.

  • Case 8: override only fullname, use --generate-name

    nameOverride: ""

    fullnameOverride: "case8full"

and execute

`C:\_tmp\my-example\my-stuff>helm install --generate-name ./ --values ./values.yaml`

The generate name option is ignored, case8full wins. This seems to me the best option, I still don't understand the actual role of nameOverride, maybe this is due to the version 3 overriding the beahviour of version 2.

Diego Pascotto
  • 329
  • 2
  • 13