From ce696bad8b4688834cf87bf0b878583da967e38e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bauer?= Date: Sun, 26 Nov 2017 21:25:57 +0100 Subject: [PATCH] added init container (installation / update)... (#2) - added memcached container (currently develop branch needed) - put all zammad services in one kubernetes pod to be able to use empty dir volume for tmp - switched to kubernetes deployments - switched to ReadWriteOnce kubernetes volume claims - added init container to elasticsearch & zammad kubernetes deployments - added IMAGE_REPO var for docker compose to .env file - run nginx from zammad container (preparation for stateless updates) - removed docker-compose-build.yml - use private docker repos in compose & kubernetes - change compose volume names --- .env | 3 +- containers/zammad-memcached/Dockerfile | 2 + .../zammad-memcached/docker-entrypoint.sh | 4 +- containers/zammad-nfs/Dockerfile | 4 +- containers/zammad-nfs/docker-entrypoint.sh | 11 +- containers/zammad-postgresql/Dockerfile | 2 +- containers/zammad-postgresql/backup.sh | 5 +- containers/zammad/Dockerfile | 8 +- containers/zammad/docker-entrypoint.sh | 113 ++++++++++++------ docker-compose-build.yml | 93 -------------- docker-compose.yml | 72 +++++++---- kubernetes/10_pvc.yaml | 22 ++-- kubernetes/40_deployment_zammad.yaml | 87 ++++++++++++++ kubernetes/41_deployment_nginx.yaml | 33 +++++ kubernetes/42_deployment_memcached.yaml | 23 ++++ ...esql.yaml => 43_deployment_postgesql.yaml} | 17 ++- ....yaml => 44_deployment_elasticsearch.yaml} | 18 ++- kubernetes/45_deployment_nfs.yaml | 33 +++++ kubernetes/52_statefulset_railsserver.yaml | 35 ------ kubernetes/53_statefulset_websocket.yaml | 35 ------ kubernetes/54_statefulset_nginx.yaml | 34 ------ kubernetes/55_statefulset_scheduler.yaml | 32 ----- kubernetes/56_statefulset_nfs.yaml | 30 ----- kubernetes/{80_sv.yaml => 80_svc.yaml} | 111 +++++++++-------- kubernetes/90_ingress.yaml | 4 +- kubernetes/Readme.md | 34 +++++- rancher-compose.yml | 8 ++ 27 files changed, 453 insertions(+), 420 deletions(-) delete mode 100644 docker-compose-build.yml create mode 100644 kubernetes/40_deployment_zammad.yaml create mode 100644 kubernetes/41_deployment_nginx.yaml create mode 100644 kubernetes/42_deployment_memcached.yaml rename kubernetes/{50_statefulset_postgesql.yaml => 43_deployment_postgesql.yaml} (61%) rename kubernetes/{51_statefulset_elasticsearch.yaml => 44_deployment_elasticsearch.yaml} (67%) create mode 100644 kubernetes/45_deployment_nfs.yaml delete mode 100644 kubernetes/52_statefulset_railsserver.yaml delete mode 100644 kubernetes/53_statefulset_websocket.yaml delete mode 100644 kubernetes/54_statefulset_nginx.yaml delete mode 100644 kubernetes/55_statefulset_scheduler.yaml delete mode 100644 kubernetes/56_statefulset_nfs.yaml rename kubernetes/{80_sv.yaml => 80_svc.yaml} (78%) diff --git a/.env b/.env index 81d188a..0af8aac 100644 --- a/.env +++ b/.env @@ -1,3 +1,4 @@ # don't forget to add the minus before the version -# it should look like: VERSION=-2.1.0-13 +# example: VERSION=-2.1.0-13 +IMAGE_REPO=monotek/zammad-docker-compose VERSION= diff --git a/containers/zammad-memcached/Dockerfile b/containers/zammad-memcached/Dockerfile index 32cee68..bc1ecd4 100644 --- a/containers/zammad-memcached/Dockerfile +++ b/containers/zammad-memcached/Dockerfile @@ -15,7 +15,9 @@ LABEL org.label-schema.build-date="$BUILD_DATE" \ org.label-schema.docker.cmd="sysctl -w vm.max_map_count=262144;docker-compose up" # docker init +USER root COPY containers/zammad-memcached/docker-entrypoint.sh / RUN chmod +x /docker-entrypoint.sh +USER memcache ENTRYPOINT ["/docker-entrypoint.sh"] CMD ["zammad-memcached"] diff --git a/containers/zammad-memcached/docker-entrypoint.sh b/containers/zammad-memcached/docker-entrypoint.sh index cb1780a..699588c 100644 --- a/containers/zammad-memcached/docker-entrypoint.sh +++ b/containers/zammad-memcached/docker-entrypoint.sh @@ -1,7 +1,9 @@ -#!/bin/bash +#!/bin/sh set -e if [ "$1" = 'zammad-memcached' ]; then + echo "starting memcached..." + exec memcached -m ${MEMCACHED_SIZE} fi diff --git a/containers/zammad-nfs/Dockerfile b/containers/zammad-nfs/Dockerfile index 591585a..fe52046 100644 --- a/containers/zammad-nfs/Dockerfile +++ b/containers/zammad-nfs/Dockerfile @@ -1,8 +1,8 @@ FROM cpuguy83/nfs-server MAINTAINER Zanmmad -ENV NFS_DIR /mnt/zammad -ENV TMPFS_SIZE 1G +ENV NFS_DIR /exports +ENV TMPFS_SIZE 256M LABEL org.label-schema.build-date="$BUILD_DATE" \ org.label-schema.name="Zammad" \ diff --git a/containers/zammad-nfs/docker-entrypoint.sh b/containers/zammad-nfs/docker-entrypoint.sh index b85e1bb..0ff8383 100644 --- a/containers/zammad-nfs/docker-entrypoint.sh +++ b/containers/zammad-nfs/docker-entrypoint.sh @@ -3,14 +3,17 @@ set -e 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 "creating nfs dir" + + test -d ${NFS_DIR}/data || mkdir -p ${NFS_DIR}/data + test -d ${NFS_DIR}/uploads || mkdir -p ${NFS_DIR}/uploads + chmod -R 777 ${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 + echo "${NFS_DIR}/data *(rw,sync,no_subtree_check,no_root_squash)" >> /etc/exports + echo "${NFS_DIR}/uploads *(rw,sync,no_subtree_check,no_root_squash)" >> /etc/exports exec runsvdir /etc/sv fi diff --git a/containers/zammad-postgresql/Dockerfile b/containers/zammad-postgresql/Dockerfile index 2b3e3c3..6a364c0 100644 --- a/containers/zammad-postgresql/Dockerfile +++ b/containers/zammad-postgresql/Dockerfile @@ -4,7 +4,7 @@ ARG BUILD_DATE ENV BACKUP_SLEEP 86400 ENV HOLD_DAYS 10 -ENV ZAMMAD_DIR /home/zammad +ENV ZAMMAD_DIR /opt/zammad ENV BACKUP_DIR /var/tmp/zammad LABEL org.label-schema.build-date="$BUILD_DATE" \ diff --git a/containers/zammad-postgresql/backup.sh b/containers/zammad-postgresql/backup.sh index 280d38b..3db010e 100644 --- a/containers/zammad-postgresql/backup.sh +++ b/containers/zammad-postgresql/backup.sh @@ -3,10 +3,9 @@ set -e 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 + echo "waiting for railsserver to be ready..." + sleep 60 done } diff --git a/containers/zammad/Dockerfile b/containers/zammad/Dockerfile index 22e6a7f..c72a887 100644 --- a/containers/zammad/Dockerfile +++ b/containers/zammad/Dockerfile @@ -2,14 +2,15 @@ FROM ruby:2.4.1-slim MAINTAINER Zammad ARG BUILD_DATE -ENV ZAMMAD_DIR /home/zammad +ENV ZAMMAD_DIR /opt/zammad ENV ZAMMAD_TMP_DIR /tmp/zammad ENV ZAMMAD_USER zammad ENV RAILS_ENV production ENV RAILS_SERVER puma ENV GIT_URL https://github.com/zammad/zammad.git -ENV GIT_BRANCH stable +ENV GIT_BRANCH develop ENV GOSU_VERSION 1.10 +ENV ZAMMAD_READY_FILE tmp/zammad.ready LABEL org.label-schema.build-date="$BUILD_DATE" \ org.label-schema.name="Zammad" \ @@ -23,7 +24,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 nfs-common rsync" \ +RUN BUILD_DEPENDENCIES="git build-essential libffi-dev libpq5 libpq-dev nfs-common nginx 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/* \ @@ -45,6 +46,7 @@ RUN BUILD_DEPENDENCIES="git build-essential libffi-dev libpq5 libpq-dev nfs-comm && bundle exec rake assets:precompile \ && sed -e 's#.*adapter: postgresql# adapter: postgresql#g' -e 's#.*username:.*# username: postgres#g' -e 's#.*password:.*# password: \n host: zammad-postgresql\n#g' < config/database.yml.pkgr > config/database.yml \ && rm -r tmp/cache \ + && sed -e 's#server localhost:3000#server zammad-railsserver:3000#g' -e 's#localhost:6042#zammad-websocket:6042#g' -e 's#server_name localhost#server_name _#g' -e 's#.*\(access\|error\)_log.*log;##g' < contrib/nginx/zammad.conf > /etc/nginx/sites-enabled/default \ && chown -R ${ZAMMAD_USER}:${ZAMMAD_USER} ${ZAMMAD_TMP_DIR} # docker init diff --git a/containers/zammad/docker-entrypoint.sh b/containers/zammad/docker-entrypoint.sh index 4ebb25a..28b93a5 100644 --- a/containers/zammad/docker-entrypoint.sh +++ b/containers/zammad/docker-entrypoint.sh @@ -2,38 +2,40 @@ set -e -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 +function check_zammad_ready { + until [ -f "${ZAMMAD_DIR}/${ZAMMAD_READY_FILE}" ]; do + echo "waiting for install or update to be ready..." + sleep 5 done } function mount_nfs { if [ -n "$(env|grep KUBERNETES)" ]; then - mount -t nfs4 zammad-nfs:/ /home/zammad/tmp + test -d ${ZAMMAD_DIR} || mkdir -p ${ZAMMAD_DIR} + mount -t nfs4 zammad-nfs:/data /opt/zammad + chown ${ZAMMAD_USER}:${ZAMMAD_USER} ${ZAMMAD_DIR} fi } -# zammad-railsserver -if [ "$1" = 'zammad-railsserver' ]; then - - # wait for postgres process coming up on zammad-postgresql +# zammad init +if [ "$1" = 'zammad-init' ]; then until (echo > /dev/tcp/zammad-postgresql/5432) &> /dev/null; do echo "zammad railsserver waiting for postgresql server to be ready..." sleep 5 done - echo "railsserver can access postgresql server now..." - - rsync -a --delete --exclude 'storage/fs/*' ${ZAMMAD_TMP_DIR}/ ${ZAMMAD_DIR} - cd ${ZAMMAD_DIR} - gem update bundler - bundle install - mount_nfs + # install / update zammad + rsync -a --delete --exclude 'storage/fs/*' --exclude 'public/assets/images/*' ${ZAMMAD_TMP_DIR}/ ${ZAMMAD_DIR} + rsync -a ${ZAMMAD_TMP_DIR}/public/assets/images/ ${ZAMMAD_DIR}/public/assets/images + + cd ${ZAMMAD_DIR} + + # enable memcached + sed -i -e "s/.*config.cache_store.*file_store.*cache_file_store.*/ config.cache_store = :dalli_store, 'zammad-memcached:11211'\n config.session_store = :dalli_store, 'zammad-memcached:11211'/" config/application.rb + + echo "initialising / updating database..." # db mirgrate set +e bundle exec rake db:migrate &> /dev/null @@ -41,52 +43,95 @@ if [ "$1" = 'zammad-railsserver' ]; then set -e if [ "${DB_CHECK}" != "0" ]; then - echo "creating db & searchindex..." bundle exec rake db:create bundle exec rake db:migrate bundle exec rake db:seed fi + echo "changing settings..." # es config bundle exec rails r "Setting.set('es_url', 'http://zammad-elasticsearch:9200')" + + until (echo > /dev/tcp/zammad-elasticsearch/9200) &> /dev/null; do + echo "zammad railsserver waiting for elasticsearch server to be ready..." + sleep 5 + done + + echo "rebuilding es searchindex..." bundle exec rake searchindex:rebuild + # chown everything to zammad user chown -R ${ZAMMAD_USER}:${ZAMMAD_USER} ${ZAMMAD_DIR} - # run zammad - echo "starting zammad..." - echo "zammad will be accessable on http://localhost in some seconds" + # create install ready file + su -c "echo 'zammad-init' > ${ZAMMAD_DIR}/${ZAMMAD_READY_FILE}" ${ZAMMAD_USER} +fi - if [ "${RAILS_SERVER}" == "puma" ]; then - exec gosu ${ZAMMAD_USER}:${ZAMMAD_USER} bundle exec puma -b tcp://0.0.0.0:3000 -e ${RAILS_ENV} - elif [ "${RAILS_SERVER}" == "unicorn" ]; then - exec gosu ${ZAMMAD_USER}:${ZAMMAD_USER} bundle exec unicorn -p 3000 -c config/unicorn.rb -E ${RAILS_ENV} + +# zammad nginx +if [ "$1" = 'zammad-nginx' ]; then + mount_nfs + + if [ -n "$(env|grep KUBERNETES)" ]; then + sed -i -e 's#server zammad-\(railsserver\|websocket\):#server zammad:#g' /etc/nginx/sites-enabled/default fi + + until [ -f "${ZAMMAD_DIR}/${ZAMMAD_READY_FILE}" ] && [ -n "$(grep zammad-railsserver < ${ZAMMAD_DIR}/${ZAMMAD_READY_FILE})" ] && [ -n "$(grep zammad-scheduler < ${ZAMMAD_DIR}/${ZAMMAD_READY_FILE})" ] && [ -n "$(grep zammad-websocket < ${ZAMMAD_DIR}/${ZAMMAD_READY_FILE})" ] ; do + echo "waiting for all zammad services to start..." + sleep 5 + done + + rm ${ZAMMAD_DIR}/${ZAMMAD_READY_FILE} + + echo "starting nginx..." + + exec /usr/sbin/nginx -g 'daemon off;' +fi + + +# zammad-railsserver +if [ "$1" = 'zammad-railsserver' ]; then + mount_nfs + + check_zammad_ready + + cd ${ZAMMAD_DIR} + + echo "starting railsserver..." + + echo "zammad-railsserver" >> ${ZAMMAD_DIR}/${ZAMMAD_READY_FILE} + + exec gosu ${ZAMMAD_USER}:${ZAMMAD_USER} bundle exec puma -b tcp://0.0.0.0:3000 -e ${RAILS_ENV} fi # zammad-scheduler if [ "$1" = 'zammad-scheduler' ]; then - check_railsserver_available - - echo "scheduler can access raillsserver now..." - mount_nfs - # start scheduler + check_zammad_ready + cd ${ZAMMAD_DIR} + + echo "starting scheduler..." + + echo "zammad-scheduler" >> ${ZAMMAD_DIR}/${ZAMMAD_READY_FILE} + exec gosu ${ZAMMAD_USER}:${ZAMMAD_USER} bundle exec script/scheduler.rb run fi # zammad-websocket if [ "$1" = 'zammad-websocket' ]; then - check_railsserver_available - - echo "websocket server can access raillsserver now..." - mount_nfs + check_zammad_ready + cd ${ZAMMAD_DIR} + + echo "starting websocket server..." + + echo "zammad-websocket" >> ${ZAMMAD_DIR}/${ZAMMAD_READY_FILE} + exec gosu ${ZAMMAD_USER}:${ZAMMAD_USER} bundle exec script/websocket-server.rb -b 0.0.0.0 start fi diff --git a/docker-compose-build.yml b/docker-compose-build.yml deleted file mode 100644 index 7e1751a..0000000 --- a/docker-compose-build.yml +++ /dev/null @@ -1,93 +0,0 @@ -version: '3.3' - -services: - - zammad-backup: - build: - context: . - dockerfile: containers/zammad-postgresql/Dockerfile - depends_on: - - zammad-railsserver - links: - - zammad-postgresql - restart: always - volumes: - - data-zammad:/home/zammad - - backup-zammad:/var/tmp/zammad - entrypoint: /usr/local/bin/backup.sh - command: ["zammad-backup"] - - zammad-elasticsearch: - build: - context: . - dockerfile: containers/zammad-elasticsearch/Dockerfile - restart: always - - zammad-nginx: - build: - context: . - dockerfile: containers/zammad-nginx/Dockerfile - depends_on: - - zammad-railsserver - links: - - zammad-railsserver - - zammad-websocket - ports: - - "80:80" - restart: always - volumes: - - data-zammad:/home/zammad - - zammad-postgresql: - build: - context: . - dockerfile: containers/zammad-postgresql/Dockerfile - restart: always - - zammad-railsserver: - build: - context: . - dockerfile: containers/zammad/Dockerfile - depends_on: - - zammad-postgresql - links: - - zammad-elasticsearch - - zammad-postgresql - restart: always - volumes: - - data-zammad:/home/zammad - command: ["zammad-railsserver"] - - zammad-scheduler: - build: - context: . - dockerfile: containers/zammad/Dockerfile - depends_on: - - zammad-railsserver - links: - - zammad-elasticsearch - - zammad-postgresql - restart: always - volumes: - - data-zammad:/home/zammad - command: ["zammad-scheduler"] - - zammad-websocket: - build: - context: . - dockerfile: containers/zammad/Dockerfile - depends_on: - - zammad-railsserver - links: - - zammad-elasticsearch - - zammad-postgresql - restart: always - volumes: - - data-zammad:/home/zammad - command: ["zammad-websocket"] - -volumes: - backup-zammad: - driver: local - data-zammad: - driver: local diff --git a/docker-compose.yml b/docker-compose.yml index 20911e0..9dccbfb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,32 +3,54 @@ version: '3.3' services: zammad-backup: + command: ["zammad-backup"] depends_on: - zammad-railsserver - image: zammad/zammad-docker-compose:zammad-postgresql${VERSION} + entrypoint: /usr/local/bin/backup.sh + image: ${IMAGE_REPO}:zammad-postgresql${VERSION} labels: io.rancher.container.pull_image: always links: - zammad-postgresql restart: always volumes: - - data-zammad:/home/zammad - - backup-zammad:/var/tmp/zammad - entrypoint: /usr/local/bin/backup.sh - command: zammad-backup + - zammad-backup:/var/tmp/zammad + - zammad-data:/opt/zammad zammad-elasticsearch: - image: zammad/zammad-docker-compose:zammad-elasticsearch${VERSION} + image: ${IMAGE_REPO}:zammad-elasticsearch${VERSION} labels: io.rancher.container.pull_image: always restart: always volumes: - - data-elasticsearch:/usr/share/elasticsearch/data + - elasticsearch-data:/usr/share/elasticsearch/data + + zammad-init: + command: ["zammad-init"] + depends_on: + - zammad-postgresql + image: ${IMAGE_REPO}:zammad${VERSION} + labels: + io.rancher.container.pull_image: always + links: + - zammad-elasticsearch + - zammad-postgresql + restart: on-failure + volumes: + - zammad-data:/opt/zammad + + zammad-memcached: + command: ["zammad-memcached"] + image: ${IMAGE_REPO}:zammad-memcached${VERSION} + labels: + io.rancher.container.pull_image: always + restart: always zammad-nginx: + command: ["zammad-nginx"] depends_on: - zammad-railsserver - image: zammad/zammad-docker-compose:zammad-nginx${VERSION} + image: ${IMAGE_REPO}:zammad${VERSION} labels: io.rancher.container.pull_image: always links: @@ -36,59 +58,65 @@ services: - zammad-websocket restart: always volumes: - - data-zammad:/home/zammad + - zammad-data:/opt/zammad zammad-postgresql: - image: zammad/zammad-docker-compose:zammad-postgresql${VERSION} + image: ${IMAGE_REPO}:zammad-postgresql${VERSION} labels: io.rancher.container.pull_image: always restart: always zammad-railsserver: + command: ["zammad-railsserver"] depends_on: + - zammad-memcached - zammad-postgresql - image: zammad/zammad-docker-compose:zammad${VERSION} + image: ${IMAGE_REPO}:zammad${VERSION} labels: io.rancher.container.pull_image: always links: - zammad-elasticsearch + - zammad-memcached - zammad-postgresql restart: always volumes: - - data-zammad:/home/zammad - command: ["zammad-railsserver"] + - zammad-data:/opt/zammad zammad-scheduler: + command: ["zammad-scheduler"] depends_on: + - zammad-memcached - zammad-railsserver - image: zammad/zammad-docker-compose:zammad${VERSION} + image: ${IMAGE_REPO}:zammad${VERSION} labels: io.rancher.container.pull_image: always links: - zammad-elasticsearch + - zammad-memcached - zammad-postgresql restart: always volumes: - - data-zammad:/home/zammad - command: ["zammad-scheduler"] + - zammad-data:/opt/zammad zammad-websocket: + command: ["zammad-websocket"] depends_on: + - zammad-memcached - zammad-railsserver - image: zammad/zammad-docker-compose:zammad${VERSION} + image: ${IMAGE_REPO}:zammad${VERSION} labels: io.rancher.container.pull_image: always links: - zammad-postgresql + - zammad-memcached restart: always volumes: - - data-zammad:/home/zammad - command: ["zammad-websocket"] + - zammad-data:/opt/zammad volumes: - backup-zammad: + elasticsearch-data: driver: local - data-zammad: + zammad-backup: driver: local - data-elasticsearch: + zammad-data: driver: local diff --git a/kubernetes/10_pvc.yaml b/kubernetes/10_pvc.yaml index 46b98c3..9f849f1 100644 --- a/kubernetes/10_pvc.yaml +++ b/kubernetes/10_pvc.yaml @@ -2,42 +2,40 @@ kind: PersistentVolumeClaim apiVersion: v1 metadata: - name: zammad-postgresql + name: zammad namespace: zammad - annotations: - volume.beta.kubernetes.io/storage-class: standard spec: + storageClassName: standard accessModes: - - ReadWriteMany + - ReadWriteOnce resources: requests: storage: 10G + --- kind: PersistentVolumeClaim apiVersion: v1 metadata: name: zammad-elasticsearch namespace: zammad - annotations: - volume.beta.kubernetes.io/storage-class: standard spec: + storageClassName: standard accessModes: - - ReadWriteMany + - ReadWriteOnce resources: requests: storage: 10G + --- kind: PersistentVolumeClaim apiVersion: v1 metadata: - name: zammad-home + name: zammad-postgresql namespace: zammad - annotations: - volume.beta.kubernetes.io/storage-class: standard spec: + storageClassName: standard accessModes: - - ReadWriteMany + - ReadWriteOnce resources: requests: storage: 10G - diff --git a/kubernetes/40_deployment_zammad.yaml b/kubernetes/40_deployment_zammad.yaml new file mode 100644 index 0000000..15e0cf0 --- /dev/null +++ b/kubernetes/40_deployment_zammad.yaml @@ -0,0 +1,87 @@ +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: zammad + namespace: zammad +spec: + replicas: 1 + template: + metadata: + labels: + app: zammad + component: services + spec: + terminationGracePeriodSeconds: 10 + # volumes: + # - name: cache-volume + # emptyDir: {} + # - name: data + # nfs: + # # FIXME: use the nfs service IP instead of 'zammad-nfs' + # server: zammad-nfs + # path: /data + # - name: uploads + # nfs: + # # FIXME: use nfs service IP instead of 'zammad-nfs' + # server: zammad-nfs + # path: /uploads + + initContainers: + - name: zammad-init + image: monotek/zammad-docker-compose:zammad + args: [ "zammad-init" ] + imagePullPolicy: Always + securityContext: + privileged: true + # volumeMounts: + # - name: cache-volume + # mountPath: /opt/zammad/tmp + # - name: data + # mountPath: /opt/zammad/storage + # - name: uploads + # mountPath: /opt/zammad/assets/uploads + + containers: + - name: zammad-scheduler + image: monotek/zammad-docker-compose:zammad + args: [ "zammad-scheduler" ] + imagePullPolicy: Always + securityContext: + privileged: true + # volumeMounts: + # - name: cache-volume + # mountPath: /opt/zammad/tmp + # - name: data + # mountPath: /opt/zammad/storage + + - name: zammad-railsserver + image: monotek/zammad-docker-compose:zammad + args: ["zammad-railsserver"] + imagePullPolicy: Always + ports: + - name: railsserver + containerPort: 3000 + securityContext: + privileged: true + # volumeMounts: + # - name: cache-volume + # mountPath: /opt/zammad/tmp + # - name: data + # mountPath: /opt/zammad/storage + # - name: uploads + # mountPath: /opt/zammad/assets/uploads + + - name: zammad-websocket + image: monotek/zammad-docker-compose:zammad + args: [ "zammad-websocket" ] + imagePullPolicy: Always + ports: + - name: websocket + containerPort: 6042 + securityContext: + privileged: true + # volumeMounts: + # - name: cache-volume + # mountPath: /opt/zammad/tmp + # - name: data + # mountPath: /opt/zammad/storage diff --git a/kubernetes/41_deployment_nginx.yaml b/kubernetes/41_deployment_nginx.yaml new file mode 100644 index 0000000..9bc2f18 --- /dev/null +++ b/kubernetes/41_deployment_nginx.yaml @@ -0,0 +1,33 @@ +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: zammad-nginx + namespace: zammad +spec: + replicas: 1 + template: + metadata: + labels: + app: nginx + component: webserver + spec: + terminationGracePeriodSeconds: 10 +# volumes: +# - name: uploads +# nfs: +# # FIXME: use nfs service IP instead of 'zammad-nfs' +# server: zammad-nfs +# path: /uploads + containers: + - name: zammad-nginx + image: monotek/zammad-docker-compose:zammad + args: [ "zammad-nginx" ] + ports: + - containerPort: 80 + name: nginx + imagePullPolicy: Always + securityContext: + privileged: true +# volumeMounts: +# - name: uploads +# mountPath: /opt/zammad/assets/uploads diff --git a/kubernetes/42_deployment_memcached.yaml b/kubernetes/42_deployment_memcached.yaml new file mode 100644 index 0000000..34261a3 --- /dev/null +++ b/kubernetes/42_deployment_memcached.yaml @@ -0,0 +1,23 @@ +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: zammad-memcached + namespace: zammad +spec: + replicas: 1 + template: + metadata: + labels: + app: memcached + component: cache + spec: + terminationGracePeriodSeconds: 10 + + containers: + - name: zammad-memcached + image: monotek/zammad-docker-compose:zammad-memcached + args: [ "zammad-memcached" ] + ports: + - containerPort: 11211 + name: memcached + imagePullPolicy: Always diff --git a/kubernetes/50_statefulset_postgesql.yaml b/kubernetes/43_deployment_postgesql.yaml similarity index 61% rename from kubernetes/50_statefulset_postgesql.yaml rename to kubernetes/43_deployment_postgesql.yaml index d0a7754..1a6db7d 100644 --- a/kubernetes/50_statefulset_postgesql.yaml +++ b/kubernetes/43_deployment_postgesql.yaml @@ -1,13 +1,9 @@ apiVersion: apps/v1beta1 -kind: StatefulSet +kind: Deployment metadata: name: zammad-postgresql namespace: zammad - labels: - component: database - app: postgresql spec: - serviceName: zammad-postgresql replicas: 1 template: metadata: @@ -20,13 +16,14 @@ spec: - name: zammad-postgresql persistentVolumeClaim: 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 + - name: postgresql + containerPort: 5432 imagePullPolicy: Always volumeMounts: - - mountPath: /var/lib/postgresql - name: zammad-postgresql + - name: zammad-postgresql + mountPath: /var/lib/postgresql diff --git a/kubernetes/51_statefulset_elasticsearch.yaml b/kubernetes/44_deployment_elasticsearch.yaml similarity index 67% rename from kubernetes/51_statefulset_elasticsearch.yaml rename to kubernetes/44_deployment_elasticsearch.yaml index 2c8f1b8..ea26553 100644 --- a/kubernetes/51_statefulset_elasticsearch.yaml +++ b/kubernetes/44_deployment_elasticsearch.yaml @@ -1,13 +1,9 @@ apiVersion: apps/v1beta1 -kind: StatefulSet +kind: Deployment metadata: name: zammad-elasticsearch namespace: zammad - labels: - component: database - app: elasticsearch spec: - serviceName: zammad-elasticsearch replicas: 1 template: metadata: @@ -20,19 +16,21 @@ spec: - name: zammad-elasticsearch persistentVolumeClaim: claimName: zammad-elasticsearch + initContainers: - name: sysctl image: busybox command: ["sysctl", "-w", "vm.max_map_count=262144"] securityContext: 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 + - name: elasticsearch + containerPort: 9200 imagePullPolicy: Always volumeMounts: - - mountPath: /usr/share/elasticsearch/data - name: zammad-elasticsearch + - name: zammad-elasticsearch + mountPath: /usr/share/elasticsearch/data diff --git a/kubernetes/45_deployment_nfs.yaml b/kubernetes/45_deployment_nfs.yaml new file mode 100644 index 0000000..d1914a4 --- /dev/null +++ b/kubernetes/45_deployment_nfs.yaml @@ -0,0 +1,33 @@ +apiVersion: apps/v1beta1 +kind: Deployment +metadata: + name: zammad-nfs + namespace: zammad +spec: + replicas: 1 + template: + metadata: + labels: + component: networkstorage + app: nfs + spec: + terminationGracePeriodSeconds: 10 + volumes: + - name: zammad + persistentVolumeClaim: + claimName: zammad + + containers: + - name: zammad-nfs + image: monotek/zammad-docker-compose:zammad-nfs + imagePullPolicy: Always + ports: + - name: nfsserver + containerPort: 2049 + - name: rpc + containerPort: 111 + securityContext: + privileged: true + volumeMounts: + - name: zammad + mountPath: /exports diff --git a/kubernetes/52_statefulset_railsserver.yaml b/kubernetes/52_statefulset_railsserver.yaml deleted file mode 100644 index c28818b..0000000 --- a/kubernetes/52_statefulset_railsserver.yaml +++ /dev/null @@ -1,35 +0,0 @@ -apiVersion: apps/v1beta1 -kind: StatefulSet -metadata: - name: zammad-railsserver - namespace: zammad - labels: - component: railsserver - app: zammad -spec: - serviceName: zammad-railsserver - replicas: 1 - template: - metadata: - labels: - component: railsserver - app: zammad - spec: - terminationGracePeriodSeconds: 10 - volumes: - - name: zammad-home - persistentVolumeClaim: - claimName: zammad-home - containers: - - name: zammad-railsserver - image: zammad/zammad-docker-compose:zammad - imagePullPolicy: Always - args: ["zammad-railsserver"] - ports: - - containerPort: 3000 - name: railsserver - securityContext: - privileged: true - volumeMounts: - - mountPath: /home/zammad - name: zammad-home diff --git a/kubernetes/53_statefulset_websocket.yaml b/kubernetes/53_statefulset_websocket.yaml deleted file mode 100644 index 4508395..0000000 --- a/kubernetes/53_statefulset_websocket.yaml +++ /dev/null @@ -1,35 +0,0 @@ -apiVersion: apps/v1beta1 -kind: StatefulSet -metadata: - name: zammad-websocket - namespace: zammad - labels: - component: websocket - app: zammad -spec: - serviceName: zammad-websocket - replicas: 1 - template: - metadata: - labels: - component: websocket - app: zammad - spec: - terminationGracePeriodSeconds: 10 - volumes: - - name: zammad-home - persistentVolumeClaim: - claimName: zammad-home - containers: - - name: zammad-websocket - image: zammad/zammad-docker-compose:zammad - args: [ "zammad-websocket" ] - ports: - - containerPort: 6042 - name: websocket - imagePullPolicy: Always - securityContext: - privileged: true - volumeMounts: - - mountPath: /home/zammad - name: zammad-home diff --git a/kubernetes/54_statefulset_nginx.yaml b/kubernetes/54_statefulset_nginx.yaml deleted file mode 100644 index cc0e593..0000000 --- a/kubernetes/54_statefulset_nginx.yaml +++ /dev/null @@ -1,34 +0,0 @@ -apiVersion: apps/v1beta1 -kind: StatefulSet -metadata: - name: zammad-nginx - namespace: zammad - labels: - component: nginx - app: zammad -spec: - serviceName: zammad-nginx - replicas: 1 - template: - metadata: - labels: - component: nginx - app: zammad - spec: - terminationGracePeriodSeconds: 10 - volumes: - - name: zammad-home - persistentVolumeClaim: - claimName: zammad-home - containers: - - name: zammad-nginx - image: zammad/zammad-docker-compose:zammad-nginx - ports: - - containerPort: 80 - name: nginx - - containerPort: 6042 - name: nginx-ws - imagePullPolicy: Always - volumeMounts: - - mountPath: /home/zammad - name: zammad-home diff --git a/kubernetes/55_statefulset_scheduler.yaml b/kubernetes/55_statefulset_scheduler.yaml deleted file mode 100644 index 8ddbac5..0000000 --- a/kubernetes/55_statefulset_scheduler.yaml +++ /dev/null @@ -1,32 +0,0 @@ -apiVersion: apps/v1beta1 -kind: StatefulSet -metadata: - name: zammad-scheduler - namespace: zammad - labels: - component: scheduler - app: zammad -spec: - serviceName: zammad-scheduler - replicas: 1 - template: - metadata: - labels: - component: scheduler - app: zammad - spec: - terminationGracePeriodSeconds: 10 - volumes: - - name: zammad-home - persistentVolumeClaim: - claimName: zammad-home - containers: - - name: zammad-scheduler - image: zammad/zammad-docker-compose:zammad - args: [ "zammad-scheduler" ] - imagePullPolicy: Always - securityContext: - privileged: true - volumeMounts: - - mountPath: /home/zammad - name: zammad-home diff --git a/kubernetes/56_statefulset_nfs.yaml b/kubernetes/56_statefulset_nfs.yaml deleted file mode 100644 index 48bf06b..0000000 --- a/kubernetes/56_statefulset_nfs.yaml +++ /dev/null @@ -1,30 +0,0 @@ -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: zammad/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_svc.yaml similarity index 78% rename from kubernetes/80_sv.yaml rename to kubernetes/80_svc.yaml index b592e1e..ad952b1 100644 --- a/kubernetes/80_sv.yaml +++ b/kubernetes/80_svc.yaml @@ -2,19 +2,22 @@ kind: Service apiVersion: v1 metadata: - name: zammad-postgresql + name: zammad namespace: zammad labels: - component: database - app: postgresql + app: zammad + component: services spec: ports: - - name: postgresql - port: 5432 + - name: railsserver + port: 3000 + - name: websocket + port: 6042 selector: - component: database - app: postgresql + app: zammad + component: services type: NodePort + --- kind: Service apiVersion: v1 @@ -22,67 +25,35 @@ metadata: name: zammad-elasticsearch namespace: zammad labels: - component: searchindex app: elasticsearch + component: searchindex spec: ports: - name: elasticsearch port: 9200 selector: - component: searchindex app: elasticsearch + component: searchindex type: NodePort + --- kind: Service apiVersion: v1 metadata: - name: zammad-railsserver + name: zammad-memcached namespace: zammad labels: - component: railsserver - app: zammad + app: memcached + component: cache spec: ports: - - name: railsserver - port: 3000 + - name: memcached + port: 11211 selector: - component: railsserver - app: zammad - type: NodePort ---- -kind: Service -apiVersion: v1 -metadata: - name: zammad-websocket - namespace: zammad - labels: - component: websocket - app: zammad -spec: - ports: - - name: websocket - port: 6042 - selector: - component: websocket - app: zammad - type: NodePort ---- -kind: Service -apiVersion: v1 -metadata: - name: zammad-nginx - namespace: zammad - labels: - component: nginx - app: zammad -spec: - ports: - - name: nginx - port: 80 - selector: - component: nginx - app: zammad + app: memcached + component: cache type: NodePort + --- kind: Service apiVersion: v1 @@ -90,8 +61,8 @@ metadata: name: zammad-nfs namespace: zammad labels: - component: netfs app: nfs + component: networkstorage spec: ports: - name: nfsserver @@ -99,6 +70,42 @@ spec: - name: rpc port: 111 selector: - component: netfs app: nfs + component: networkstorage + type: NodePort + +--- +kind: Service +apiVersion: v1 +metadata: + name: zammad-nginx + namespace: zammad + labels: + app: nginx + component: webserver +spec: + ports: + - name: nginx + port: 80 + selector: + app: nginx + component: webserver + type: NodePort + +--- +kind: Service +apiVersion: v1 +metadata: + name: zammad-postgresql + namespace: zammad + labels: + app: postgresql + component: database +spec: + ports: + - name: postgresql + port: 5432 + selector: + app: postgresql + component: database type: NodePort diff --git a/kubernetes/90_ingress.yaml b/kubernetes/90_ingress.yaml index 4a1056d..1c055f9 100644 --- a/kubernetes/90_ingress.yaml +++ b/kubernetes/90_ingress.yaml @@ -4,7 +4,7 @@ metadata: name: zammad.example.com namespace: zammad labels: - component: website + component: webserver app: zammad host: zammad.example.com annotations: @@ -23,4 +23,4 @@ spec: - path: / backend: serviceName: zammad-nginx - servicePort: 80 \ No newline at end of file + servicePort: 80 diff --git a/kubernetes/Readme.md b/kubernetes/Readme.md index 171ca5b..33d4ba4 100644 --- a/kubernetes/Readme.md +++ b/kubernetes/Readme.md @@ -1,13 +1,16 @@ -# Zammad kubernetes example deployment (beta) +# Zammad kubernetes example deployment + +This is a proof of concept of a Kubernetes deployment, which should be considered +beta and not ready for production. ## Prerequisites -- Change the ingress to your needs. +- Change the ingress to your needs -## Deploy zammad +## Deploy Zammad -### Install on Minikube example +### Install on Minikube * Install kubectl * https://kubernetes.io/docs/tasks/tools/install-kubectl/ @@ -22,3 +25,26 @@ * open "Overview" and wait until all pods are green * access zammad on: * http://zammad.example.com + + +### Install on Google Kubernetes Engine +* connect to cluster via gcloud command +* kubectl apply -f . + + + +## If you want to help to improve the Kuberntes deployments here are some todos: +* fix the nfs mount from entrypoint, which is currently used because of: + * https://github.com/kubernetes/kubernetes/issues/8735 + * otherwise you have to manually: + * kubectl apply -f 00_namespace.yaml -f 80_svc.yaml + * kubectl --namespace=zammad describe services zammad-nfs + * use the NFS server IP to update + * 40_deployment_zammad.yaml + * 41_deployment_nginx.yaml + * kubectl apply -f 10_pvc.yaml -f 40_deployment_zammad.yaml -f 41_deployment_nginx.yaml -f 42_deployment_memcached.yaml -f 43_deployment_postgesql.yaml -f 44_deployment_elasticsearch.yaml -f 45_deployment_nfs.yaml -f 90_ingress.yaml +* create config map for nginx +* create a zammad helm chart +* document steps to use existing helm charts for elasticsearch, postgresql and so on +* add cpu & mem limits +* add rolling upgrade strategy to deployments diff --git a/rancher-compose.yml b/rancher-compose.yml index 9fe5aca..bc49675 100644 --- a/rancher-compose.yml +++ b/rancher-compose.yml @@ -10,6 +10,14 @@ services: scale: 1 start_on_create: true + zammad-init: + scale: 1 + start_on_create: true + + zammad-memcached: + scale: 1 + start_on_create: true + zammad-nginx: scale: 1 start_on_create: true