jac*_*ack 6 deployment kubernetes
我有两个不同的配置映射test-configmap和common-config.我试图将它们安装在同一个位置,但是一个配置图覆盖了另一个.然后我读到subPath并且没有工作.
deploy.yaml
apiVersion: apps/v1beta1 # for versions before 1.8.0 use apps/v1beta1
kind: Deployment
metadata:
name: testing
spec:
replicas: 1
template:
metadata:
name: testing
labels:
app: testing
spec:
containers:
- name: testing-container
image: testing
imagePullPolicy: IfNotPresent
ports:
- containerPort: __PORT__
volumeMounts:
- name: commonconfig-volume
mountPath: /usr/src/app/config/test.config
subPath: test.config
volumes:
- name: commonconfig-volume
configMap:
name: test-configmap
- name: commonconfig-volume
configMap:
name: common-config
Run Code Online (Sandbox Code Playgroud)
错误:
The Deployment "testing" is invalid: spec.template.spec.volumes[1].name: Duplicate value: "commonconfig-volume"
我不确定合并两个配置图是否可以实现.如果是,那么我该怎么办呢.
您无法将两个ConfigMaps安装到同一位置.
但提subPath并key在每个configmaps每一个项目都会让你在相同的位置从两个configmaps项目.您必须手动为每个文件写入挂载点:
apiVersion: v1
kind: Pod
metadata:
name: config-single-file-volume-pod
spec:
containers:
- name: test-container
image: gcr.io/google_containers/busybox
command: [ "/bin/sh", "-c", "cat /etc/special-key" ]
volumeMounts:
- name: config-volume-1
mountPath: /etc/special-key1
subPath: path/to/special-key1
- name: config-volume-2
mountPath: /etc/special-key2
subPath: path/to/special-key2
volumes:
- name: config-volume-1
configMap:
name: test-configmap1
items:
- key: data-1
path: path/to/special-key1
- name: config-volume-2
configMap:
name: test-configmap2
items:
- key: data-2
path: path/to/special-key2
restartPolicy: Never
Run Code Online (Sandbox Code Playgroud)
另一种方法是将它们安装在相同的目录下,但是不同的子路径,这样您就不必手动指定项目.但是,这里每个configmap的密钥将被放入两个不同的目录:
apiVersion: v1
kind: Pod
metadata:
name: config-single-file-volume-pod
spec:
containers:
- name: test-container
image: gcr.io/google_containers/busybox
command: [ "/bin/sh", "-c", "cat /etc/special-key" ]
volumeMounts:
- name: config-volume-1
mountPath: /etc/special-keys
subPath: cm1
- name: config-volume-2
mountPath: /etc/special-keys
subPath: cm2
volumes:
- name: config-volume-1
configMap:
name: test-configmap1
- name: config-volume-2
configMap:
name: test-configmap2
restartPolicy: Never
Run Code Online (Sandbox Code Playgroud)
cm1并且cm2将是两个目录,包含分别从test-configmap1和中导入的文件test-configmap2.
您必须使用特殊的预计体积才能实现这一目标。部署示例:
apiVersion: apps/v1
kind: Deployment
metadata:
name: testing
spec:
replicas: 1
selector:
matchLabels:
app: testing
template:
metadata:
name: testing
labels:
app: testing
spec:
containers:
- name: testing-container
image: testing
imagePullPolicy: IfNotPresent
ports:
- containerPort: __PORT__
volumeMounts:
- name: commonconfig-volume
mountPath: /usr/src/app/config
volumes:
- name: commonconfig-volume
projected:
sources:
- configMap:
name: test-configmap
- configMap:
name: common-config
Run Code Online (Sandbox Code Playgroud)
您可以使用secret与configMap
另一个示例说明如何安装多个配置映射。对于 nginx 码头,如果您想要替换主 /etc/nginx/nginx.conf 和 /etc/nginx/conn.f 中的文件。这也会删除conf.d中的default.conf文件
containers:
- name: nginx-proxy
image: nginx:1.16-alpine
imagePullPolicy: Always
ports:
- containerPort: 443
- containerPort: 80
volumeMounts:
- name: nginx-main-conf-file
mountPath: /etc/nginx/nginx.conf
subPath: nginx.conf
- name: nginx-site-conf-file
mountPath: /etc/nginx/conf.d
volumes:
- name: nginx-main-conf-file
configMap:
name: nginx-main-conf
- name: nginx-site-conf-file
configMap:
name: nginx-site-conf
Run Code Online (Sandbox Code Playgroud)
还有一点非常重要。如果您的 yaml 文件中有任何注释行(# 某事),那么这将不起作用。这是一个错误。在 kubectl v1.14 中测试
| 归档时间: |
|
| 查看次数: |
6538 次 |
| 最近记录: |