DEV Community

DarkEdges
DarkEdges

Posted on

deploy the csi driver hostpath to kubernetes n windows docker

We have been trying to find ways to get volumesnaphot working on a kubernetes deployment on Windows Docker, but it has always failed us as it is Windows underlying kubernetes.

We found that minikube was using https://github.com/kubernetes-csi/csi-driver-host-path so we started to look at how to deploy that into our environment.

It took a little finagling using a wsl2 container as the deployment needed a linux runtime to do the deployment. Anyway here are the steps we took.

deployment

Start a wsl2 container such as ubuntu that has docker integration enabled via Terminal and issue the following commands

git clone https://github.com/kubernetes-csi/csi-driver-host-path.git
cd csi-driver-host-path/
kubectl apply -f https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/release-6.3/client/config/crd/snapshot.storage.k8s.io_volumesnapshotclasses.yaml
kubectl apply -f https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/release-6.3/client/config/crd/snapshot.storage.k8s.io_volumesnapshotcontents.yaml
kubectl apply -f https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/release-6.3/client/config/crd/snapshot.storage.k8s.io_volumesnapshots.yaml
kubectl apply -f https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/v6.3.3/deploy/kubernetes/snapshot-controller/rbac-snapshot-controller.yaml
kubectl apply -f https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/v6.3.3/deploy/kubernetes/snapshot-controller/setup-snapshot-controller.yaml
deploy/kubernetes-latest/deploy.sh
Enter fullscreen mode Exit fullscreen mode

When all is finished issue the following for sanity checks

kubectl get volumesnapshotclass
Enter fullscreen mode Exit fullscreen mode

returns

NAME                     DRIVER                DELETIONPOLICY   AGE
csi-hostpath-snapclass   hostpath.csi.k8s.io   Delete           24h
Enter fullscreen mode Exit fullscreen mode
kubectl get pods -n kube-system
Enter fullscreen mode Exit fullscreen mode

check for similar

NAME                                     READY   STATUS    RESTARTS       AGE

snapshot-controller-59db5f898f-dj8ct     1/1     Running   0              24h
snapshot-controller-59db5f898f-z2p59     1/1     Running   0              24h
storage-provisioner                      1/1     Running   67 (15d ago)   111d
Enter fullscreen mode Exit fullscreen mode
kubectl get pods -n default
Enter fullscreen mode Exit fullscreen mode

check for similar

NAME                   READY   STATUS    RESTARTS   AGE
csi-hostpath-socat-0   1/1     Running   0          24h
csi-hostpathplugin-0   8/8     Running   0          24h
Enter fullscreen mode Exit fullscreen mode
kubectl get volumesnapshotclass
Enter fullscreen mode Exit fullscreen mode

check for similar

NAME                     DRIVER                DELETIONPOLICY   AGE
csi-hostpath-snapclass   hostpath.csi.k8s.io   Delete           24h
Enter fullscreen mode Exit fullscreen mode

Testing

The following describe shows how to test and validate it is working

cd csi-driver-host-path/
kubens default
kubectl apply -f examples/csi-app.yaml
Enter fullscreen mode Exit fullscreen mode

check it is running

kubectl get pod my-csi-app
Enter fullscreen mode Exit fullscreen mode

returns similar to

NAME         READY   STATUS    RESTARTS   AGE
my-csi-app   1/1     Running   0          24h
Enter fullscreen mode Exit fullscreen mode

Test File

Add a file to the file system

kubectl exec -it my-csi-app --- touch data/hello-world
Enter fullscreen mode Exit fullscreen mode

Check CSI Host

kubectl exec -it csi-hostpathplugin-0 -c hostpath -- find / -name hello-world
Enter fullscreen mode Exit fullscreen mode

should return similar to

/var/lib/kubelet/pods/4afdb0c6-9166-4f32-9e9f-686ad3b3ad31/volumes/kubernetes.io~csi/pvc-9ce19ec7-99ff-484f-acd9-d5158e1efa67/mount/hello-world
/csi-data-dir/7f3fae05-f52c-11ee-9c3e-1a6977443d45/hello-world
Enter fullscreen mode Exit fullscreen mode

We will expand further on how to use this in a later article.

Top comments (0)