In Helm, Release.Name is a built-in variable that represents the name of the Helm release. This variable is typically available in templates, but it's not directly available in values.yaml. However, you can work around this by using Helm templates to inject the Release.Name into the values during rendering.

Using Release.Name in values.yaml via Templates

  1. Modify values.yaml: You can reference a placeholder in values.yaml that will be replaced by the value of Release.Name at runtime. For example:

     
    appName: "{{ .Release.Name }}-app"
    replicaCount: 2
    
  2. Modify the Deployment Template to Use the Value: In your Helm templates (e.g., deployment.yaml), use the appName from values.yaml.

     
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: {{ .Values.appName }}
    spec:
      replicas: {{ .Values.replicaCount }}
      template:
        metadata:
          labels:
            app: {{ .Values.appName }}
          spec:
            containers:
              - name: {{ .Values.appName }}
                image: your-image:latest
    
    

Important Notes

  • Direct Usage in values.yaml: Directly writing {{ .Release.Name }} in values.yaml will not work because values.yaml does not get templated on its own. The templating only occurs within .yaml files under the templates folder.
  • Templating within values.yaml: Helm doesn’t render templates inside values.yaml. Instead, you can define placeholders in values.yaml and replace them when the template is processed.

Alternative Approach: Defining Release.Name in the Template with Default Values

You can define default values in your templates using default and Helm's templating engine if Release.Name is not provided directly.

 
# values.yaml
appName: "default-app-name"
replicaCount: 2

In your template, you can set the name dynamically:

 
# deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .Values.appName | default .Release.Name }}
spec:
  replicas: {{ .Values.replicaCount }}
  template:
    metadata:
      labels:
        app: {{ .Values.appName | default .Release.Name }}
    spec:
      containers:
        - name: {{ .Values.appName | default .Release.Name }}
          image: your-image:latest

This approach gives you flexibility by allowing you to use the value defined in values.yaml or fallback to the Release.Name if it’s not provided.