You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为Kubernetes Secret单个Key设置多个值?(MongoDB Helm场景)

问题

我正尝试为通过Bitnami MongoDB Helm Chart部署的MongoDB创建Kubernetes Secret,配置如下:

apiVersion: v1
kind: Secret
metadata:
  name: mongodb-secret
  namespace: mongodb
  labels:
    app.kubernetes.io/component: mongodb
type: Opaque
data: 
  mongodb-root-password: 'encoded value'
  mongodb-passwords: '???'
  mongodb-metrics-password: 'encoded value'
  mongodb-replica-set-key: 'encoded value'

该Helm Chart的values.yaml中说明:

auth:
  ## MongoDB(®) custom users and databases
  ## @param auth.usernames List of custom users to be created during the initialization
  ## @param auth.passwords List of passwords for the custom users set at `auth.usernames`
  ## @param auth.databases List of custom databases to be created during the initialization
  ##
  usernames: []
  passwords: []
  databases: []
  ## @param auth.existingSecret Existing secret with MongoDB(®) credentials (keys: `mongodb-passwords`, `mongodb-root-password`, `mongodb-metrics-password`, ` mongodb-replica-set-key`)
  ## NOTE: When it's set the previous parameters are ignored.
  ##
  existingSecret: ""

其中passwords是对应每个username和database的字符串数组。请问我该如何在Secret中配置这些多个密码?是否只需将所有密码用逗号分隔后编码即可?

解答

  • 不能用逗号分隔,Bitnami MongoDB Helm Chart要求mongodb-passwords字段的值是换行分隔的密码字符串,再经过Base64编码后的结果。
  • 具体操作步骤:
    1. 按顺序准备自定义用户的密码,每个密码单独占一行。比如有2个用户,密码分别为user1-pass和user2-pass,原始内容为:
      user1-pass
      user2-pass
      
    2. 对这段多行字符串执行Base64编码,可通过命令完成:
      echo -e "user1-pass\nuser2-pass" | base64
      
    3. 将编码后的结果填入Secret的mongodb-passwords字段即可。
  • 注意:密码的顺序必须和values.yaml中usernames、databases的顺序严格对应,确保每个密码匹配对应的用户和数据库。

内容的提问来源于stack exchange,提问作者user3142695

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.12 04:55:18