DEV Community

loading...
Cover image for Helmfile : Deploy multiple charts in your cluster k8S

Helmfile : Deploy multiple charts in your cluster k8S

javidjms profile image Javid Mougamadou ・3 min read

Prerequisites

  • Cluster K8S

  • Helmfile

  • Docker (helmfile image container, optional)

Concepts

Alt Text

Helmfile allows to declare specification for deploying multiple Helm charts. All information is saved in the helmfile.yaml file.

Here is the advantages of using Helmfile :

  • Keep a directory of chart value files and maintain changes in version control.

  • Apply CI/CD to configuration changes.

  • Environmental chart promotion.

  • Periodically sync to avoid skew in environments.

Installation

docker run --rm --net=host -v "${HOME}/.kube:/root/.kube" -v "${HOME}/.config/helm:/root/.config/helm" -v "${PWD}:/data" --workdir /data quay.io/roboll/helmfile:helm3-v0.135.0 helmfile 
Enter fullscreen mode Exit fullscreen mode
  • Use a docker container (cablespaghetti/helmfile-docker) :
docker run --rm --net=host -v "${HOME}/.kube:/root/.kube" -v "${HOME}/.config/helm:/root/.config/helm" -v "${PWD}:/data" --workdir /data cablespaghetti/helmfile-docker helmfile 
Enter fullscreen mode Exit fullscreen mode

Getting Started

Suppose the helmfile.yaml representing the desired state of your helm releases looks like:

releases:
- name: prom-norbac-ubuntu
  namespace: prometheus
  chart: stable/prometheus
  set:
  - name: rbac.create
    value: false
Enter fullscreen mode Exit fullscreen mode

Sync your Kubernetes cluster state to the desired one by running:

# Sync all your chart releases
helmfile sync

# OR
# Apply all your chart releases
helmfile apply

# OR
# Sync all your chart releases (offline)
helmfile charts
Enter fullscreen mode Exit fullscreen mode

Advanced Usage

Multiple values (for multiple environments)

Dev Environment

# helmfile-dev.yaml
repositories:
  - name: bitnami
    url: https://charts.bitnami.com/bitnami

releases:
  - name: my-postgres
    namespace: my-namespace-dev
    chart: bitnami/postgres
    values:
      - ./values/postgres-dev-1.yaml
      - ./values/postgres-dev-2.yaml
Enter fullscreen mode Exit fullscreen mode
# Sync all your chart releases
helmfile -f helmfile-dev.yaml sync
Enter fullscreen mode Exit fullscreen mode

Prod Environment

# helmfile-prod.yaml
repositories:
  - name: bitnami
    url: https://charts.bitnami.com/bitnami

releases:
  - name: my-postgres
    namespace: my-namespace-production
    chart: bitnami/postgres
    values:
      - ./values/postgres-prod-1.yaml
      - ./values/postgres-prod-2.yaml
Enter fullscreen mode Exit fullscreen mode
# Sync all your chart releases
helmfile -f helmfile-prod.yaml sync
Enter fullscreen mode Exit fullscreen mode

Environment Variables

# helmfile-prod.yaml
repositories:
  - name: bitnami
    url: https://charts.bitnami.com/bitnami

releases:
  - name: {{ requiredEnv "NAME" }}-postgres
    namespace: {{ requiredEnv "NAME" }}
    chart: bitnami/postgres
    set:
    - name: image
      value: {{ requiredEnv "DOCKER_IMAGE" }}
    - name: version
      value: {{ requiredEnv "VERSION" }}
    values:
      - ./values/postgres-prod.yaml
Enter fullscreen mode Exit fullscreen mode
# Sync all your chart releases
NAME=my-project VERSION=1 DOCKER_IMAGE=postgres:latest helmfile -f helmfile-prod.yaml sync
Enter fullscreen mode Exit fullscreen mode

Templates

# helmfile.yaml
releases:
  - name: {{ requiredEnv "NAME" }}-vault
    namespace: {{ requiredEnv "NAME" }}
    chart: roboll/vault-secret-manager
    values:
    - values.yaml.gotmpl
Enter fullscreen mode Exit fullscreen mode
# values.yaml.gotmpl
db:
  username: {{ requiredEnv "DB_USERNAME" }}
  password: {{ requiredEnv "DB_PASSWORD" }}
proxy:
  domain: {{ requiredEnv "PLATFORM_ID" }}.my-domain.com
  scheme: {{ env "SCHEME" | default "https" }}
Enter fullscreen mode Exit fullscreen mode

Environement Files

# helmfile.yaml
environments:
  production:
    values:
    - production.yaml

releases:
- name: myapp
  values:
  - values.yaml.gotmpl
Enter fullscreen mode Exit fullscreen mode
# production.yaml
domain: prod.example.com
releaseName: prod
Enter fullscreen mode Exit fullscreen mode
# values.yaml.gotmpl
domain: {{ .Values | get "domain" "dev.example.com" }}
Enter fullscreen mode Exit fullscreen mode

Secrets

# helmfile.yaml
environments:
  production:
    secrets:
    - environments/production/secrets.yaml

releases:
- name: myapp
  chart: mychart
  values:
  - values.yaml.gotmpl
Enter fullscreen mode Exit fullscreen mode
# environments/production/secrets.yaml
foo.bar: "mysupersecretstring"
Enter fullscreen mode Exit fullscreen mode

The value can be used in your values.yaml.gotmpl like :

{{ .Values.foo.bar }}
Enter fullscreen mode Exit fullscreen mode

Examples

repositories:
  - name: bitnami
    url: https://charts.bitnami.com/bitnami

releases:
  - name: my-nginx
    namespace: my-namespace-production
    chart: bitnami/nginx
    values:
      - ./values/nginx-production.yaml
  - name: my-postgres
    namespace: my-namespace-production
    chart: bitnami/postgres
    values:
      - ./values/postgres-production.yaml
Enter fullscreen mode Exit fullscreen mode

Links

https://github.com/roboll/helmfile

https://github.com/roboll/helmfile/tree/master/examples

https://lyz-code.github.io/blue-book/devops/helmfile/#:~:text=Helmfile%20is%20a%20declarative%20spec,Environmental%20chart%20promotion.

https://github.com/wkrzywiec/k8s-helm-helmfile

https://hub.docker.com/r/cablespaghetti/helmfile-docker

https://alexsimonjones.medium.com/helmfile-post-v3-helm-519c82a29c6a

Discussion (0)

pic
Editor guide