如何将本地文件复制到 helm 部署中

Car*_*bes 7 mongodb docker kubernetes kubernetes-helm

我正在尝试使用 mongo 映像在 Kubernetes 中部署多个 pod,其中包含初始化脚本。我正在使用 helm 进行部署。由于我从官方 Mongo docker 映像开始,因此我尝试在 /docker-entrypoint-initdb.d 添加一个脚本,以便它将在开始时执行以初始化 Mongo 的一些参数。

我不知道的是如何使用 helm 插入我的脚本,也就是说,在我的本地计算机中的 /docker-entrypoint-initdb.d 中。

我正在尝试执行类似 docker run -v hostfile:mongofile 之类的操作,但我需要 helm 中的等效操作,因此这将在部署的所有 Pod 中完成

Luf*_*ffy 11

您可以使用配置映射。让我们通过 configmap 将 nginx 配置文件放入容器中。我们有名为 nginx 的目录名称,具有相同级别的values.yml。里面有我们实际的配置文件。

apiVersion: v1
kind: ConfigMap
metadata:
  name: nginx-config-file
  labels:
    app: ...    
data:
  nginx.conf: |-
{{ .Files.Get "nginx/nginx.conf" | indent 4 }}

---

apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: SomeDeployment
  ...  
spec:
  replicas: 
  selector:
    matchLabels:
      app: ...
      release: ...
  template:
    metadata:
      labels:
        app: ...
        release: ...
    spec:
      volumes:
        - name: nginx-conf
          configMap:
            name: nginx-config-file
            items:
            - key: nginx.conf
              path: nginx.conf
      containers:        
        - name: ...
          image: ...          
          volumeMounts:
            - name: nginx-conf
              mountPath: /etc/nginx/nginx.conf
              subPath: nginx.conf
Run Code Online (Sandbox Code Playgroud)

您还可以从此链接检查 initContainers 概念: https://kubernetes.io/docs/concepts/workloads/pods/init-containers/