简体   繁体   English

helm:如果 values.yaml 不支持,如何挂载 configMap?

[英]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 .我正在使用他们的掌舵图https://artifacthub.io/packages/helm/truecharts/authelia部署 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 .我需要将 ConfigMap 挂载到 authelia 容器中的特定文件,但是这不能作为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 ?"我正在努力理解做这样的事情的推荐方法是什么......这可以概括为“我如何定制一个超出values.yaml允许范围的 helm 部署?”

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我只能想到从图表中获取所有 yaml,进行我需要的更改并像那样部署......这不是最好的方法

solution解决方案

users_database.yml 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补丁/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值.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

I would say you could try to use kubectl patch to mount the ConfigMap to the authelia container afterwards.我想说你可以尝试使用kubectl patch之后将 ConfigMap 挂载到 authelia 容器。 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).因此,使用 Deployment、Replicaset 或 Statefulset 创建一个.yml文件并添加 ConfigMap 配置(只需根据 Helm 部署检查哪个 Kubernetes 对象最适合您)。 After deploying the application using the Helm chart;使用 Helm 图表部署应用程序后; run the command kubectl patch -f your-deployment-file.yml .运行命令kubectl patch -f your-deployment-file.yml

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.将 helm 包想象为一个 java 包,您无法实例化尚未在该包中定义的对象,并且您正在尝试在 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 ,helm 是一个工具,可以帮助你在特定的 k8s 资源清单上创建抽象,它们根据你在values.yaml中的定义进行配置,每个 helm 图表都有自己的模板定义,所以如果你有什么想要配置但在该图表中尚不可用,您可以通过运行下载图表:

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 .提取包然后添加您的自定义模板,正如您所说,您试图在部署中引用配置文件,因此在模板目录中的deployment.yaml中添加该配置的引用,然后如果您的定义和语法正确,您可以添加您在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值.yaml

...
configmap: myconfigmap

make sure the configmap name specified exist so things work确保指定的 configmap 名称存在,以便一切正常

make sure to read helm docs on how to create your own templates确保阅读 helm 文档,了解如何创建自己的模板

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM