關於k8s中subpath的使用詳解
有兩種情況:
1.做為volumes使用時,subPath代表存儲卷的子路徑:
apiVersion: v1 kind: Pod metadata: name: testpod0 spec: containers: - name: testc image: busybox command: ["/bin/sleep","10000"] volumeMounts: - name: data mountPath: /opt/data # 掛載的路徑 subPath: data # volume的子路徑 mountPath: /opt/model subPath: model volumes: - name: data persistentVolumeClaim: claimName: test-data
2.作為configmap/secret使用時,subPath代表configmap/secret的子路徑:
apiVersion: v1 kind: ConfigMap metadata: name: config-test data: config.ini: "hello" config.conf: "nihao"
單獨掛載一個key為文件
apiVersion: v1 kind: Pod metadata: name: testpod spec: containers: - name: testc image: busybox command: ["/bin/sleep","10000"] volumeMounts: - name: config-test mountPath: /etc/config.ini # 最終在容器中的文件名 subPath: config.ini #要掛載的confmap中的key的名稱 volumes: - name: config-test configMap: name: config-test
掛載多個key為文件:
apiVersion: v1 kind: Pod metadata: name: testpod2 spec: containers: - name: testc image: busybox command: ["/bin/sleep","10000"] volumeMounts: - name: config-test mountPath: /etc/config.ini # 最終在容器中的文件名 subPath: config.ini #要掛載的confmap中的key的名稱 mountPath: /etc/config.conf # 最終在容器中的文件名 subPath: config.conf #要掛載的confmap中的key的名稱 volumes: - name: config-test configMap: name: config-test
多個container掛載不同的key:
apiVersion: v1 kind: Pod metadata: name: testpod1 spec: containers: - name: testc imagePullPolicy: Never image: busybox command: ["/bin/sleep","10000"] volumeMounts: - name: config-test mountPath: /etc/config/config.ini subPath: config.ini - name: testc1 imagePullPolicy: Never image: busybox command: ["/bin/sleep","10000"] volumeMounts: - name: config-test mountPath: /etc/config/config.conf subPath: config.conf volumes: - name: config-test configMap: name: config-test items: - key: config.ini path: config.ini - key: config.conf path: config.conf
摘自
https://soulchild.cn/1911.html
到此這篇關於關於k8s中subpath的使用詳解的文章就介紹到這瞭,更多相關k8s subpath使用內容請搜索WalkonNet以前的文章或繼續瀏覽下面的相關文章希望大傢以後多多支持WalkonNet!
推薦閱讀:
- 詳解k8s ConfigMap 中 subPath 字段和 items 字段
- kubernetes環境部署單節點redis數據庫的方法
- kubernetes之statefulset搭建MySQL集群
- Kubernetes k8s configmap 容器技術解析
- Docker容器定時備份數據庫並發送到指定郵箱(設計思路)