Update README and deployment, split up dockerfile

This commit is contained in:
Cyrill Troxler 2019-05-14 21:53:44 +02:00
parent c6b3b5199d
commit 152eeb1d14
10 changed files with 168 additions and 112 deletions

108
README.md
View file

@ -1,17 +1,23 @@
# CSI for S3 # CSI for S3
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. 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.
# Status ## Status
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. 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 ## Kubernetes installation
## Requirements
* Kubernetes 1.10+ ### Requirements
* Kubernetes 1.13+
* Kubernetes has to allow privileged containers * Kubernetes has to allow privileged containers
* Docker daemon must allow shared mounts (systemd flag `MountFlags=shared`) * Docker daemon must allow shared mounts (systemd flag `MountFlags=shared`)
## 1. Create a secret with your S3 credentials ### 1. Create a secret with your S3 credentials
The endpoint is optional if you are using something else than AWS S3. Also the region can be empty if you are using some other S3 compatible storage. The endpoint is optional if you are using something else than AWS S3. Also the region can be empty if you are using some other S3 compatible storage.
```yaml ```yaml
apiVersion: v1 apiVersion: v1
kind: Secret kind: Secret
@ -20,7 +26,7 @@ metadata:
stringData: stringData:
accessKeyID: <YOUR_ACCESS_KEY_ID> accessKeyID: <YOUR_ACCESS_KEY_ID>
secretAccessKey: <YOUR_SECRET_ACCES_KEY> secretAccessKey: <YOUR_SECRET_ACCES_KEY>
# For AWS set it to "https://s3.amazonaws.com" # For AWS set it to "https://s3.<region>.amazonaws.com"
endpoint: <S3_ENDPOINT_URL> endpoint: <S3_ENDPOINT_URL>
# If not on S3, set it to "" # If not on S3, set it to ""
region: <S3_REGION> region: <S3_REGION>
@ -29,47 +35,60 @@ stringData:
encryptionKey: <FS_ENCRYPTION_KEY> encryptionKey: <FS_ENCRYPTION_KEY>
``` ```
## 2. Deploy the driver ### 2. Deploy the driver
```bash ```bash
cd deploy/kubernetes cd deploy/kubernetes
$ kubectl create -f provisioner.yaml kubectl create -f provisioner.yaml
$ kubectl create -f attacher.yaml kubectl create -f attacher.yaml
$ kubectl create -f csi-s3.yaml kubectl create -f csi-s3.yaml
``` ```
## 3. Create the storage class ### 3. Create the storage class
```bash ```bash
$ kubectl create -f storageclass.yaml kubectl create -f storageclass.yaml
``` ```
## 4. Test the S3 driver ### 4. Test the S3 driver
* Create a pvc using the new storage class: * Create a pvc using the new storage class:
```bash ```bash
$ kubectl create -f pvc.yaml kubectl create -f pvc.yaml
``` ```
* Check if the PVC has been bound: * Check if the PVC has been bound:
```bash ```bash
$ kubectl get pvc csi-s3-pvc $ kubectl get pvc csi-s3-pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
csi-s3-pvc Bound pvc-c5d4634f-8507-11e8-9f33-0e243832354b 5Gi RWX csi-s3 9s csi-s3-pvc Bound pvc-c5d4634f-8507-11e8-9f33-0e243832354b 5Gi RWX csi-s3 9s
``` ```
* Create a test pod which mounts your volume: * Create a test pod which mounts your volume:
```bash ```bash
$ kubectl create -f poc.yaml kubectl create -f poc.yaml
``` ```
If the pod can start, everything should be working. If the pod can start, everything should be working.
* Test the mount * Test the mount
```bash ```bash
$ kubectl exec -ti csi-s3-test-nginx bash $ kubectl exec -ti csi-s3-test-nginx bash
$ mount | grep fuse $ mount | grep fuse
s3fs on /var/lib/www/html type fuse.s3fs (rw,nosuid,nodev,relatime,user_id=0,group_id=0,allow_other) 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 $ touch /var/lib/www/html/hello_world
``` ```
If something does not work as expected, check the troubleshooting section below. If something does not work as expected, check the troubleshooting section below.
# Additional configuration ## Additional configuration
## Mounter
### Mounter
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). 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).
The driver can be configured to use one of these mounters to mount buckets: The driver can be configured to use one of these mounters to mount buckets:
@ -84,22 +103,26 @@ The mounter can be set as a parameter in the storage class. You can also create
All mounters have different strengths and weaknesses depending on your use case. Here are some characteristics which should help you choose a mounter: All mounters have different strengths and weaknesses depending on your use case. Here are some characteristics which should help you choose a mounter:
### rclone #### rclone
* Almost full POSIX compatibility (depends on caching mode) * Almost full POSIX compatibility (depends on caching mode)
* Files can be viewed normally with any S3 client * Files can be viewed normally with any S3 client
### s3fs #### s3fs
* Large subset of POSIX * Large subset of POSIX
* Files can be viewed normally with any S3 client * Files can be viewed normally with any S3 client
* Does not support appends or random writes * Does not support appends or random writes
### goofys #### goofys
* Weak POSIX compatibility * Weak POSIX compatibility
* Performance first * Performance first
* Files can be viewed normally with any S3 client * Files can be viewed normally with any S3 client
* Does not support appends or random writes * Does not support appends or random writes
### s3ql #### s3ql (not recommended*)
* (Almost) full POSIX compatibility * (Almost) full POSIX compatibility
* Uses its own object format * Uses its own object format
* Files are not readable with other S3 clients * Files are not readable with other S3 clients
@ -107,7 +130,8 @@ All mounters have different strengths and weaknesses depending on your use case.
* Supports compression before upload * Supports compression before upload
* Supports encryption before upload * Supports encryption before upload
### s3backer #### s3backer (not recommended*)
* Represents a block device stored on S3 * Represents a block device stored on S3
* Allows to use a real filesystem * Allows to use a real filesystem
* Files are not readable with other S3 clients * Files are not readable with other S3 clients
@ -115,33 +139,47 @@ All mounters have different strengths and weaknesses depending on your use case.
* Supports compression before upload (Not yet implemented in this driver) * Supports compression before upload (Not yet implemented in this driver)
* Supports encryption before upload (Not yet implemented in this driver) * Supports encryption before upload (Not yet implemented in this driver)
*s3ql and s3backer are not recommended at this point because volume corruption can occur pretty quickly in case of an unexpected shutdown of a Kubernetes node or CSI pod.
Fore more detailed limitations consult the documentation of the different projects. Fore more detailed limitations consult the documentation of the different projects.
# Troubleshooting ## Troubleshooting
## Issues while creating PVC
### Issues while creating PVC
* Check the logs of the provisioner: * Check the logs of the provisioner:
```
$ kubectl logs -l app=csi-provisioner-s3 -c csi-s3 ```bash
kubectl logs -l app=csi-provisioner-s3 -c csi-s3
``` ```
## Issues creating containers ### Issues creating containers
* Ensure feature gate `MountPropagation` is not set to `false` * Ensure feature gate `MountPropagation` is not set to `false`
* Check the logs of the s3-driver: * Check the logs of the s3-driver:
```
$ kubectl logs -l app=csi-s3 -c csi-s3 ```bash
kubectl logs -l app=csi-s3 -c csi-s3
``` ```
# Development ## Development
This project can be built like any other go application. This project can be built like any other go application.
```bash ```bash
$ go get -u github.com/ctrox/csi-s3 go get -u github.com/ctrox/csi-s3
``` ```
## Build
### Build executable
```bash ```bash
$ make build make build
``` ```
## Tests
### Tests
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: 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:
```bash ```bash
$ make test make test
``` ```

