[英]How to specify a directory in ConfigMap that is located with in a docker container running on Kubernetes?
[英]How to mount entire directory in Kubernetes using configmap?
我希望能够在 /etc/configs 中挂载未知数量的配置文件
我已经使用以下方法将一些文件添加到 configmap 中:
kubectl 创建 configmap etc-configs --from-file=/tmp/etc-config
永远不会知道文件和文件名的数量,我想重新创建配置映射,并且应该在同步间隔后更新 Kubernetes 容器中的文件夹。
我试图安装它,但我无法这样做,该文件夹始终为空,但我在 configmap 中有数据。
bofh$ kubectl describe configmap etc-configs
Name: etc-configs
Namespace: default
Labels: <none>
Annotations: <none>
Data
====
file1.conf:
----
{
... trunkated ...
}
file2.conf:
----
{
... trunkated ...
}
file3.conf:
----
{
... trunkated ...
}
Events: <none>
我在容器 volumeMounts 中使用了这个:
- name: etc-configs
mountPath: /etc/configs
这是卷:
- name: etc-configs
configMap:
name: etc-configs
我可以挂载单个项目,但不能挂载整个目录。
有关如何解决此问题的任何建议?
我现在感觉真的很傻。
对不起,我的错。
Docker 容器没有启动,所以我使用 docker run -it --entrypoint='/bin/bash' 手动启动它,但我看不到 configMap 中的任何文件。
这不起作用,因为在 Kubernetes 启动之前 docker 对我的部署一无所知。
docker 镜像失败,Kubernetes 配置一直正确。
我调试错了。
您可以将 ConfigMap 作为特殊卷安装到您的容器中。
在这种情况下,挂载文件夹会将每个键显示为挂载文件夹中的一个文件,并且这些文件将地图值作为内容。
apiVersion: v1
kind: Pod
metadata:
name: dapi-test-pod
spec:
containers:
- name: test-container
image: k8s.gcr.io/busybox
...
volumeMounts:
- name: config-volume
mountPath: /etc/config
volumes:
- name: config-volume
configMap:
# Provide the name of the ConfigMap containing the files you want
# to add to the container
name: special-config
使用您的配置,您将挂载 configmap 中列出的每个文件。
如果需要挂载文件夹中的所有文件,则不应使用 configmap,而应使用 persistenceVolume 和 persistenceVolumeClaims:
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-volume-jenkins
spec:
capacity:
storage: 50Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/data/pv-jenkins"
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pv-claim-jenkins
spec:
accessModes:
- ReadWriteOnce
storageClassName: ""
resources:
requests:
storage: 50Gi
在您的 deployment.yml 中:
volumeMounts:
- name: jenkins-persistent-storage
mountPath: /data
volumes:
- name: jenkins-persistent-storage
persistentVolumeClaim:
claimName: pv-claim-jenkins
您还可以使用以下内容:
kubectl create configmap my-config --from-file=/etc/configs
使用该文件夹中的所有文件创建配置映射。
希望这会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.