Hostpath
- KubernetesNode上のボリュームをコンテナにマッピングするプラグイン
 Directoryはディレクトリが存在しない場合に作成しないDirectoryOrCreateはディレクトリが存在しない場合には作成して起動する- 利用できないようにしているKubernetesも多いみたい
 - あまり推奨の構成ではないようで、検証環境とかは手っ取り早くHostpathというのはありなのかもしれない
 
Sampleをデプロイ
sample-hostpath.yaml
apiVersion: v1
kind: Pod
metadata:
  name: sample-hostpath
spec:
  containers:
  - image: nginx:1.12
    name: nginx-container
    volumeMounts:
    - mountPath: /srv
      name: hostpath-sample
  volumes:
  - name: hostpath-sample
    hostPath:
      path: /etc
      type: DirectoryOrCreate
kubectl apply -f sample-hostpath.yaml
Podからマウントされているか確認
kubectl exec -it sample-hostpath cat /srv/hostname
出力結果
k3d-k3s-default-worker-1
dfコマンドで見ると
df | grep /srv
overlayとでる。出ていればマウントされいているに違いない。
overlay         61255492 13356212  44757956  23% /srv
/dev/sda1       61255492 13356212  44757956  23% /srv/hosts
ホスト上のファイルを確認
docker exec -it k3d-k3s-default-worker-1 cat /etc/hostname
出力結果
k3d-k3s-default-worker-1
