Kubernetes集群使用Volumes實現宿主機與容器內部文件、目錄共享
互聯網 2022/4/21 6:23:26
本文通過編寫關于運行nginx pod的yaml文件介紹兩種文件共享的方式
[root@master1 ~]# vim nginx.yaml --- apiVersion: v1 kind: Pod metadata: name: nginx namespace: test labels: app: nginx spec: containers: - name: nginx image: nginx:1.20 imagePullPolicy: IfNotPresent ports: - containerPort: 80 volumeMounts: - name: nginx-data mountPath: /usr/share/nginx/html - name: nginx-conf mountPath: /etc/nginx/conf.d/ volumes: - name: nginx-data hostPath: path: /www type: DirectoryOrCreate - name: nginx-conf nfs: server: 192.168.110.5 path: "/conf"
- 使用hostpath的方式實現
volumeMounts: - name: nginx-data #名稱與下面對應 mountPath: /usr/share/nginx/html #容器內的路徑 volumes: - name: nginx-data hostPath: path: /www #宿主機的路徑 type: DirectoryOrCreate #當目錄不存在時自動創建
注:宿主機的路徑時該pod被調度在對應的服務器路徑
??2. 使用nfs遠程掛載
首先在服務端與客戶端都安裝nfs
[root@master1 ~]# yum install -y nfs-utils
更改服務端的配置,客戶端無須更改
[root@master1 ~]# cat /etc/exports /conf 192.168.110.0/24(rw,sync,no_root_squash)
客戶端與服務端同時啟動nfs
[root@master1 ~]# systemctl start nfs
volumeMounts: - name: nginx-conf #名稱與下面相對應 mountPath: /etc/nginx/conf.d/ 容器內的文件路徑 volumes: - name: nginx-conf nfs: server: 192.168.110.5 #服務端的ip地址 path: "/conf" #服務端宿主機的路徑
最后運行yaml文件
[root@master1 ~]# kubectl apply -y nginx.yaml

關于找一找教程網
本站文章僅代表作者觀點,不代表本站立場,所有文章非營利性免費分享。
本站提供了軟件編程、網站開發技術、服務器運維、人工智能等等IT技術文章,希望廣大程序員努力學習,讓我們用科技改變世界。
[Kubernetes集群使用Volumes實現宿主機與容器內部文件、目錄共享]http://www.yachtsalesaustralia.com/tech/detail-315885.html
- 2022-05-1938 k8s-19.Ingress入門使用
- 2022-05-18k8s系列--node(k8s節點介紹,新增節點,移除節點)
- 2022-05-15k8s源碼閱讀基礎 flag標準庫
- 2022-05-13k8s 使用ceph
- 2022-05-1338 k8s-18.service
- 2022-05-11k8s工作節點組件狀態報ContainerCreating,未獲取到ip地址
- 2022-05-05Kubernetes版本離線升級(服務器不能訪問互聯網)
- 2022-05-05二進制安裝k8s-1.20.4之搭建etcd集群
- 2022-05-0538 k8s-Deployment 20220505
- 2022-05-03ubuntu 二進制部署k8s