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

Blog

<スポンサーリンク>

kindは、Dockerコンテナ上で動作しているため、コンテナ側から見えるhostpathは実際はDockerコンテナ上のディレクトリとなる。
なので、ローカルマシン→Dockerコンテナ→Kind上コンテナの順でマウントさせる必要がある。

クラスタ作成時点でNodeに対してローカルパスをマウントする

cat <<EOF | kind create cluster  --image kindest/node:v1.22.1@sha256:e0bf222d7dd1589075117c51740903017b328c59ffb0c3d97187a2b3de1f92b3 --config=-
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
- role: control-plane
  extraMounts:
    - hostPath: /data
      containerPath: /data
EOF

deployment

---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv-www
spec:
  storageClassName: standard
  accessModes:
    - ReadWriteOnce
  capacity:
    storage: 2Gi
  hostPath:
    path: /data/
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: pvc-www
spec:
  volumeName: pv-www
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      volumes:
      - name: www
        persistentVolumeClaim:
          claimName: pvc-www
      containers:
      - name: nginx
        image: nginx:1.14.2
        volumeMounts:
        - name: www
          mountPath: /var/www

中身

# Nginxコンテナへログイン 
kubectl-iexec nginx
ls /var/www
aiut

# ローカルパス
ls /data/
aiut

参考

<スポンサーリンク>

コメントを残す

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

*

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