Kubernetes configMap-仅一个文件 [英] Kubernetes configMap - only one file

查看:80
本文介绍了Kubernetes configMap-仅一个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从文件创建的configMap:

I have a configMap created from file:

kubectl create configmap ssportal-apache-conf --from-file=ssportal.conf=ssportal.conf

然后我需要将此文件挂载到部署中:

and then I need to mount this file into the deployment:

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替换了该目录.

But this effectively removes the existing /etc/apache2/ directory from the container and replaces it with one an only file /etc/apache2/sites-enabled/ssportal.conf.

是否可以在现有配置目录上仅覆盖一个文件?

Is it possible to overlay only one file over the existing config directory?

推荐答案

好的,这有点棘手.最终有效的YAML规范是

Okay, it's a bit tricky. The final working YAML spec is

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 

这篇关于Kubernetes configMap-仅一个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