【问题标题】:How do I mount a single file from a secret in Kubernetes?如何从 Kubernetes 中的 Secret 挂载单个文件?
【发布时间】:2018-11-14 08:42:47
【问题描述】:

如何从密钥中挂载“单个”文件?

我创建了一个秘密:

kubectl create secret generic oauth \
        --from-file=./.work-in-progress/oauth_private.key \
        --from-file=./.work-in-progress/oauth_public.key \

如何将oauth_private.key 文件挂载为单个文件,而不是使用仅包含这两个文件的目录覆盖整个路径(并可能删除最初存在于容器中的文件)?

【问题讨论】:

标签: kubernetes kubernetes-secrets


【解决方案1】:

你可以这样做:

apiVersion: v1
kind: Pod
metadata:
  name: mypod
spec:
  containers:
  - name: mypod
    image: redis
    volumeMounts:
    - name: foo
      mountPath: "/etc/foo"
      readOnly: true
  volumes:
  - name: foo
    secret:
      secretName: mysecret
      items:
      - key: username
        path: my-group/my-username

假设mysecret 包含usernamepassword。上面的 yaml 只会在 /etc/foo/my-group/my-username 目录中挂载 username

更多详情请查看:Using Secrets as Files from a Pod

【讨论】:

  • 我假设这会将 /etc/foo 挂载为一个新的空卷 - 它会覆盖容器中的现有文件?所以不幸的是,它产生了意想不到的效果。
  • subPath 在这种情况下可能会有所帮助。检查此问题的答案:stackoverflow.com/questions/33415913/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-01-22
  • 1970-01-01
  • 2019-01-15
  • 2019-07-29
  • 2021-08-04
  • 2017-11-11
  • 1970-01-01
相关资源
最近更新 更多