Helmfile Components
Helmfile components manage Kubernetes deployments using Helmfile, a declarative spec for deploying Helm charts. They allow you to manage Helm releases with the same stack-based configuration approach used for Terraform.
Available Configuration Sections
Helmfile components support the common configuration sections:
vars- Variables passed to helmfile.
env- Environment variables during execution.
settings- Integrations and metadata.
metadata- Component behavior and inheritance.
command- Override helmfile binary.
hooks- Lifecycle event handlers.
Component Structure
A typical Helmfile component configuration:
components:
helmfile:
nginx-ingress:
metadata:
component: nginx-ingress
vars:
chart_version: "4.7.1"
replica_count: 3
service_type: LoadBalancer
env:
KUBECONFIG: "{{ env \"HOME\" }}/.kube/config"
settings:
depends_on:
- component: eks
type: terraform
Helmfile Directory Structure
Helmfile components are located in the path configured in atmos.yaml:
# atmos.yaml
components:
helmfile:
base_path: components/helmfile
kubeconfig_path: /dev/shm
helm_aws_profile_pattern: "{namespace}-{tenant}-gbl-{stage}-helm"
cluster_name_pattern: "{namespace}-{tenant}-{environment}-{stage}-eks-cluster"
Example structure:
components/helmfile/
├── nginx-ingress/
│ └── helmfile.yaml
├── cert-manager/
│ └── helmfile.yaml
└── prometheus/
└── helmfile.yaml
Helmfile Template
Each helmfile component contains a helmfile.yaml that uses variables passed from Atmos:
components/helmfile/nginx-ingress/helmfile.yaml
Component-Type Defaults
Define defaults for all Helmfile components:
# Apply to all Helmfile components
helmfile:
vars:
timeout: 600
atomic: true
wait: true
env:
HELM_CACHE_HOME: /tmp/helm-cache
HELM_CONFIG_HOME: /tmp/helm-config
# Individual components
components:
helmfile:
nginx-ingress:
vars:
chart_version: "4.7.1"
Complete Example
stacks/orgs/acme/plat/prod/us-east-1.yaml
Running Helmfile Commands
Atmos provides commands that wrap Helmfile operations:
# Diff changes
atmos helmfile diff nginx-ingress -s plat-ue1-prod
# Apply changes
atmos helmfile apply nginx-ingress -s plat-ue1-prod
# Sync releases
atmos helmfile sync nginx-ingress -s plat-ue1-prod
# Destroy releases
atmos helmfile destroy nginx-ingress -s plat-ue1-prod
# Run any helmfile subcommand
atmos helmfile <subcommand> <component> -s <stack>
Environment Variables
Common environment variables for Helmfile components:
KUBECONFIG- Path to kubeconfig file.
HELM_CACHE_HOME- Helm cache directory.
HELM_CONFIG_HOME- Helm configuration directory.
HELM_DATA_HOME- Helm data directory.
AWS_PROFILE- AWS profile for EKS authentication.
HELM_EXPERIMENTAL_OCI- Enable OCI registry support.
Integration with Terraform
Helmfile components often depend on infrastructure created by Terraform:
components:
terraform:
eks:
vars:
cluster_name: acme-prod-eks
helmfile:
nginx-ingress:
vars:
# Reference Terraform outputs
cluster_name: "{{ .terraform_outputs.eks.cluster_name }}"
env:
KUBECONFIG: "{{ .terraform_outputs.eks.kubeconfig_path }}"
settings:
depends_on:
- component: eks
type: terraform
Values Handling
Variables from the vars section are passed to Helmfile and available in templates:
# In stack manifest
components:
helmfile:
my-app:
vars:
image_tag: "v1.2.3"
replicas: 5
resources:
requests:
cpu: "100m"
memory: "256Mi"
# In helmfile.yaml
releases:
- name: my-app
values:
- image:
tag: {{ .Values.image_tag | quote }}
replicaCount: {{ .Values.replicas }}
resources:
requests:
cpu: {{ .Values.resources.requests.cpu | quote }}
memory: {{ .Values.resources.requests.memory | quote }}
Best Practices
-
Use Dependencies: Define
depends_onto ensure Helmfile components deploy after their infrastructure dependencies. -
Centralize Chart Versions: Define chart versions in catalog defaults and override only when necessary.
-
Use Atomic Deployments: Set
atomic: trueto automatically roll back failed deployments. -
Manage Kubeconfig: Use environment variables or settings to manage kubeconfig paths consistently.
-
Version Pin Charts: Always specify explicit chart versions for reproducible deployments.
-
Separate Concerns: Create separate Helmfile components for distinct services rather than combining everything into one.