Skip to content
README.md 5.29 KiB
Newer Older
Cyrill Troxler's avatar
Cyrill Troxler committed
# CSI for S3
Cyrill Troxler's avatar
Cyrill Troxler committed
This is a Container Storage Interface ([CSI](https://github.com/container-storage-interface/spec/blob/master/spec.md)) for S3 (or S3 compatible) storage. This can dynamically allocate buckets and mount them via a fuse mount into any container.
Cyrill Troxler's avatar
Cyrill Troxler committed

Cyrill Troxler's avatar
Cyrill Troxler committed
This is still very experimental and should not be used in any production environment. Unexpected data loss could occur depending on what mounter and S3 storage backend is being used.

## Kubernetes installation

### Requirements

Cyrill Troxler's avatar
Cyrill Troxler committed
* Kubernetes 1.13+ (CSI v1.0.0 compatibility)
Cyrill Troxler's avatar
Cyrill Troxler committed
* Kubernetes has to allow privileged containers
* Docker daemon must allow shared mounts (systemd flag `MountFlags=shared`)

### 1. Create a secret with your S3 credentials

Cyrill Troxler's avatar
Cyrill Troxler committed
```yaml
apiVersion: v1
kind: Secret
metadata:
Cyrill Troxler's avatar
Cyrill Troxler committed
  name: csi-s3-secret
Ching Yi, Chan's avatar
Ching Yi, Chan committed
  # Namespace depends on the configuration in the storageclass.yaml
  namespace: kube-system
Cyrill Troxler's avatar
Cyrill Troxler committed
stringData:
  accessKeyID: <YOUR_ACCESS_KEY_ID>
  secretAccessKey: <YOUR_SECRET_ACCES_KEY>
  # For AWS set it to "https://s3.<region>.amazonaws.com"
Cyrill Troxler's avatar
Cyrill Troxler committed
  endpoint: <S3_ENDPOINT_URL>
  # If not on S3, set it to ""
Cyrill Troxler's avatar
Cyrill Troxler committed
  region: <S3_REGION>
```

Cyrill Troxler's avatar
Cyrill Troxler committed
The region can be empty if you are using some other S3 compatible storage.

### 2. Deploy the driver

Cyrill Troxler's avatar
Cyrill Troxler committed
```bash
cd deploy/kubernetes
kubectl create -f provisioner.yaml
kubectl create -f attacher.yaml
kubectl create -f csi-s3.yaml
Cyrill Troxler's avatar
Cyrill Troxler committed
```

### 3. Create the storage class

Cyrill Troxler's avatar
Cyrill Troxler committed
```bash
kubectl create -f examples/storageclass.yaml
Cyrill Troxler's avatar
Cyrill Troxler committed
```

### 4. Test the S3 driver

Cyrill Troxler's avatar
Cyrill Troxler committed
1. Create a pvc using the new storage class:
Cyrill Troxler's avatar
Cyrill Troxler committed
    ```bash
    kubectl create -f examples/pvc.yaml
    ```
1. Check if the PVC has been bound:
Cyrill Troxler's avatar
Cyrill Troxler committed
    ```bash
    $ kubectl get pvc csi-s3-pvc
    NAME         STATUS    VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
    csi-s3-pvc   Bound     pvc-c5d4634f-8507-11e8-9f33-0e243832354b   5Gi        RWO            csi-s3         9s
    ```
1. Create a test pod which mounts your volume:
Cyrill Troxler's avatar
Cyrill Troxler committed
    ```bash
    kubectl create -f examples/pod.yaml
    ```
Cyrill Troxler's avatar
Cyrill Troxler committed
    If the pod can start, everything should be working.
Cyrill Troxler's avatar
Cyrill Troxler committed

Cyrill Troxler's avatar
Cyrill Troxler committed
    ```bash
    $ kubectl exec -ti csi-s3-test-nginx bash
    $ mount | grep fuse
    s3fs on /var/lib/www/html type fuse.s3fs (rw,nosuid,nodev,relatime,user_id=0,group_id=0,allow_other)
    $ touch /var/lib/www/html/hello_world
    ```
Cyrill Troxler's avatar
Cyrill Troxler committed
If something does not work as expected, check the troubleshooting section below.

## Additional configuration

### Bucket

By default, csi-s3 will create a new bucket per volume. The bucket name will match that of the volume ID. If you want your volumes to live in a precreated bucket, you can simply specify the bucket in the storage class parameters:

```yaml
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: csi-s3-existing-bucket
provisioner: ru.yandex.s3.csi
parameters:
  mounter: rclone
  bucket: some-existing-bucket-name
```

If the bucket is specified, it will still be created if it does not exist on the backend. Every volume will get its own prefix within the bucket which matches the volume ID. When deleting a volume, also just the prefix will be deleted.

Cyrill Troxler's avatar
Cyrill Troxler committed
As S3 is not a real file system there are some limitations to consider here. Depending on what mounter you are using, you will have different levels of POSIX compability. Also depending on what S3 storage backend you are using there are not always [consistency guarantees](https://github.com/gaul/are-we-consistent-yet#observed-consistency).

Cyrill Troxler's avatar
Cyrill Troxler committed
The driver can be configured to use one of these mounters to mount buckets:
Cyrill Troxler's avatar
Cyrill Troxler committed

* [geesefs](https://github.com/yandex-cloud/geesefs) (recommended and default)
Cyrill Troxler's avatar
Cyrill Troxler committed
* [s3fs](https://github.com/s3fs-fuse/s3fs-fuse)
* [rclone](https://rclone.org/commands/rclone_mount)
Cyrill Troxler's avatar
Cyrill Troxler committed

Cyrill Troxler's avatar
Cyrill Troxler committed
The mounter can be set as a parameter in the storage class. You can also create multiple storage classes for each mounter if you like.

Characteristics of different mounters (for more detailed information consult their own documentation):
Cyrill Troxler's avatar
Cyrill Troxler committed

* Almost full POSIX compatibility
* Good performance for both small and big files
Cyrill Troxler's avatar
Cyrill Troxler committed
* Files can be viewed normally with any S3 client

* Almost full POSIX compatibility
* Good performance for big files, poor performance for small files
Cyrill Troxler's avatar
Cyrill Troxler committed
* Files can be viewed normally with any S3 client

* Less POSIX compatible than s3fs
* Bad performance for big files, okayish performance for small files
Cyrill Troxler's avatar
Cyrill Troxler committed
* Files can be viewed normally with any S3 client
* Doesn't create directory objects like s3fs or GeeseFS
Cyrill Troxler's avatar
Cyrill Troxler committed

## Troubleshooting

### Issues while creating PVC

Cyrill Troxler's avatar
Cyrill Troxler committed
Check the logs of the provisioner:

```bash
kubectl logs -l app=csi-provisioner-s3 -c csi-s3
Cyrill Troxler's avatar
Cyrill Troxler committed
```

### Issues creating containers

Cyrill Troxler's avatar
Cyrill Troxler committed
1. Ensure feature gate `MountPropagation` is not set to `false`
2. Check the logs of the s3-driver:

```bash
kubectl logs -l app=csi-s3 -c csi-s3
Cyrill Troxler's avatar
Cyrill Troxler committed
```

Cyrill Troxler's avatar
Cyrill Troxler committed
This project can be built like any other go application.
Cyrill Troxler's avatar
Cyrill Troxler committed
```bash
go get -u github.com/ctrox/csi-s3
Cyrill Troxler's avatar
Cyrill Troxler committed
```
Cyrill Troxler's avatar
Cyrill Troxler committed
```bash
Cyrill Troxler's avatar
Cyrill Troxler committed
```
Cyrill Troxler's avatar
Cyrill Troxler committed
Currently the driver is tested by the [CSI Sanity Tester](https://github.com/kubernetes-csi/csi-test/tree/master/pkg/sanity). As end-to-end tests require S3 storage and a mounter like s3fs, this is best done in a docker container. A Dockerfile and the test script are in the `test` directory. The easiest way to run the tests is to just use the make command:
Cyrill Troxler's avatar
Cyrill Troxler committed
```bash
Cyrill Troxler's avatar
Cyrill Troxler committed
```