LoginSignup
2
0

More than 3 years have passed since last update.

k3dで永続ボリューム(PersistentVolume)を使う

Posted at

やること、わかったこと

  • 永続ボリューム上にファイルを作成して、Podを再作成してもちゃんと残っていることをチェック
  • minikube,microk8sなど他のk8sと違いはなさそう
  • ただ、今のところDynamicProvisioningが対応していないよう

参考

k3d起動

k3d create

kubetclコマンドを実行できるように環境変数をセット

export KUBECONFIG="$(k3d get-kubeconfig --name='k3s-default')"

kubectlコマンド実行できるか確認

kubectl cluster-info

出力結果

Kubernetes master is running at https://localhost:6443
CoreDNS is running at https://localhost:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

ストレージ検証セットをデプロイ

kubectl apply -f https://raw.githubusercontent.com/rancher/local-path-provisioner/master/deploy/local-path-storage.yaml

podがデプロイされているか確認

kubectl -n local-path-storage get pod

出力結果

NAME                                    READY   STATUS    RESTARTS   AGE
local-path-provisioner-848fdcff-k8vdm   1/1     Running   0          2m18s

ログも確認

kubectl -n local-path-storage logs -f  local-path-provisioner-848fdcff-k8vdm

出力結果

time="2019-09-23T07:19:05Z" level=debug msg="Applied config: {\"nodePathMap\":[{\"node\":\"DEFAULT_PATH_FOR_NON_LISTED_NODES\",\"paths\":[\"/opt/local-path-provisioner\"]}]}"
time="2019-09-23T07:19:05Z" level=debug msg="Provisioner started"

PVとPVCをデプロイ

kubectl create -f https://raw.githubusercontent.com/rancher/local-path-provisioner/master/examples/pvc.yaml
kubectl create -f https://raw.githubusercontent.com/rancher/local-path-provisioner/master/examples/pod.yaml

デプロイされているか確認

kubectl get pv
kubectl get pvc

ファイルを作成する

kubectl exec volume-test -- sh -c "echo local-path-test > /data/test"

podを削除

kubectl delete -f https://raw.githubusercontent.com/rancher/local-path-provisioner/master/examples/pod.yaml

podを再作成

kubectl create -f https://raw.githubusercontent.com/rancher/local-path-provisioner/master/examples/pod.yaml

catでファイルを確認

kubectl exec volume-test cat /data/test

出力結果

Podを消してもpv上のファイルは保持されていることがわかりました

local-path-test

pvとpvcを削除(後片付け)

kubectl delete -f https://raw.githubusercontent.com/rancher/local-path-provisioner/master/examples/pod.yaml
kubectl delete -f https://raw.githubusercontent.com/rancher/local-path-provisioner/master/examples/pvc.yaml
2
0
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
2
0