flux - how to deploy app that leverages a helm chart repository (standard service)

Let's say you would like to deploy your app and it needs to use a helm chart with fluxcd, you can do that by creating a gitrepository and a helm release. Git repository is for your helm chart (you only required to do it once) and then create multiple helm releases - as more than one application would be using this standard chart.

This is what my chart repo looks like - if you have sub-directory, please specify that in your helm release setup. 



And these are my yamls 

apiVersion: source.toolkit.fluxcd.io/v1
kind: GitRepository
metadata:
  name: standardservice
  namespace: flux-system
spec:
  interval: 1m
  url: https://github.com/kepungnzai/helloworld-chart
  ref:
    branch: main

And the actual app deployment using helm release 

apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
  name: my-configmap
  namespace: test
spec:
  interval: 1m
  releaseName: my-configmap
  chart:
    spec:
      chart: ./ # path to chart directory in your app github repository
      sourceRef:
        kind: GitRepository
        name: standardservice
        namespace: flux-system
      interval: 1m
  values:
    config:
      APP_ENV: test
      LOG_LEVEL: debug
      FEATURE_FLAG: "false"


And if everything runs well, you will get a config map.



And your config map is available here:- 




The approach here is inline which is not practical at all. So we would typically use values files from a different repository. So i have create my values file here in a new repo. https://github.com/kepungnzai/flux-app-helloworld here and it has the following directory structure 


production-values.yaml contains 

config:

  APP_ENV: productionA

  LOG_LEVEL: info

  FEATURE_FLAG: "true"

And kustomiation.yaml looks like this 

  # Inside your-values-repo/prod-env/kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
configMapGenerator:
  - name: my-app-values
    files:
      - values.yaml=production-values.yaml # Maps your file to a key
    options:
      disableNameSuffixHash: true

We need to create a new git repository and kustomization resource 

A git repository

apiVersion: source.toolkit.fluxcd.io/v1
kind: GitRepository
metadata:
  name: app-values-repo
  namespace: flux-system
spec:
  interval: 1m
  url: https://github.com/kepungnzai/flux-app-helloworld
  ref:
    branch: main

And kustomization resource

apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
metadata:
  name: app-values-sync
  namespace: flux-system
spec:
  interval: 1m
  path: ./prod-env # Path inside your values repo
  sourceRef:
    kind: GitRepository
    name: app-values-repo
  prune: true
  targetNamespace: test # Where the ConfigMap will be created

And now we would need to update our helm release 

# apiVersion: helm.toolkit.fluxcd.io/v2
# kind: HelmRelease
# metadata:
#   name: my-configmap
#   namespace: test
# spec:
#   interval: 1m
#   releaseName: my-configmap
#   chart:
#     spec:
#       chart: ./
#       sourceRef:
#         kind: GitRepository
#         name: standardservice
#         namespace: flux-system
#       interval: 1m
#   values:
#     config:
#       APP_ENV: test
#       LOG_LEVEL: debug
#       FEATURE_FLAG: "false"

apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
  name: my-configmap
  namespace: test
spec:
  interval: 1m
  releaseName: my-configmap
  chart:
    spec:
      chart: ./
      sourceRef:
        kind: GitRepository
        name: standardservice # Your Chart Repo
        namespace: flux-system
 
  # This is the "Practical" part: No more inline values!
  valuesFrom:
    - kind: ConfigMap
      name: my-app-values # Must match the name in the Kustomization above
      valuesKey: values.yaml # Must match the key in configMapGenerator

Troubleshooting issues

HelmChart 'flux-system/test-my-configmap' is not ready: invalid chart reference: stat /tmp/helmchart-flux-system-test-my-configmap-1294696522/source/charts/my-configmap: no such file or directory

This means your gitrepository for your chart path might not be setup correctly. 


Comments

Popular posts from this blog

vllm : Failed to infer device type

android studio kotlin source is null error

gemini cli getting file not defined error