6

I'm installing fluent-bit in our k8s cluster. I have the helm chart for it on our repo, and argo is doing the deployment.

Among the resources in the helm chart is a config-map with data value as below:

apiVersion: v1
kind: ConfigMap
metadata:
  name: fluent-bit
  labels:
    app: fluent-bit
data:
...
  output-s3.conf: |
    [OUTPUT]
        Name s3
        Match *
        bucket bucket/prefix/random123/test
        region ap-southeast-2
...

My question is how can I externalize the value for the bucket so it's not hardcoded (please note that the bucket value has random numbers)? As the s3 bucket is being created by a separate app that gets ran on the same master node, the randomly generated s3 bucket name is available as environment variable, e.g. doing "echo $s3bucketName" on the node would give the actual value).

I have tried doing below on the config map but it didn't work and is just getting set as it is when inspected on pod:

bucket $(echo $s3bucketName) 

Using helm, I know it can be achieved something like below and then can populate using scripting something like helm --set to set the value from environment variable. But the deployment is happening auto through argocd so it's not like there is a place to do helm --set command or please let me know if otherwise.

bucket {{.Values.s3.bucket}}

TIA

lorraine batol
  • 6,001
  • 16
  • 55
  • 114
  • the scope is narrow, I would create a init container, which would take care of creating this `configmap` , where I can access the variable. – Saikat Chakrabortty Aug 10 '21 at 16:45
  • ArgoCD can override the parameter values with `argo app set` command. (more [here](https://argoproj.github.io/argo-cd/user-guide/helm/#helm-parameters)). –  Aug 11 '21 at 06:39
  • @p10l, thanks, would you know equivalent yaml for that? as argo syncing is automated and we don't do argo cli. also can the values to set be from an system env variable – lorraine batol Aug 11 '21 at 07:13

2 Answers2

2

Instead of using helm install you can use helm template ... --set ... > out.yaml to locally render your chart in a yaml file. This file can then be processed by Argo.

Docs

Lukas Eichler
  • 5,689
  • 1
  • 24
  • 43
  • Argo is on automated sync, I don't run cli for argo nor helm, it's all declarative yaml. Any equivalent of --set that can be sourced from system env var? – lorraine batol Aug 20 '21 at 12:58
1

With FluentBit you should be able to use environment variables such as:

  output-s3.conf: |
    [OUTPUT]
        Name s3
        Match *
        bucket ${S3_BUCKET_NAME}
        region ap-southeast-2

You can then set the environment variable on your Helm values. Depending on the chart you are using and how values are passed you may have to perform a different setup, but for example using the official FluentBit charts with a values-prod.yml like:

env:
- name: S3_BUCKET_NAME
  value: "bucket/prefix/random123/test"

Using ArgoCD, you probably have a Git repository where Helm values files are defined (like values-prod.yml) and/or an ArgoCD application defining values direct. For example, if you have an ArgoCD application defined such as:

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  # [...]
spec:
  source:
    # ...
    helm:      
      # Helm values files for overriding values in the helm chart
      valueFiles:
      # You can update this file
      - values-prod.yaml

      # Helm values
      values: |
        # Or update values here
        env:
        - name: S3_BUCKET_NAME
          value: "bucket/prefix/random123/test"
        # ...

You should be able to update either values-prod.yml on the repository used by ArgoCD or update directly values: with you environment variable

Pierre B.
  • 11,612
  • 1
  • 37
  • 58