View file

@ -1,61 +1,12 @@
FROM python:3.6 as s3ql-deps FROM debian:stretch
LABEL maintainers="Cyrill Troxler <cyrilltroxler@gmail.com>" LABEL maintainers="Cyrill Troxler <cyrilltroxler@gmail.com>"
LABEL description="s3ql dependencies" LABEL description="csi-s3 slim image"
RUN apt-get update && \ RUN apt-get update && \
apt-get install -y \ apt-get install -y \
python3 python3-setuptools \ s3fs wget unzip && \
python3-dev python3-pip pkg-config cython \
libfuse-dev libattr1-dev && \
rm -rf /var/lib/apt/lists/* rm -rf /var/lib/apt/lists/*
RUN pip3 install llfuse apsw defusedxml dugong requests pycrypto
FROM debian:stretch as s3backer
ARG S3BACKER_VERSION=1.5.0
RUN apt-get update && apt-get install -y \
build-essential \
autoconf \
libcurl4-openssl-dev \
libfuse-dev \
libexpat1-dev \
libssl-dev \
zlib1g-dev \
psmisc \
pkg-config \
git && \
rm -rf /var/lib/apt/lists/*
# Compile & install s3backer
RUN git clone https://github.com/archiecobbs/s3backer.git /src/s3backer
WORKDIR /src/s3backer
RUN git checkout tags/${S3BACKER_VERSION}
RUN ./autogen.sh && \
./configure && \
make && \
make install
FROM python:3.6-slim
LABEL maintainers="Cyrill Troxler <cyrilltroxler@gmail.com>"
LABEL description="csi-s3 production image"
RUN apt-get update && \
apt-get install -y \
libfuse2 gcc sqlite3 libsqlite3-dev \
s3fs psmisc procps libcurl3 xfsprogs wget unzip && \
rm -rf /var/lib/apt/lists/*
ARG S3QL_VERSION=2.29
ENV S3QL_URL=https://github.com/s3ql/s3ql/releases/download/release-${S3QL_VERSION}/s3ql-${S3QL_VERSION}.tar.bz2
COPY --from=s3ql-deps /root/.cache /root/.cache
COPY --from=s3ql-deps /usr/local/lib/python3.6/site-packages /usr/local/lib/python3.6/site-packages
RUN pip install ${S3QL_URL} && rm -rf /root/.cache
COPY --from=s3backer /usr/bin/s3backer /usr/bin/s3backer
# install rclone # install rclone
ARG RCLONE_VERSION=v1.46 ARG RCLONE_VERSION=v1.46
RUN cd /tmp \ RUN cd /tmp \

View file

@ -0,0 +1,68 @@
FROM python:3.6 as s3ql-deps
LABEL maintainers="Cyrill Troxler <cyrilltroxler@gmail.com>"
LABEL description="s3ql dependencies"
RUN apt-get update && \
apt-get install -y \
python3 python3-setuptools \
python3-dev python3-pip pkg-config cython \
libfuse-dev libattr1-dev && \
rm -rf /var/lib/apt/lists/*
RUN pip3 install llfuse apsw defusedxml dugong requests pycrypto
FROM debian:stretch as s3backer
ARG S3BACKER_VERSION=1.5.0
RUN apt-get update && apt-get install -y \
build-essential \
autoconf \
libcurl4-openssl-dev \
libfuse-dev \
libexpat1-dev \
libssl-dev \
zlib1g-dev \
psmisc \
pkg-config \
git && \
rm -rf /var/lib/apt/lists/*
# Compile & install s3backer
RUN git clone https://github.com/archiecobbs/s3backer.git /src/s3backer
WORKDIR /src/s3backer
RUN git checkout tags/${S3BACKER_VERSION}
RUN ./autogen.sh && \
./configure && \
make && \
make install
FROM python:3.6-slim
LABEL maintainers="Cyrill Troxler <cyrilltroxler@gmail.com>"
LABEL description="csi-s3 full image"
RUN apt-get update && \
apt-get install -y \
libfuse2 gcc sqlite3 libsqlite3-dev \
s3fs psmisc procps libcurl3 xfsprogs wget unzip && \
rm -rf /var/lib/apt/lists/*
ARG S3QL_VERSION=2.29
ENV S3QL_URL=https://github.com/s3ql/s3ql/releases/download/release-${S3QL_VERSION}/s3ql-${S3QL_VERSION}.tar.bz2
COPY --from=s3ql-deps /root/.cache /root/.cache
COPY --from=s3ql-deps /usr/local/lib/python3.6/site-packages /usr/local/lib/python3.6/site-packages
RUN pip install ${S3QL_URL} && rm -rf /root/.cache
COPY --from=s3backer /usr/bin/s3backer /usr/bin/s3backer
# install rclone
ARG RCLONE_VERSION=v1.46
RUN cd /tmp \
&& wget -q https://downloads.rclone.org/${RCLONE_VERSION}/rclone-${RCLONE_VERSION}-linux-amd64.zip \
&& unzip /tmp/rclone-${RCLONE_VERSION}-linux-amd64.zip \
&& mv /tmp/rclone-*-linux-amd64/rclone /usr/bin \
&& rm -r /tmp/rclone*
COPY ./_output/s3driver /s3driver
ENTRYPOINT ["/s3driver"]

View file

@ -67,7 +67,7 @@ spec:
serviceAccount: csi-attacher-sa serviceAccount: csi-attacher-sa
containers: containers:
- name: csi-attacher - name: csi-attacher
image: quay.io/k8scsi/csi-attacher:v1.0.1 image: quay.io/k8scsi/csi-attacher:v1.1.0
args: args:
- "--v=4" - "--v=4"
- "--csi-address=$(ADDRESS)" - "--csi-address=$(ADDRESS)"

View file

@ -55,7 +55,7 @@ spec:
hostNetwork: true hostNetwork: true
containers: containers:
- name: driver-registrar - name: driver-registrar
image: quay.io/k8scsi/csi-node-driver-registrar:v1.0.1 image: quay.io/k8scsi/csi-node-driver-registrar:v1.1.0
args: args:
- "--kubelet-registration-path=$(DRIVER_REG_SOCK_PATH)" - "--kubelet-registration-path=$(DRIVER_REG_SOCK_PATH)"
- "--v=4" - "--v=4"
@ -80,15 +80,10 @@ spec:
capabilities: capabilities:
add: ["SYS_ADMIN"] add: ["SYS_ADMIN"]
allowPrivilegeEscalation: true allowPrivilegeEscalation: true
image: ctrox/csi-s3:1.0.1-alpha image: ctrox/csi-s3:v1.1.0
args: args:
- "--endpoint=$(CSI_ENDPOINT)" - "--endpoint=$(CSI_ENDPOINT)"
- "--nodeid=$(NODE_ID)" - "--nodeid=$(NODE_ID)"
- "--access-key-id=$(ACCESS_KEY_ID)"
- "--secret-access-key=$(SECRET_ACCESS_KEY)"
- "--s3-endpoint=$(S3_ENDPOINT)"
- "--region=$(REGION)"
- "--encryption-key=$(ENCRYPTION_KEY)"
- "--v=4" - "--v=4"
env: env:
- name: CSI_ENDPOINT - name: CSI_ENDPOINT

View file

@ -2,6 +2,7 @@ apiVersion: v1
kind: Pod kind: Pod
metadata: metadata:
name: csi-s3-test-nginx name: csi-s3-test-nginx
namespace: default
spec: spec:
containers: containers:
- name: csi-s3-test-nginx - name: csi-s3-test-nginx

View file

@ -66,7 +66,7 @@ spec:
serviceAccount: csi-provisioner-sa serviceAccount: csi-provisioner-sa
containers: containers:
- name: csi-provisioner - name: csi-provisioner
image: quay.io/k8scsi/csi-provisioner:v1.0.1 image: quay.io/k8scsi/csi-provisioner:v1.1.0
args: args:
- "--provisioner=ch.ctrox.csi.s3-driver" - "--provisioner=ch.ctrox.csi.s3-driver"
- "--csi-address=$(ADDRESS)" - "--csi-address=$(ADDRESS)"
@ -79,15 +79,10 @@ spec:
- name: socket-dir - name: socket-dir
mountPath: /var/lib/kubelet/plugins/ch.ctrox.csi.s3-driver mountPath: /var/lib/kubelet/plugins/ch.ctrox.csi.s3-driver
- name: csi-s3 - name: csi-s3
image: ctrox/csi-s3:1.0.1-alpha image: ctrox/csi-s3:v1.1.0
args: args:
- "--endpoint=$(CSI_ENDPOINT)" - "--endpoint=$(CSI_ENDPOINT)"
- "--nodeid=$(NODE_ID)" - "--nodeid=$(NODE_ID)"
- "--access-key-id=$(ACCESS_KEY_ID)"
- "--secret-access-key=$(SECRET_ACCESS_KEY)"
- "--s3-endpoint=$(S3_ENDPOINT)"
- "--region=$(REGION)"
- "--encryption-key=$(ENCRYPTION_KEY)"
- "--v=4" - "--v=4"
env: env:
- name: CSI_ENDPOINT - name: CSI_ENDPOINT

View file

@ -5,10 +5,10 @@ metadata:
stringData: stringData:
accessKeyID: <YOUR_ACCESS_KEY_ID> accessKeyID: <YOUR_ACCESS_KEY_ID>
secretAccessKey: <YOUR_SECRET_ACCES_KEY> secretAccessKey: <YOUR_SECRET_ACCES_KEY>
# For AWS set it to "https://s3.amazonaws.com" # For AWS set it to "https://s3.<region>.amazonaws.com"
endpoint: <S3_ENDPOINT_URL> endpoint: https://s3.eu-central-1.amazonaws.com
# If not on S3, set it to "" # If not on S3, set it to ""
region: <S3_REGION> region: <S3_REGION>
# Currently only for s3ql # Currently only for s3ql
# If not using s3ql, set it to "" # If not using s3ql, set it to ""
encryptionKey: <FS_ENCRYPTION_KEY> encryptionKey: ""

View file

@ -7,4 +7,12 @@ provisioner: ch.ctrox.csi.s3-driver
parameters: parameters:
# specify which mounter to use # specify which mounter to use
# can be set to s3backer, s3ql, s3fs or goofys # can be set to s3backer, s3ql, s3fs or goofys
mounter: s3backer mounter: rclone
csi.storage.k8s.io/provisioner-secret-name: csi-s3-secret
csi.storage.k8s.io/provisioner-secret-namespace: kube-system
csi.storage.k8s.io/controller-publish-secret-name: csi-s3-secret
csi.storage.k8s.io/controller-publish-secret-namespace: kube-system
csi.storage.k8s.io/node-stage-secret-name: csi-s3-secret
csi.storage.k8s.io/node-stage-secret-namespace: kube-system
csi.storage.k8s.io/node-publish-secret-name: csi-s3-secret
csi.storage.k8s.io/node-publish-secret-namespace: kube-system

View file

@ -40,7 +40,7 @@ type s3Volume struct {
} }
var ( var (
vendorVersion = "1.0.1-alpha" vendorVersion = "1.1.0"
driverName = "ch.ctrox.csi.s3-driver" driverName = "ch.ctrox.csi.s3-driver"
) )