This project implements a Container Storage Interface (CSI) driver for Kubernetes that supports ephemeral volumes. Ephemeral volumes are temporary storage volumes that are created and destroyed with the pod lifecycle.
The CSI driver consists of two main components:
- Controller Service: Handles volume provisioning and deletion.
- Node Service: Manages volume mounting and unmounting on the node.
The driver uses a local filesystem-based approach, where volumes are created as directories on the host. For ephemeral volumes, the driver creates the volume directory on the node if it does not exist, ensuring that the volume is available for the pod.
CSI is a standard interface for container orchestration systems to expose arbitrary storage systems to their container workloads. Ephemeral volumes are volumes that are created and destroyed with the pod lifecycle, providing temporary storage for applications.
To use the CSI driver, you need to:
- Deploy the CSI driver to your Kubernetes cluster.
- Create a pod that uses the CSI driver for ephemeral storage.
Example pod specification:
apiVersion: v1
kind: Pod
metadata:
name: test-ephemeral-volume
spec:
containers:
- name: test-container
image: busybox
command: ["/bin/sh", "-c", "while true; do echo 'Hello from ephemeral volume' >> /data/test.txt; sleep 5; done"]
volumeMounts:
- name: ephemeral-volume
mountPath: /data
volumes:
- name: ephemeral-volume
csi:
driver: ephemeral.csi.local
volumeAttributes:
size: "1Gi"- Kubernetes cluster (e.g., minikube)
- Docker
- Go 1.21 or later
-
Clone the repository:
git clone https://github.com/chinnareddy578/kubernetes-ephemeral-csi.git cd kubernetes-ephemeral-csi -
Build the driver:
make build
-
Build the Docker image:
docker build -t ephemeral-csi:latest . -
Load the image into minikube:
minikube image load ephemeral-csi:latest
-
Apply the CSI driver deployment:
kubectl apply -f deploy/kubernetes/csi-driver.yaml
-
Verify the deployment:
kubectl get pods -n kube-system | grep ephemeral-csi
-
Deploy the test pod:
kubectl apply -f deploy/kubernetes/test-pod.yaml
-
Check the pod status:
kubectl get pods | grep test-ephemeral-volume -
Verify the volume is mounted and writable:
kubectl exec test-ephemeral-volume -- cat /data/test.txt
We welcome contributions! If you encounter any issues or have suggestions for improvements, please submit them through the GitHub issue tracker. For change proposals, please create a pull request with a detailed description of the changes.
This project is licensed under the MIT License. See the LICENSE file for details.