mongodb - 如何将本地文件复制到 helm 部署中
问题描述
我正在尝试使用带有初始化脚本的 mongo 映像在 Kubernetes 中部署几个 pod。我正在使用 helm 进行部署。由于我从官方的 Mongo docker 映像开始,我试图在 /docker-entrypoint-initdb.d 中添加一个脚本,因此它将在开始时执行以初始化我的 Mongo 的一些参数。
我不知道如何使用 helm 插入我的脚本,也就是说,在我的本地机器中,在 /docker-entrypoint-initdb.d 中。
我正在尝试做类似 docker run -v hostfile:mongofile 但我需要 helm 中的等效项,因此这将在部署的所有 pod 中完成
解决方案
您可以使用配置映射。让我们通过 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
您还可以从此链接检查 initContainers 概念: https ://kubernetes.io/docs/concepts/workloads/pods/init-containers/
推荐阅读
- c# - C# ASP.NET Core 2.1/Entity Framework:实体集合不保存
- php - PHP Laravel,如何检查字符串日期和时间是否不在过去
- javascript - 从浏览器控制台向 Instagram 图片添加评论(在本机 JavaScript 中)
- html - 环绕手机的引导导航栏
- node.js - eureka-js-client 为什么我不能为两个服务实例使用相同的主机名?
- html - 如何将背景图像堆叠在一起?
- python - 如何在 Python 中检查文本的第一个字符?
- python - Python(或R)中连续分布的总变异距离
- conan - 如何链接到柯南中的特定 packageid
- android - 没有适配器连接到 viewpager2