What's Actually Happening

Helmfile sync command fails when trying to deploy Helm releases. Charts are not installed or upgraded successfully.

The Error You'll See

```bash $ helmfile sync

Error: Failed to render chart: template: chart/templates/deployment.yaml: error converting YAML to JSON ```

Release error:

bash
Error: Release my-release failed: unable to build kubernetes objects from release manifest

Environment error:

bash
Error: environment values file not found: environments/production.yaml

Dependency error:

bash
Error: chart "my-chart" not found in repository

Why This Happens

  1. 1.Chart syntax error - Invalid Helm template
  2. 2.Missing values file - Environment or release values not found
  3. 3.Repository not added - Helm repository missing
  4. 4.Dependency issue - Chart dependencies not updated
  5. 5.Kubeconfig issue - Cannot connect to cluster
  6. 6.Template rendering error - Values cause invalid YAML

Step 1: Check Helmfile Configuration

```bash # View helmfile.yaml: cat helmfile.yaml

# Validate helmfile syntax: helmfile lint

# Check releases: helmfile list

# Show rendered templates: helmfile template

# Show diff (what would change): helmfile diff

# Debug output: helmfile sync --debug

# Check specific release: helmfile -l name=my-release sync

# Verify selectors: helmfile -l environment=production sync

# Check environments: helmfile list --output yaml | grep -A5 "environment" ```

Step 2: Verify Chart Values

```bash # Check values file path: cat helmfile.yaml | grep values

# Verify values files exist: ls -la values/ ls -la environments/

# Test values rendering: helmfile template --debug

# Show merged values: helmfile write-values

# Check specific values: helmfile -l name=my-release template | grep -A20 "values:"

# Common values configuration: releases: - name: my-release namespace: default chart: ./charts/my-chart values: - values/common.yaml - values/production.yaml set: - name: image.tag value: v1.0.0

# Verify environment interpolation: cat helmfile.yaml | grep '{{'

# Check environment variables: helmfile sync --environment production ```

Step 3: Check Helm Repositories

```bash # List repositories in helmfile: cat helmfile.yaml | grep -A5 "repositories:"

# Add repositories manually: helm repo add my-repo https://charts.example.com helm repo update

# Repositories configuration: repositories: - name: stable url: https://charts.helm.sh/stable - name: my-repo url: https://charts.example.com

# Update repos via helmfile: helmfile repos

# Check repo exists: helm repo list

# Fetch chart: helm fetch my-repo/my-chart

# Use local chart: releases: - name: my-release chart: ./charts/my-chart

# Use remote chart: releases: - name: my-release chart: my-repo/my-chart ```

Step 4: Debug Template Errors

```bash # Show rendered output: helmfile template

# Render specific release: helmfile -l name=my-release template

# Save rendered output: helmfile template > rendered.yaml

# Validate rendered YAML: kubectl apply --dry-run=client -f rendered.yaml

# Check specific template: helm template my-release ./charts/my-chart -f values.yaml

# Debug with helm: helm template my-release ./charts/my-chart --debug

# Check template syntax: helm lint ./charts/my-chart

# Common template errors:

# 1. Wrong indentation # BAD: spec: containers: - name: app # GOOD: spec: containers: - name: app

# 2. Missing quote # BAD: image: {{ .Values.image }} # GOOD: image: "{{ .Values.image }}"

# 3. Undefined value # BAD: {{ .Values.missing }} # GOOD: {{ .Values.missing | default "default" }} ```

Step 5: Fix Environment Issues

```bash # Check environment configuration: cat helmfile.yaml | grep -A10 "environments:"

# Define environments: environments: development: production: staging:

# Use environment-specific values: releases: - name: my-release values: - values/{{ .Environment.Name }}.yaml

# Set environment explicitly: helmfile sync --environment production

# Default environment: export HELMFILE_ENVIRONMENT=production

# Check environment values: cat environments/production.yaml

# Missing environment file: # Error: environments/production.yaml: no such file

# Create environment file: mkdir -p environments cat > environments/production.yaml << EOF image: tag: v1.0.0 repository: gcr.io/my-project EOF

# Environment interpolation in values: values: - image: tag: {{ .Environment.Values.image.tag }} ```

Step 6: Check Dependencies

