Kubernetes configMap-仅一个文件
我从文件中创建了一个Kubernetes configMap-仅一个文件,kubernetes,Kubernetes,我从文件中创建了一个configMap: kubectl create configmap ssportal-apache-conf --from-file=ssportal.conf=ssportal.conf 然后我需要将此文件装载到部署中: apiVersion: extensions/v1beta1 kind: Deployment metadata: name: ssportal spec: replicas: 2 template: metadata:
configMap
:
kubectl create configmap ssportal-apache-conf --from-file=ssportal.conf=ssportal.conf
然后我需要将此文件装载到部署中:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: ssportal
spec:
replicas: 2
template:
metadata:
labels:
app: ssportal
spec:
containers:
- name: ssportal
image: eu.gcr.io/my-project/ssportal:0.0.0
ports:
- containerPort: 80
volumeMounts:
- name: apache2-config-volume
mountPath: /etc/apache2/
volumes:
- name: apache2-config-volume
configMap:
name: ssportal-apache-conf
items:
- key: ssportal.conf
path: sites-enabled/ssportal.conf
但这将有效地从容器中删除现有的/etc/apache2/
目录,并将其替换为唯一的文件/etc/apache2/sites enabled/ssportal.conf
是否可以在现有配置目录上只覆盖一个文件?是。在
volumeMounts
中设置子路径:ssportal.conf
和mountPath:/etc/apache2/ssportal.conf
。您也可以删除项:…
阅读更多信息:好吧,这有点棘手。最终工作YAML规范为
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: ssportal
spec:
replicas: 2
template:
metadata:
labels:
app: ssportal
spec:
containers:
- name: ssportal
image: eu.gcr.io/my-project/ssportal:0.0.0
command: ["sleep","120d"]
ports:
- containerPort: 80
volumeMounts:
- name: test
mountPath: /etc/apache2/conf-enabled/test.conf
subPath: test.conf
volumes:
- name: test
configMap:
name: sstest
和configMap
创建步骤:
echo "# comment" > test.conf
kubectl create configmap sstest --from-file=test.conf=test.conf
这对我也有用。在configmap中包含多个文件的情况下非常有用
volumeMounts:
- name: test
mountPath: /etc/apache2/conf-enabled/test.conf
subPath: test.conf
volumes:
- name: test
configMap:
name: test
- key: test.conf
path: test.conf
另外,请注意,
kubectl create configmap sstest--from file=test.conf
足以创建configmap。如果原始容器在/etc/apache2/conf enabled/中有更多文件,这些文件不会受到影响?