株式会社ヴァンデミックシステム

Blog

<スポンサーリンク>

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

<スポンサーリンク>

コメントを残す

Allowed tags:  you may use these HTML tags and attributes: <a href="">, <strong>, <em>, <h1>, <h2>, <h3>
Please note:  all comments go through moderation.

*

日本語が含まれない投稿は無視されますのでご注意ください。(スパム対策)