Pass dynamic environment-specific configurations in score-helm

This section describes how to pass dynamic environment-specific configuration to the Workload during deployment.

Substitute environment configurations

To use environment configurations, declare your variable names in your score.yaml file.

In the following example, the FRIEND variable sources its value from the NAME property in the resources section.

  • NAME
apiVersion: score.dev/v1b1

metadata:
  name: hello-world

containers:
  hello:
    image: busybox
    command: ["/bin/sh"]
    args: ["-c", "while true; do echo Hello $${FRIEND}!; sleep 5; done"]
    variables:
      FRIEND: ${resources.env.NAME}

resources:
  env:
    type: environment
    properties:
      NAME:
        type: string
        default: World

environment configurations file

Declare your environment configurations.

  1. Create a env.yaml file and add your environment variables.
env:
  NAME: John
  1. When running score-helm run, you’ll want to pass the --values flag where env.yaml imported values file.
score-helm run -f ./score.yaml \
  --values ./env.yaml \
  -o ./values.yaml

The following is the output of the previous command.

containers:
  hello:
    args:
      - -c
      - while true; do echo Hello $${FRIEND}!; sleep 5; done
    command:
      - /bin/sh
    env:
      - name: FRIEND
        value: John
    image:
      name: busybox

Generate a Helm file

Generate a Helm values.yaml file and specify the name or absolute path to Helm starter scaffold.

helm create -p ../path-to-your/values.yaml hello

The following is the results from the previous command.

NAME: hello
LAST DEPLOYED: Wed Nov 1 00:00:00 2022
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None

The following is the generated Kubernetes deployment object.

# Source: hello/templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello
  labels:
    helm.sh/chart: hello-0.1.0
    app.kubernetes.io/name:
    app.kubernetes.io/instance: hello
    app.kubernetes.io/version: "0.1.0"
    app.kubernetes.io/managed-by: Helm
spec:
  selector:
    matchLabels:
      app.kubernetes.io/name:
      app.kubernetes.io/instance: hello
  template:
    metadata:
      labels:
        app.kubernetes.io/name:
        app.kubernetes.io/instance: hello
    spec:
      containers:
        - name: hello
          image: "busybox"
          command:
            - /bin/sh
          args:
            - -c
            - while true; do echo Hello $${FRIEND}!; sleep 5; done
          env:
            - name: FRIEND
              value: John