Environment variables in score-helm

This section describes how to define environment variables for score-helm.

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

Generate a Helm values 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

Initialize the Workload Helm Chart Repository

Run the following command to initialize the Workload Helm chart repository.

helm repo add score-helm-charts https://score-spec.github.io/score-helm-charts

Once this is installed, you will be able to use the default score-helm-charts/workload Helm chart (you can adapt it for your own use case, find the source code here).

Install Helm values.yaml

Run the following command to deploy the score-helm-charts/workload Helm chart with the Helm values.yaml file generated previously.

helm install hello score-helm-charts/workload --values ./values.yaml

The following are the outputs of 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: workload/templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello
  labels:
    helm.sh/chart: workload-0.3.0
    app.kubernetes.io/name: hello
    app.kubernetes.io/instance: hello
    app.kubernetes.io/version: "0.3.0"
    app.kubernetes.io/managed-by: Helm
spec:
  selector:
    matchLabels:
      app.kubernetes.io/name: hello
      app.kubernetes.io/instance: hello
  template:
    metadata:
      labels:
        app.kubernetes.io/name: hello
        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