user3753342
user3753342

Reputation: 439

helm: how to mount configMap if not supported by values.yaml?

I am deploying authelia with their helm chart https://artifacthub.io/packages/helm/truecharts/authelia.

I need to mount a ConfigMap to a specific file in the authelia container, however this is not available as a templated value in the values.yaml.

I'm struggling to understand what is the recommended way of doing something like this... this could generalise to "how can I customise an helm deployment beyond what is allowed through the values.yaml?"

I can only think of getting all the yaml from the chart, make the change I need and deploy like that... It can't be the best way of doing this

solution

users_database.yml
###############################################################
#                         Users Database                      #
###############################################################

# This file can be used if you do not have an LDAP set up.

# List of users
users:
  admin:
    displayname: "admin"
    password: "redacted"
    email: admin@redacted
    groups:
      - admins
      - dev
patches/authelia_users_database.yaml
spec:
  template:
    spec:
      containers:
      - name: authelia
        volumeMounts:
        - name: authelia-users-database
          mountPath: /etc/config
      volumes:
      - name: authelia-users-database
        configMap:
          name: authelia-users-database
values.yaml
authentication_backend:
  file:
    enabled: true
      path: /etc/config/users_database.yml
$ helm repo add authelia https://charts.authelia.com
$ helm repo update
$ helm upgrade --install authelia authelia/authelia --values values/authelia.yaml --version 0.8.34
$ kubectl create configmap authelia-users-database --from-file=users_database.yml --dry-run -o yaml | kubectl apply -f -
$ kubectl patch daemonset authelia --patch-file patches/authelia_users_database.yaml

Upvotes: 2

Views: 1417

Answers (2)

Affes Salem
Affes Salem

Reputation: 1651

Think of the helm package as it's a java package, you can't instantiate an object that has not been defined yet in that package and you are trying to do the same thing in helm.

If you are not familiar with helm, helm is a tool that helps you create abstraction on a specific k8s resources manifests and they are configured depending on you definition in values.yaml, each helm chart has its own deinition of templates, so If something you want to configure but isn't available yet in that chart you could either download the chart by running:

helm pull truecharts/authelia
# or 
helm fetch truecharts/authelia

extract the package then add your custom templates which as you said you are trying to refer to a configfile in your deployement so add a reference of that config in the deployment.yaml in the templates directory then if your definition and syntax are right you can add your specifications in the values.yaml.

Not sure how you want to bind your config but would that respong to your use case?

          envFrom:
          - configMapRef:
              name: {{ .Values.configmap }}

values.yaml

...
configmap: myconfigmap

make sure the configmap name specified exist so things work

make sure to read helm docs on how to create your own templates

Upvotes: 1

Lucas Scheepers
Lucas Scheepers

Reputation: 601

I would say you could try to use kubectl patch to mount the ConfigMap to the authelia container afterwards. Look here for more information.

So create a .yml file with Deployment, Replicaset or Statefulset and add the ConfigMap configuration (just check which Kubernetes object suits best for you according to the Helm deployment). After deploying the application using the Helm chart; run the command kubectl patch -f your-deployment-file.yml.

Upvotes: 2

Related Questions