```bash # Check chart dependencies: cat charts/my-chart/Chart.yaml | grep -A10 "dependencies:"

# Update dependencies: helm dependency update ./charts/my-chart

# Build dependencies: helm dependency build ./charts/my-chart

# List dependencies: helm dependency list ./charts/my-chart

# Check charts directory: ls -la charts/my-chart/charts/

# Dependencies configuration: dependencies: - name: redis version: "17.x.x" repository: https://charts.bitnami.com/bitnami - name: postgresql version: "12.x.x" repository: https://charts.bitnami.com/bitnami

# Subchart values: values: - redis: auth: password: my-password ```

Step 7: Verify Cluster Connection

```bash # Check kubeconfig: kubectl cluster-info

# Verify current context: kubectl config current-context

# Test cluster access: kubectl get nodes

# Use specific context: helmfile sync --kube-context my-cluster

# Check namespace: kubectl get namespace production

# Create namespace if missing: kubectl create namespace production

# RBAC check: kubectl auth can-i create deployments -n production

# Check Helm history: helm list -n production

# Check Tiller (Helm 2): helm version ```

Step 8: Handle Release State

```bash # List releases: helmfile list

# Check specific release: helm list -n production | grep my-release

# View release history: helm history my-release -n production

# Rollback release: helm rollback my-release 1 -n production

# Delete release: helmfile delete

# Delete and purge: helmfile delete --purge

# Force sync: helmfile sync --force

# Wait for resources: helmfile sync --wait

# Timeout settings: helmfile sync --timeout 600

# Concurrency: helmfile sync --concurrency 3 ```

Step 9: Use Hooks for Complex Scenarios

```bash # Helmfile hooks for pre/post actions:

releases: - name: my-release chart: ./charts/my-chart hooks: - events: ["presync"] command: "kubectl" args: ["apply", "-f", "crds.yaml"] - events: ["postsync"] command: "sh" args: ["-c", "kubectl rollout status deployment/my-app"]

# Common hooks: # - presync: Before sync # - postsync: After sync # - predelete: Before delete # - postdelete: After delete # - prepare: Before any operation

# Multiple hooks: hooks: - events: ["presync"] command: "echo" args: ["Starting sync"] - events: ["postsync"] command: "kubectl" args: ["apply", "-f", "ingress.yaml"]

# Show hooks: helmfile sync --output yaml | grep -A10 hooks ```

Step 10: Helmfile Verification Script

```bash # Create verification script: cat << 'EOF' > /usr/local/bin/check-helmfile.sh #!/bin/bash

echo "=== Helmfile Configuration ===" cat helmfile.yaml

echo "" echo "=== Helm Repositories ===" helm repo list

echo "" echo "=== Helmfile Releases ===" helmfile list

echo "" echo "=== Helm Releases ===" helm list -A

echo "" echo "=== Template Validation ===" helmfile template 2>&1 | tail -20

echo "" echo "=== Lint Check ===" helmfile lint 2>&1 | tail -10

echo "" echo "=== Diff Preview ===" helmfile diff 2>&1 | head -30

echo "" echo "=== Values Files ===" ls -la values/ 2>/dev/null || echo "No values directory" ls -la environments/ 2>/dev/null || echo "No environments directory"

echo "" echo "=== Cluster Access ===" kubectl cluster-info 2>&1 | head -5

echo "" echo "=== Recommendations ===" echo "1. Ensure Helm repos are added and updated" echo "2. Check values files exist and are valid" echo "3. Verify template syntax with helmfile template" echo "4. Test cluster connectivity with kubectl" echo "5. Review chart dependencies" echo "6. Use --debug for verbose output" echo "7. Check hooks execute successfully" EOF

chmod +x /usr/local/bin/check-helmfile.sh

# Usage: /usr/local/bin/check-helmfile.sh ```

Helmfile Sync Checklist

CheckExpected
RepositoriesAdded and updated
Values filesExist and valid YAML
TemplatesRender without error
DependenciesDownloaded
Cluster accessCan connect
NamespaceExists
RBACHas permissions

Verify the Fix

```bash # After fixing Helmfile sync issues

# 1. Validate configuration helmfile lint // No errors

# 2. Preview changes helmfile diff // Shows expected changes

# 3. Run sync helmfile sync // All releases synced

# 4. Check releases helmfile list // All releases deployed

# 5. Verify resources kubectl get all -n production // Resources created

# 6. Check Helm history helm history my-release -n production // Revision 1 deployed ```

  • [Fix Helm Chart Installation Failed](/articles/fix-helm-chart-installation-failed)
  • [Fix Kubernetes Deployment Not Working](/articles/fix-kubernetes-deployment-not-working)
  • [Fix ArgoCD Application Not Syncing](/articles/fix-argocd-application-not-syncing)