2017-06-02 53 views
2

我從文件中創建一個configMapKubernetes 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

是否有可能覆蓋現有的配置目錄只有一個文件?

回答

2

好吧,這是一個有點棘手。最後的工作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 
0

這也爲我工作。在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 
相關問題