Search code examples
kuberneteskubernetes-helm

How to bind values in a helm chart from an HTTP request?


I want to bind some variables based on the return of an HTTP request. I imagine something like this:

name: {{ curl -s 'https://something.com/users/1' | jq -r '.name' }}

Is there a suitable way to do something like this or equivalent?


Solution

  • Helm has no way to run shell commands or other subprocesses, and no general way to make HTTP callouts.

    The closest you can come to this is using command substitution in your host shell in combination with the --set option:

    name: {{ .Values.name }}
    
    helm install ... \
      --set name=$(curl -s 'https://something.com/users/1' | jq -r '.name')
    

    This will create a fixed value across the entire installation; helm get values would show you what that is.

    Since this does create essentially a fixed install-time value, you can also run the curl command, add the result to the chart's values.yaml file or another helm install -f YAML file, and commit the result to source control. This would give you a trackable history of what deployment values were used at a given point in time.

    Depending on how you're using the value, you could also have your application make the HTTP call itself as part of its startup sequence, or use an init container to make the call and leave its result in an emptyDir volume. Those approaches would make the call at pod startup time rather than at deployment time, and would repeat the call for each replica, but if the remote value changed, you could more easily restart the pods without redeploying.