LoginSignup
5
3

More than 3 years have passed since last update.

KubernetesでHostPathを使う

Posted at

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
5
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3