Pod 中挂载单个文件的方法 - daniel-qa/Azure-Kubernetes-Service GitHub Wiki

https://www.qikqiak.com/post/pod-mount-single-file/

1.通过文件创建ConfigMap对象:

$ kubectl create configmap confnginx --from-file=nginx.conf

kubectl create configmap sok-env --from-file=sok-env

kubectl create configmap laravel-ini  --from-file=laravel.ini
kubectl create configmap xlaravel-pool-conf  --from-file=xlaravel.pool.conf
kubectl create configmap php-ini  --from-file=php.ini

2 .创建一个 nginx 的 Pod,通过上面的 configmap 挂载 nginx.conf 配置文件,保存为 nginx.yaml:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: ngtest
spec:
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
        - name: nginx
          image: nginx:1.7.9
          ports:
          - containerPort: 80
          volumeMounts:
            - name: nginx-config
              mountPath: /etc/nginx/nginx.conf
              subPath: nginx.conf
      volumes:
        - name: nginx-config
          configMap:
            name: confnginx
  • 修改 configmap
kubectl edit configmap special-config
kubectl edit configmap -n default php-ini -o yaml

  • 获取该ConfigMap的内容。
kubectl get configmap -o yaml nginx-config 
kubectl get -o yaml configmap/php-ini