diff --git a/Nextcloud-db.kube.yaml b/Nextcloud-db.kube.yaml new file mode 100644 index 0000000..7f9654f --- /dev/null +++ b/Nextcloud-db.kube.yaml @@ -0,0 +1,89 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: nextcloud +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: nextcloud-db + namespace: nextcloud +spec: + replicas: 1 + selector: + matchLabels: + app: nextcloud-db + template: + metadata: + labels: + app: nextcloud-db + spec: +# nodeName: kube-master + containers: + - name: db + image: docker.io/library/postgres:14 + imagePullPolicy: IfNotPresent + env: + - name: POSTGRES_DB + valueFrom: + secretKeyRef: + name: nextcloud-credentials + key: POSTGRES_DB + - name: POSTGRES_USER + valueFrom: + secretKeyRef: + name: nextcloud-credentials + key: POSTGRES_USER + - name: POSTGRES_PASSWORD + valueFrom: + secretKeyRef: + name: nextcloud-credentials + key: POSTGRES_PASSWORD + + volumeMounts: +# - name: pgdata +# mountPath: /var/lib/postgresql/data + - name: nextcloud-database-data + mountPath: /var/lib/postgresql/data + ports: + - name: postgres + containerPort: 5432 + volumes: + - name: pgdata + hostPath: + path: /opt/kubernetes/Nextcloud_kube/data/pgdata + + - name: nextcloud-database-data + persistentVolumeClaim: + claimName: nextcloud-database +--- +apiVersion: v1 +kind: Service +metadata: + name: db + namespace: nextcloud +spec: + selector: + app: nextcloud-db + ports: + - protocol: TCP + port: 5432 + targetPort: postgres + + +--- +# if remote access required +#apiVersion: v1 +#kind: Service +#metadata: +# name: db-nodeport +# namespace: nextcloud +#spec: +# type: NodePort +# selector: +# app: nextcloud-db +# ports: +# - protocol: TCP +# port: 5432 +# targetPort: postgres +# nodePort: 32366 diff --git a/Nextcloud-redis.kube.yaml b/Nextcloud-redis.kube.yaml new file mode 100644 index 0000000..da202ac --- /dev/null +++ b/Nextcloud-redis.kube.yaml @@ -0,0 +1,50 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: nextcloud +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: nextcloud-redis + namespace: nextcloud +spec: + replicas: 1 + selector: + matchLabels: + app: nextcloud-redis + template: + metadata: + labels: + app: nextcloud-redis + spec: + containers: + - name: broker + image: docker.io/library/redis:7 + imagePullPolicy: IfNotPresent + volumeMounts: + - name: redisdata + mountPath: /data + ports: + - name: redis + containerPort: 6379 + + volumes: + - name: redisdata + hostPath: + path: /opt/kubernetes/Nextcloud_kube/data/redisdata + +--- +apiVersion: v1 +kind: Service +metadata: + name: redis + namespace: nextcloud +spec: + selector: + app: nextcloud-redis + ports: + - protocol: TCP + port: 6379 + targetPort: redis + diff --git a/Nextcloud-webserver.kube.yaml b/Nextcloud-webserver.kube.yaml new file mode 100644 index 0000000..6109112 --- /dev/null +++ b/Nextcloud-webserver.kube.yaml @@ -0,0 +1,74 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: nextcloud +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: nextcloud-webserver + namespace: nextcloud +spec: + replicas: 1 + selector: + matchLabels: + app: nextcloud-webserver + template: + metadata: + labels: + app: nextcloud-webserver + spec: + nodeName: kube-master + containers: + - name: nextcloud-webserver +# image: nextcloud:apache +# image: nextcloud:28.0.5-apache +# image: nextcloud:28.0.6-apache + image: nextcloud:29.0.1-apache + imagePullPolicy: Always + ports: + - containerPort: 80 + name: webserver-port + env: + #- name: REDIS_HOST + # value: "redis://redis:6379" + - name: POSTGRES_HOST + value: "db" + livenessProbe: + httpGet: + path: / + port: 80 + httpHeaders: + - name: host + value: nextcloud.tryton.geeraert.eu + initialDelaySeconds: 3 + periodSeconds: 3 + + volumeMounts: + - name: nextcloud-webserver + mountPath: /var/www/html + + + volumes: + - name: nextcloud-webserver + persistentVolumeClaim: + claimName: nextcloud-webserver + securityContext: + fsGroup: 33 + +--- +apiVersion: v1 +kind: Service +metadata: + name: webserver + namespace: nextcloud +spec: + ports: + - name: http + port: 80 +# targetPort: webserver-port + protocol: TCP +# nodePort: 31236 +# type: NodePort + selector: + app: nextcloud-webserver diff --git a/docker_compose.yml b/docker_compose.yml new file mode 100644 index 0000000..bad278a --- /dev/null +++ b/docker_compose.yml @@ -0,0 +1,45 @@ +$ cat docker-compose.yml +version: '3' + +services: + db: + image: postgres:alpine + restart: always + volumes: + - db:/var/lib/postgresql/data:Z + env_file: + - db.env + + redis: + image: redis:alpine + restart: always + + app: + image: nextcloud:apache + restart: always + ports: + - 6456:80 + volumes: + - nextcloud:/var/www/html:z + environment: + - POSTGRES_HOST=db + - REDIS_HOST=redis + env_file: + - db.env + depends_on: + - db + - redis + + cron: + image: nextcloud:apache + restart: always + volumes: + - nextcloud:/var/www/html:z + entrypoint: /cron.sh + depends_on: + - db + - redis + +volumes: + db: + nextcloud: diff --git a/nextcloud.secret.yaml b/nextcloud.secret.yaml new file mode 100644 index 0000000..d655f6e --- /dev/null +++ b/nextcloud.secret.yaml @@ -0,0 +1,9 @@ +apiVersion: v1 +data: + POSTGRES_DB: bmV4dGNsb3Vk + POSTGRES_PASSWORD: bmV4dGNsb3Vk + POSTGRES_USER: bmV4dGNsb3Vk +kind: Secret +metadata: + name: nextcloud-credentials + namespace: nextcloud diff --git a/purge_oc_authtoken.CronJob.yaml b/purge_oc_authtoken.CronJob.yaml new file mode 100644 index 0000000..cb3ea76 --- /dev/null +++ b/purge_oc_authtoken.CronJob.yaml @@ -0,0 +1,45 @@ +apiVersion: batch/v1 +kind: CronJob +metadata: + name: purge-oc-authtoken + namespace: nextcloud +spec: + schedule: 0 0 */15 * * + jobTemplate: + spec: + ttlSecondsAfterFinished: 100 + template: + spec: + containers: + - image: alpine + imagePullPolicy: Always + name: purge-oc-authtoken + volumeMounts: + - name: nextcloud-purge-oc-authtoken-log + mountPath: /var/log/nextcloud-nextcloud-purge-oc-authtoken.log + command: [ "/bin/sh", "-c", "--" ] + args: + - apk -q update; apk -q add postgresql;clear;echo $(date) >> /var/log/nextcloud-nextcloud-purge-oc-authtoken.log 2>&1;echo "Number of row before the query" >> /var/log/nextcloud-nextcloud-purge-oc-authtoken.log;PGPASSWORD=$POSTGRES_PASSWORD psql -h db.nextcloud.svc -d $POSTGRES_DB -U $POSTGRES_USER -c "select * from oc_authtoken where uid='pi';" |tail -n 2 >> /var/log/nextcloud-nextcloud-purge-oc-authtoken.log; PGPASSWORD=$POSTGRES_PASSWORD psql -h db.nextcloud.svc -d $POSTGRES_DB -U $POSTGRES_USER -c "delete from oc_authtoken where uid='pi' >> /var/log/nextcloud-nextcloud-purge-oc-authtoken.log;";echo "Number of row after the query" >> /var/log/nextcloud-nextcloud-purge-oc-authtoken.log; PGPASSWORD=$POSTGRES_PASSWORD psql -h db.nextcloud.svc -d $POSTGRES_DB -U $POSTGRES_USER -c "select * from oc_authtoken where uid='pi';"|tail -n 2 >> /var/log/nextcloud-nextcloud-purge-oc-authtoken.log;sleep 3600 + env: + - name: POSTGRES_DB + valueFrom: + secretKeyRef: + name: nextcloud-credentials + key: POSTGRES_DB + - name: POSTGRES_USER + valueFrom: + secretKeyRef: + name: nextcloud-credentials + key: POSTGRES_USER + - name: POSTGRES_PASSWORD + valueFrom: + secretKeyRef: + name: nextcloud-credentials + key: POSTGRES_PASSWORD + restartPolicy: OnFailure + volumes: + - name: nextcloud-purge-oc-authtoken-log + hostPath: + path: /var/log/nextcloud-nextcloud-purge-oc-authtoken.log + type: File + diff --git a/pvc.claim.yaml b/pvc.claim.yaml new file mode 100644 index 0000000..e1b3a0c --- /dev/null +++ b/pvc.claim.yaml @@ -0,0 +1,25 @@ +kind: PersistentVolumeClaim +apiVersion: v1 +metadata: + name: nextcloud-database + namespace: nextcloud +spec: + storageClassName: nfs-storage-intelligent + accessModes: + - ReadWriteMany + resources: + requests: + storage: 2Gi +--- +kind: PersistentVolumeClaim +apiVersion: v1 +metadata: + name: nextcloud-webserver + namespace: nextcloud +spec: + storageClassName: nfs-storage-intelligent + accessModes: + - ReadWriteMany + resources: + requests: + storage: 2Gi