Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Kubernetes configMap-仅一个文件_Kubernetes - Fatal编程技术网

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/中有更多文件,这些文件不会受到影响?