Chat Zalo Chat Messenger Phone Number Đăng nhập
Helm Chart Install: Advanced Usage of the “Set” Argument - ITNEXT

Helm Chart Install: Advanced Usage of the “Set” Argument – ITNEXT

When you install

Helm charts with the helm install command, the -set argument allows you to define the values used in chart templates.

The -set argument is an alternative to defining the value in a values.yaml file.

A simple use of -set looks like this

:$ helm install codecentric/keycloak -set keycloak.replicas=2 Conversely, to set the same value with a values.yaml file, you would add the value to the file

and then use the -f argument to specify the path to the file. # values.yamlkeycloak

: replicas: 2

There are some special cases where it is difficult to specify a YAML property/value on the command line.

These special cases involve properties and values that contain characters that conflict with YAML syntax or undocumented behaviors.

A common solution to handle these special values is to reuse a values.yaml file. However, it is not feasible to use values.yaml in certain situations.

A common situation in which it is not feasible to use a values.yaml file is when values or properties are expected to be provided at run time as dynamic values.

Dynamic values cannot be inserted or used in values.yaml. A shell script can provide dynamic value capability.

In this example, the shell script prompts the user for input, and then injects the user’s input into the Helm graph through the -set argument.

#!/bin/bash# read dynamic valueread -p “Keycloak replicas: ” replicas# set dynamic valuehelm install codecentric/keycloak -set keycloak.replicas=$replicas

The previous example is not possible using a values.yaml file.

Arrays are defined in a values.yaml file like this

:# values.yamlkeycloak: ingress: hosts: – “auth1” – “auth2”

Helm provides two methods for defining array values on the command line

.

The first method is to wrap the list of values with {}. The elements of the array are delimited with commas.

$ helm install codecentric/keycloak -set ‘keycloak.ingress.hosts={auth1,auth2}’

The second method of defining an array value on the command line is to specify individual array elements per index

. $ helm install codecentric/keycloak -set ‘keycloak.ingress.hosts[0]=auth1’ -set ‘keycloak.ingress.hosts[1]=auth2’When

property names contain special characters, they do not require any special syntax in a values.yaml file.

# values.yamlkeycloak: podLabels: app.kubernetes.io/part-of: security However,

on the command line, you must use to escape special

characters in the property name. $ helm install codecentric/keycloak -set ‘keycloak.podLabels.app.kubernetes.io/part-of=

security’Special characters that require escape are defined in the Helm source code. They are ., [, ,, and =.

In a values.yaml file, multiline strings are defined using standard YAML syntax

:# values.yamlkeycloak: extraEnv: | – name: KEYCLOAK_HTTP_PORT value: “80” – name: KEYCLOAK_HOSTNAME value: auth.k8salliance.com

Note that the extraEnv value is actually a string even though it contains YAML syntax. The Keycloak Helm chart reads the value as a string, and then processes the string as a Helm template.

Unfortunately, it

is not possible to include newline characters in value strings on the command line with escape characters (for example, n) as you would expect.

You can set this same value on the command line by enclosing the entire property key/value in quotation marks.

$ helm install codecentric/keycloak -set “keycloak.extraEnv=- name: KEYCLOAK_HTTP_PORT value: “80”- name: KEYCLOAK_HOSTNAME value: auth.k8salliance.com”

The above command-line syntax will produce the same value as values.yaml.

Contact US