How to add a default value to a kubernetes helm template

6/17/2020

If I have a basic kubernetes helm template like below:

port: {{ .Values.Port }}

Is there a way to specify a default port if none is passed in?

-- jjbskir
kubernetes
kubernetes-helm

2 Answers

6/17/2020

In values.yaml you put Port: <port-number> which will be used if you don't pass the value using --set.

You can also set default like following

port: {{ default 1234 .Values.Port }}
# You can replace 1234 with your port number
-- hoque
Source: StackOverflow

6/17/2020

The designated place for default values according to the Helm documentation is the values.yaml. This is where to look first to peruse the default configuration of a Chart. Also, it can be overwritten if need be by providing a customized values.yaml from the command line.

Also, there is the default template function. The intention here is usage for computed default values, e.g.:

drink: {{ .Values.favorite.drink | default (printf "%s-tea" (include "fullname" .)) }}
-- Fritz Duchardt
Source: StackOverflow