kubernetes config map data value externalisation

8/10/2021

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
configmap
kubernetes
kubernetes-helm

2 Answers

8/19/2021

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
Source: StackOverflow

8/24/2021

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.
Source: StackOverflow