Help us understand the problem. What is going on with this article?

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

やること、わかったこと

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

参考

https://github.com/rancher/local-path-provisioner

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
Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away