Giriş
Host bilgisayarın diskindeki bir dizini pod kullanabilir. Açıklaması şöyle. Yani sadece single node cluster için işe yarar. Örneğin minikube sadece hostPath destekler
A hostPath volume mounts a file or directory from the host node's filesystem into your Pod. So, if you have a multi-node cluster, the pod is restarted for some reasons and assigned to another node, the new node won't have the old data on the same path. That's why we have seen, that hostPath volumes work well only on single-node clusters.
Kullanım
1. volumes ile host bilgisayar üzerindeki dizin belirtilir.
2. Pod bu bu volume'u volumeMounts kullanırÖrnek
Şekle şöyle
Örnek
Şöyle yaparız
apiVersion: v1 kind: Pod metadata: name: myapp spec: containers: - name: myapp-container image: myapp-image volumeMounts: - name: data-volume mountPath: /data volumes: - name: data-volume hostPath: path: /mnt/data
Örnek - DirectoryOrCreate
Şeklen şöyle
Açıklaması şöyle
Mount a directory /var/local/data as a volume from the host machine to /usr/share/nginx/html location of the nginx container of a pod.Any data written by the nginx-container at /usr/share/nginx/html location will be persisted at /var/local/data location of the host machine. If the pod terminates, data will remain safe at /var/local/data location.
Şöyle yaparız
#pod definition file with a volume apiVersion: v1 kind: Pod metadata: name: webserver spec: containers: - image: nginx:latest name: nginx-container volumeMounts: - mountPath: /usr/share/nginx/html name: test-vol volumes: - name: test-vol hostPath: path: /var/local/data type: DirectoryOrCreate
Örnek
Şöyle yaparız
apiVersion: v1 kind: Pod metadata: name: test-pd spec: containers: - image: k8s.gcr.io/test-webserver name: test-container volumeMounts: - mountPath: /test-pd name: test-volume volumes: - name: test-volume hostPath: # directory location on host path: /data # this field is optional type: Directory
Hiç yorum yok:
Yorum Gönder