From 0019469221211b1be10b63f375ce048ecf4d5d17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bauer?= Date: Mon, 20 Nov 2017 23:59:01 +0100 Subject: [PATCH] added nfs server for kubernetes --- containers/zammad-nfs/Dockerfile | 22 +++++++++++ containers/zammad-nfs/docker-entrypoint.sh | 18 +++++++++ containers/zammad-postgresql/backup.sh | 2 + containers/zammad/Dockerfile | 4 +- containers/zammad/docker-entrypoint.sh | 40 +++++++++++++------- docker-compose.yml | 14 +++---- hooks/config | 2 +- kubernetes/10_pvc.yaml | 1 + kubernetes/50_statefulset_postgesql.yaml | 4 +- kubernetes/51_statefulset_elasticsearch.yaml | 4 +- kubernetes/52_statefulset_railsserver.yaml | 6 ++- kubernetes/53_statefulset_websocket.yaml | 6 ++- kubernetes/54_statefulset_nginx.yaml | 4 +- kubernetes/55_statefulset_scheduler.yaml | 8 ++-- kubernetes/56_statefulset_nfs.yaml | 30 +++++++++++++++ kubernetes/80_sv.yaml | 21 +++++++++- 16 files changed, 149 insertions(+), 37 deletions(-) create mode 100644 containers/zammad-nfs/Dockerfile create mode 100644 containers/zammad-nfs/docker-entrypoint.sh create mode 100644 kubernetes/56_statefulset_nfs.yaml diff --git a/containers/zammad-nfs/Dockerfile b/containers/zammad-nfs/Dockerfile new file mode 100644 index 0000000..591585a --- /dev/null +++ b/containers/zammad-nfs/Dockerfile @@ -0,0 +1,22 @@ +FROM cpuguy83/nfs-server +MAINTAINER Zanmmad + +ENV NFS_DIR /mnt/zammad +ENV TMPFS_SIZE 1G + +LABEL org.label-schema.build-date="$BUILD_DATE" \ + org.label-schema.name="Zammad" \ + org.label-schema.license="AGPL-3.0" \ + org.label-schema.description="Docker container for Zammad - NFS Server Container for Kubernetes" \ + org.label-schema.url="https://zammad.org" \ + org.label-schema.vcs-url="https://github.com/zammad/zammad" \ + org.label-schema.vcs-type="Git" \ + org.label-schema.vendor="Zammad" \ + org.label-schema.schema-version="1.2" \ + org.label-schema.docker.cmd="sysctl -w vm.max_map_count=262144;docker-compose up" + +# docker init +COPY containers/zammad-nfs/docker-entrypoint.sh / +RUN chmod +x /docker-entrypoint.sh +ENTRYPOINT ["/docker-entrypoint.sh"] +CMD ["zammad-nfs"] diff --git a/containers/zammad-nfs/docker-entrypoint.sh b/containers/zammad-nfs/docker-entrypoint.sh new file mode 100644 index 0000000..b8c1002 --- /dev/null +++ b/containers/zammad-nfs/docker-entrypoint.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +set -o errexit +set -o nounset +set -o pipefail + +if [ "$1" = 'zammad-nfs' ]; then + echo "create & mount tmpfs" + mkdir -p ${NFS_DIR} + chmod 777 ${NFS_DIR} + mount -t tmpfs -o size=${TMPFS_SIZE} none ${NFS_DIR} + + echo "create nfs exports" + echo "# NFS Export for Zammad" > /etc/exports + echo "${NFS_DIR} *(rw,sync,no_subtree_check,fsid=0,no_root_squash)" >> /etc/exports + + exec runsvdir /etc/sv +fi diff --git a/containers/zammad-postgresql/backup.sh b/containers/zammad-postgresql/backup.sh index 86852e3..c74b71e 100644 --- a/containers/zammad-postgresql/backup.sh +++ b/containers/zammad-postgresql/backup.sh @@ -1,5 +1,7 @@ #!/bin/bash +set -e + function check_railsserver_available { # wait for zammad process coming up until (echo > /dev/tcp/zammad-railsserver/3000) &> /dev/null; do diff --git a/containers/zammad/Dockerfile b/containers/zammad/Dockerfile index 883d196..22e6a7f 100644 --- a/containers/zammad/Dockerfile +++ b/containers/zammad/Dockerfile @@ -23,7 +23,7 @@ LABEL org.label-schema.build-date="$BUILD_DATE" \ org.label-schema.docker.cmd="sysctl -w vm.max_map_count=262144;docker-compose up" # install dependencies, GOSU & zammad -RUN BUILD_DEPENDENCIES="git build-essential libffi-dev libpq5 libpq-dev rsync" \ +RUN BUILD_DEPENDENCIES="git build-essential libffi-dev libpq5 libpq-dev nfs-common rsync" \ GOSU_DEPENDENCIES="ca-certificates wget" \ set -ex \ && apt-get update && apt-get install -y --force-yes --no-install-recommends ${BUILD_DEPENDENCIES} ${GOSU_DEPENDENCIES} && rm -rf /var/lib/apt/lists/* \ @@ -49,7 +49,7 @@ RUN BUILD_DEPENDENCIES="git build-essential libffi-dev libpq5 libpq-dev rsync" \ # docker init COPY containers/zammad/docker-entrypoint.sh / -RUN chown ${ZAMMAD_USER}:${ZAMMAD_USER} /docker-entrypoint.sh && chmod +x /docker-entrypoint.sh +RUN chmod +x /docker-entrypoint.sh ENTRYPOINT ["/docker-entrypoint.sh"] WORKDIR ${ZAMMAD_DIR} diff --git a/containers/zammad/docker-entrypoint.sh b/containers/zammad/docker-entrypoint.sh index 4b67e0e..d09234b 100644 --- a/containers/zammad/docker-entrypoint.sh +++ b/containers/zammad/docker-entrypoint.sh @@ -1,7 +1,26 @@ #!/bin/bash +set -o errexit +set -o nounset +set -o pipefail + +function check_railsserver_available { + # wait for zammad process coming up + until (echo > /dev/tcp/zammad-railsserver/3000) &> /dev/null; do + echo "backup waiting for zammads railsserver to be ready..." + sleep 2 + done +} + +function mount_nfs { + if [ -n "$(env|grep KUBERNETES)" ]; then + mount -t nfs4 zammad-nfs:/ /home/zammad/tmp + fi +} + # zammad-railsserver if [ "$1" = 'zammad-railsserver' ]; then + # wait for postgres process coming up on zammad-postgresql until (echo > /dev/tcp/zammad-postgresql/5432) &> /dev/null; do echo "zammad railsserver waiting for postgresql server to be ready..." @@ -11,13 +30,12 @@ if [ "$1" = 'zammad-railsserver' ]; then echo "railsserver can access postgresql server now..." rsync -a --delete --exclude 'storage/fs/*' ${ZAMMAD_TMP_DIR}/ ${ZAMMAD_DIR} - cd ${ZAMMAD_DIR} - - # update zammad gem update bundler bundle install + mount_nfs + # db mirgrate bundle exec rake db:migrate &> /dev/null @@ -48,14 +66,12 @@ fi # zammad-scheduler if [ "$1" = 'zammad-scheduler' ]; then - # wait for zammad process coming up - until (echo > /dev/tcp/zammad-railsserver/3000) &> /dev/null; do - echo "scheduler waiting for zammads railsserver to be ready..." - sleep 2 - done + check_railsserver_available echo "scheduler can access raillsserver now..." + mount_nfs + # start scheduler cd ${ZAMMAD_DIR} exec gosu ${ZAMMAD_USER}:${ZAMMAD_USER} bundle exec script/scheduler.rb run @@ -64,14 +80,12 @@ fi # zammad-websocket if [ "$1" = 'zammad-websocket' ]; then - # wait for zammad process coming up - until (echo > /dev/tcp/zammad-railsserver/3000) &> /dev/null; do - echo "websocket server waiting for zammads railsserver to be ready..." - sleep 5 - done + check_railsserver_available echo "websocket server can access raillsserver now..." + mount_nfs + cd ${ZAMMAD_DIR} exec gosu ${ZAMMAD_USER}:${ZAMMAD_USER} bundle exec script/websocket-server.rb -b 0.0.0.0 start fi diff --git a/docker-compose.yml b/docker-compose.yml index 20911e0..57009c5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,7 +5,7 @@ services: zammad-backup: depends_on: - zammad-railsserver - image: zammad/zammad-docker-compose:zammad-postgresql${VERSION} + image: monotek/zammad-docker-compose:zammad-postgresql${VERSION} labels: io.rancher.container.pull_image: always links: @@ -18,7 +18,7 @@ services: command: zammad-backup zammad-elasticsearch: - image: zammad/zammad-docker-compose:zammad-elasticsearch${VERSION} + image: monotek/zammad-docker-compose:zammad-elasticsearch${VERSION} labels: io.rancher.container.pull_image: always restart: always @@ -28,7 +28,7 @@ services: zammad-nginx: depends_on: - zammad-railsserver - image: zammad/zammad-docker-compose:zammad-nginx${VERSION} + image: monotek/zammad-docker-compose:zammad-nginx${VERSION} labels: io.rancher.container.pull_image: always links: @@ -39,7 +39,7 @@ services: - data-zammad:/home/zammad zammad-postgresql: - image: zammad/zammad-docker-compose:zammad-postgresql${VERSION} + image: monotek/zammad-docker-compose:zammad-postgresql${VERSION} labels: io.rancher.container.pull_image: always restart: always @@ -47,7 +47,7 @@ services: zammad-railsserver: depends_on: - zammad-postgresql - image: zammad/zammad-docker-compose:zammad${VERSION} + image: monotek/zammad-docker-compose:zammad${VERSION} labels: io.rancher.container.pull_image: always links: @@ -61,7 +61,7 @@ services: zammad-scheduler: depends_on: - zammad-railsserver - image: zammad/zammad-docker-compose:zammad${VERSION} + image: monotek/zammad-docker-compose:zammad${VERSION} labels: io.rancher.container.pull_image: always links: @@ -75,7 +75,7 @@ services: zammad-websocket: depends_on: - zammad-railsserver - image: zammad/zammad-docker-compose:zammad${VERSION} + image: monotek/zammad-docker-compose:zammad${VERSION} labels: io.rancher.container.pull_image: always links: diff --git a/hooks/config b/hooks/config index 34af82b..87fe385 100644 --- a/hooks/config +++ b/hooks/config @@ -3,4 +3,4 @@ # build hooks config # -DOCKER_IMAGES="zammad zammad-elasticsearch zammad-nginx zammad-postgresql" +DOCKER_IMAGES="zammad zammad-elasticsearch zammad-nfs zammad-nginx zammad-postgresql" diff --git a/kubernetes/10_pvc.yaml b/kubernetes/10_pvc.yaml index 47ea77a..46b98c3 100644 --- a/kubernetes/10_pvc.yaml +++ b/kubernetes/10_pvc.yaml @@ -40,3 +40,4 @@ spec: resources: requests: storage: 10G + diff --git a/kubernetes/50_statefulset_postgesql.yaml b/kubernetes/50_statefulset_postgesql.yaml index 8fea411..37d505b 100644 --- a/kubernetes/50_statefulset_postgesql.yaml +++ b/kubernetes/50_statefulset_postgesql.yaml @@ -22,11 +22,11 @@ spec: claimName: zammad-postgresql containers: - name: zammad-postgresql - image: zammad/zammad-docker-compose:zammad-postgresql + image: monotek/zammad-docker-compose:zammad-postgresql ports: - containerPort: 5432 name: postgresql imagePullPolicy: Always volumeMounts: - mountPath: /var/lib/postgresql - name: zammad-postgresql \ No newline at end of file + name: zammad-postgresql diff --git a/kubernetes/51_statefulset_elasticsearch.yaml b/kubernetes/51_statefulset_elasticsearch.yaml index d6e5f4b..6e8493a 100644 --- a/kubernetes/51_statefulset_elasticsearch.yaml +++ b/kubernetes/51_statefulset_elasticsearch.yaml @@ -25,10 +25,10 @@ spec: image: busybox command: ["sysctl", "-w", "vm.max_map_count=262144"] securityContext: - privileged: true + privileged: true containers: - name: zammad-elasticsearch - image: zammad/zammad-docker-compose:zammad-elasticsearch + image: monotek/zammad-docker-compose:zammad-elasticsearch ports: - containerPort: 9200 name: elasticsearch diff --git a/kubernetes/52_statefulset_railsserver.yaml b/kubernetes/52_statefulset_railsserver.yaml index 49ac67e..2c68802 100644 --- a/kubernetes/52_statefulset_railsserver.yaml +++ b/kubernetes/52_statefulset_railsserver.yaml @@ -22,12 +22,14 @@ spec: claimName: zammad-home containers: - name: zammad-railsserver - image: zammad/zammad-docker-compose:zammad-railsserver + image: monotek/zammad-docker-compose:zammad imagePullPolicy: Always args: ["zammad-railsserver"] ports: - containerPort: 3000 name: railsserver + securityContext: + privileged: true volumeMounts: - mountPath: /home/zammad - name: zammad-home \ No newline at end of file + name: zammad-home diff --git a/kubernetes/53_statefulset_websocket.yaml b/kubernetes/53_statefulset_websocket.yaml index 9651843..2a1ced3 100644 --- a/kubernetes/53_statefulset_websocket.yaml +++ b/kubernetes/53_statefulset_websocket.yaml @@ -22,12 +22,14 @@ spec: claimName: zammad-home containers: - name: zammad-websocket - image: zammad/zammad-docker-compose:zammad + image: monotek/zammad-docker-compose:zammad args: [ "zammad-websocket" ] ports: - containerPort: 6042 name: websocket imagePullPolicy: Always + securityContext: + privileged: true volumeMounts: - mountPath: /home/zammad - name: zammad-home \ No newline at end of file + name: zammad-home diff --git a/kubernetes/54_statefulset_nginx.yaml b/kubernetes/54_statefulset_nginx.yaml index eb6aa98..651af47 100644 --- a/kubernetes/54_statefulset_nginx.yaml +++ b/kubernetes/54_statefulset_nginx.yaml @@ -22,7 +22,7 @@ spec: claimName: zammad-home containers: - name: zammad-nginx - image: zammad/zammad-docker-compose:zammad-nginx + image: monotek/zammad-docker-compose:zammad-nginx ports: - containerPort: 80 name: nginx @@ -31,4 +31,4 @@ spec: imagePullPolicy: Always volumeMounts: - mountPath: /home/zammad - name: zammad-home \ No newline at end of file + name: zammad-home diff --git a/kubernetes/55_statefulset_scheduler.yaml b/kubernetes/55_statefulset_scheduler.yaml index d7f2f54..49ed77c 100644 --- a/kubernetes/55_statefulset_scheduler.yaml +++ b/kubernetes/55_statefulset_scheduler.yaml @@ -19,12 +19,14 @@ spec: volumes: - name: zammad-home persistentVolumeClaim: - claimName: zammad-home + claimName: zammad-home containers: - name: zammad-scheduler - image: zammad/zammad-docker-compose:zammad + image: monotek/zammad-docker-compose:zammad args: [ "zammad-scheduler" ] imagePullPolicy: Always + securityContext: + privileged: true volumeMounts: - mountPath: /home/zammad - name: zammad-home \ No newline at end of file + name: zammad-home diff --git a/kubernetes/56_statefulset_nfs.yaml b/kubernetes/56_statefulset_nfs.yaml new file mode 100644 index 0000000..a9e8ac6 --- /dev/null +++ b/kubernetes/56_statefulset_nfs.yaml @@ -0,0 +1,30 @@ +apiVersion: apps/v1beta1 +kind: StatefulSet +metadata: + name: zammad-nfs + namespace: zammad + labels: + component: netfs + app: zammad +spec: + serviceName: zammad-nfs + replicas: 1 + template: + metadata: + labels: + component: netfs + app: nfs + spec: + terminationGracePeriodSeconds: 10 + containers: + - name: zammad-nfs + image: monotek/zammad-docker-compose:zammad-nfs + args: [ "zammad-nfs" ] + imagePullPolicy: Always + ports: + - containerPort: 2049 + name: nfsserver + - containerPort: 111 + name: rpc + securityContext: + privileged: true diff --git a/kubernetes/80_sv.yaml b/kubernetes/80_sv.yaml index c171f66..b592e1e 100644 --- a/kubernetes/80_sv.yaml +++ b/kubernetes/80_sv.yaml @@ -82,4 +82,23 @@ spec: selector: component: nginx app: zammad - type: NodePort \ No newline at end of file + type: NodePort +--- +kind: Service +apiVersion: v1 +metadata: + name: zammad-nfs + namespace: zammad + labels: + component: netfs + app: nfs +spec: + ports: + - name: nfsserver + port: 2049 + - name: rpc + port: 111 + selector: + component: netfs + app: nfs + type: NodePort