【问题标题】:can two kubernetes volumes mount to the same place两个 Kubernetes 卷可以挂载到同一个地方吗
【发布时间】:2018-11-19 01:50:03
【问题描述】:

我对 Kubernetes 还很陌生,正在尝试弄明白。我一直无法谷歌这个答案,所以我很难过。 Kubernetes 可以将两个秘密挂载到同一路径吗?说给定以下部署:

apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx-deployment
    version: v1
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 1
  template:
    metadata:
      labels:
        app: nginx
        version: v1
    spec:
      volumes:
      - name: nginxlocal
        hostPath:
          path: /srv/docker/nginx
      - name: requestcert
        secret:
          secretName: requests-certificate
      - name: mysitecert
        secret:
          secretName: mysitecert
      containers:
      - name: nginx
        image: nginx:mainline-alpine # Use 1.15.0
        volumeMounts:
        - name: nginxlocal
          subPath: config/nginx.conf
          mountPath: /etc/nginx/nginx.conf
        - name: requestcert
          mountPath: /etc/nginx/ssl
        - name: mysitecert
          mountPath: /etc/nginx/ssl
        - name: nginxlocal
          subPath: logs
          mountPath: /etc/nginx/logs
        ports:
        - containerPort: 443

是否可以将两个 SSL 证书挂载到同一目录(/etc/nginx/ssl/*)?

如果没有,可以将 TLS 证书+密钥存储为“不透明”而不是 kubernetes.io/tls 类型吗?我试图将两个 certs+keys 组合成一个 tls 类型的 secret,但是 kubernetes 期望它被称为 tls.crt 和 tls.key,所以我不得不将它分成两个 secret 文件。如果它们可以做到不透明,我想我可以删除这两个秘密值并只使用一个不透明的条目。

谢谢!

【问题讨论】:

标签: ssl kubernetes


【解决方案1】:

是否可以将两个 SSL 证书挂载到同一目录(/etc/nginx/ssl/*)?

不,因为(至少在使用 docker 运行时)它使用卷挂载,其行为与 mount -t ext4 /dev/something /path/something 完全相同,因为 /path/something 将是最后一个获胜者。

但是,您可以使用一个只有轻微气味的解决方法:将秘密 requestcert 挂载为 /etc/nginx/.reqcert(或类似),将秘密 mysitecert 挂载为 /etc/nginx/.sitecert,然后取代 entrypoint 的图像并将文件复制到适当位置,然后再委派到实际入口点:

containers:
- name: nginx
  image: etc etc
  command:
  - bash
  - -c
  - |
    mkdir -p /etc/nginx/ssl
    cp /etc/nginx/.*cert/* /etc/nginx/ssl/
    # or whatever initialization you'd like

    # then whatever the entrypoint is for your image
    /usr/local/sbin/nginx -g "daemon off;"

或者,如果这看起来不是一个好主意,您可以利用一次性的、特定于 Pod 的目录与 initContainers: 结合使用:

spec:
  volumes:
  # all the rest of them, as you had them
  - name: temp-config
    emptyDir: {}
  initContainers:
  - name: setup-config
    image: busybox  # or whatever
    command:
    - sh
    - -c
    - |
       # "stage" all the config files, including certs
       # into /nginx-config which will evaporate on Pod destruction
    volumeMounts:
    - name: temp-config
      mountPath: /nginx-config
    # and the rest

  containers:
  - name: nginx
    # ...
    volumeMounts:
    - name: temp-config
      mountPath: /etc/nginx

它们的复杂性不同,具体取决于您是否要处理跟踪上游映像的入口点命令,而不是保持上游映像不变,但要花费更多的初始化能量

【讨论】:

    猜你喜欢
    • 2021-10-26
    • 1970-01-01
    • 2017-06-05
    • 2021-10-30
    • 2020-08-07
    • 1970-01-01
    • 2016-05-28
    • 1970-01-01
    • 2019-08-24
    相关资源
    最近更新 更多