Introduction
Environment variables are essential for configuring cloud-based applications dynamically. These variables can either be regular environment variables or secrets (sensitive data like API keys and credentials). This document outlines the process for adding both types of variables to customer applications deployed via Helm and GitLab CI/CD.
Adding a Regular Environment Variable
If the environment variable is not a secret, it only needs to be added to the Helm configuration files and pushed to the repository.
Step 1: Update Helm Configuration
Modify the appropriate Helm values files in the following order:
Deployment-specific configuration files (values-<deployment>.yaml)
Environment-specific configuration files (values-<env>.yaml)
General configuration files (values.yaml) – only if the variable is not found in the previous files.
Example of adding a regular environment variable in a Helm values file:
env:
NEW_VARIABLE: "your-value-here"
Step 2: Push Changes to GitLab CI/CD
Commit and push the updated Helm configuration files to the repository.
GitLab CI/CD will detect the changes and re-deploy the application automatically.
Adding a Secret Environment Variable
If the environment variable is sensitive, it must be securely stored in AWS Secrets Manager before updating Helm configurations.
Step 1: Update AWS Secrets Manager
Navigate to AWS Secrets Manager in the AWS Management Console.
Click Store a new secret.
Choose Other type of secrets and enter the key-value pair for the new secret.
Click Next, provide a meaningful secret name, and save it.
Step 2: Update Helm Secret Configuration
Modify the Helm files in the following order:
Deployment-specific configuration files (values-<deployment>.yaml)
Environment-specific configuration files (values-<env>.yaml)
General configuration files (values.yaml) – only if the variable is not found in the previous files.
Ensure that the secret is referenced correctly in the Helm templates (secrets.yaml or deployment.yaml).
Step 3: Push Changes to GitLab CI/CD
Commit and push the updated Helm configuration files to the repository.
GitLab CI/CD will detect the changes and re-deploy the application automatically.
Troubleshooting
Issue: New environment variable is not reflected in the application
Solution:
Ensure that the variable is added to the correct Helm values file.
Verify that the Helm templates correctly reference the variable.
Check GitLab CI/CD pipeline logs for errors.
If using a secret, confirm that it is correctly stored in AWS Secrets Manager and referenced properly in the Helm files.
Issue: GitLab CI/CD did not trigger a deployment
Solution:
Ensure that the Helm configuration changes were committed and pushed.
Check if GitLab CI/CD is enabled for the repository.
Review the GitLab CI/CD pipeline logs for any failures.
Issue: Application crashes after deployment
Solution:
Verify that the environment variable values are correctly set.
Ensure that no conflicting values exist in multiple Helm configuration files.
If using a secret, confirm that it is being retrieved correctly from AWS Secrets Manager.