elasticsearch - 如何在 Kubernetes 部署文件中覆盖 pods 容器中的文件?
问题描述
我想覆盖 pod 容器上的文件。现在我elasticsearch.yml
在 location /usr/share/elasticsearch/config
。
我试图initContainer
在 kubernetes 部署文件中实现这一点,所以我添加了类似的内容:
- name: disabled-the-xpack-security
image: busybox
command:
- /bin/sh
- -c
- |
sleep 20
rm /usr/share/elasticsearch/config/elasticsearch.yml
cp /home/x/IdeaProjects/BD/infra/istio/kube/elasticsearch.yml /usr/share/elasticsearch/config/
securityContext:
privileged: true
但这不起作用,错误看起来像:
rm: can't remove '/usr/share/elasticsearch/config/elasticsearch.yml': No such file or directory
cp: can't stat '/home/x/IdeaProjects/BD/infra/istio/kube/elasticsearch.yml': No such file or directory
我试图使用 some echo "some yaml config" >> elasticsearch.yml
,但这种解决方法不起作用,因为我能够保持正确的 yaml 格式。
你有什么建议,我该怎么做?
解决方案
正如 Arman 在评论中所述,您可以创建一个包含 ConfigMap 的内容,/home/x/IdeaProjects/BD/infra/istio/kube/elasticsearch.yml
并将其作为卷安装在部署中。
要从您的文件创建配置映射,您可以运行:
kubectl create configmap my-es-config --from-file=/home/x/IdeaProjects/BD/infra/istio/kube/elasticsearch.yml
这将使用 yaml 文件在您的 kubernetes 集群中创建一个 ConfigMap。
然后,您可以使用它并将卷安装添加到您的部署中:
containers:
- name: elasticsearch
image: k8s.gcr.io/busybox
.
.
.
volumeMounts:
- name: config-volume
mountPath: /usr/share/elasticsearch/config/
volumes:
- name: config-volume
configMap:
name: my-es-config
笔记
- 建议也将 ConfigMap 创建为 yaml。更多信息在这里
- 直接在 上安装 configmap
/usr/share/elasticsearch/config/
,将替换该路径内的所有内容并放置 configmap 中的配置文件。如果这导致问题,您可能希望将其安装在另一个位置,然后复制它。
推荐阅读
- java - Tomcat 构建错误:java.lang.NoClassDefFoundError
- javascript - DOMException:无法在“选择”上执行“getRangeAt”:0 不是有效索引。- 下拉 - 反应
- java - 如何将对象作为 JSON Web 令牌的一部分发送?
- r - 是否可以使用 Here API 使用公共交通工具或骑自行车来创建等值线?
- kerberos - Solace Spring Cloud 流绑定
- python - 我如何按一天中的时间分组以找出最高顺序?
- validation - 谷歌表格数据验证每行不同
- python - 在 ReadTheDocs 上记录 Python C 扩展
- ruby-on-rails - 在 Rails API 中将分页计数添加到相同的 GET 响应
- r - 这两行代码的错误是什么?获取模式:“http://blabla.nc”