From 8e91aa8936a84597bf394fcf98dbd849f9c27e29 Mon Sep 17 00:00:00 2001 From: Massaki Archambault Date: Sat, 29 Aug 2020 00:54:40 -0400 Subject: [PATCH] setup nfs --- clean-dev-cluster.sh | 7 ++- kustomize/bases/gitea/gitea-deployment.yaml | 40 +++++++++++------ kustomize/bases/gitea/kustomization.yaml | 2 +- kustomize/bases/grafana/kustomization.yaml | 2 +- kustomize/bases/nextcloud/kustomization.yaml | 2 +- .../bases/nextcloud/nextcloud-cronjob.yaml | 6 +-- .../bases/nextcloud/nextcloud-deployment.yaml | 36 ++++++++++++---- .../dev/cert-manager/clusterissuer.yaml | 2 +- kustomize/overlays/dev/kustomization.yaml | 2 +- kustomize/overlays/dev/placeholders.txt | 10 ++--- setup-dev-cluster.sh | 43 ++++++++++++++----- 11 files changed, 103 insertions(+), 49 deletions(-) diff --git a/clean-dev-cluster.sh b/clean-dev-cluster.sh index f1f4e24..b0a3e17 100755 --- a/clean-dev-cluster.sh +++ b/clean-dev-cluster.sh @@ -1,7 +1,6 @@ #!/bin/bash -e k3d cluster delete local -# docker stop registry.localhost -# docker container rm registry.localhost -# docker stop mariadb.localhost -# docker container rm mariadb.localhost \ No newline at end of file +docker rm -f registry-localhost +docker rm -f mariadb-localhost +docker rm -f nfs-localhost diff --git a/kustomize/bases/gitea/gitea-deployment.yaml b/kustomize/bases/gitea/gitea-deployment.yaml index cac862f..e7713ac 100644 --- a/kustomize/bases/gitea/gitea-deployment.yaml +++ b/kustomize/bases/gitea/gitea-deployment.yaml @@ -57,31 +57,45 @@ spec: - name: ssh containerPort: 22 volumeMounts: - - name: gitea-pvc + - name: gitea-data mountPath: /data - # - name: gitea-app-ini - # mountPath: /data/gitea/conf/ - # readOnly: true volumes: - - name: gitea-pvc + - name: gitea-data persistentVolumeClaim: - claimName: gitea-pvc - # - name: gitea-app-ini - # secret: - # secretName: gitea-app-ini-secret + claimName: gitea-data --- apiVersion: v1 -kind: PersistentVolumeClaim +kind: PersistentVolume metadata: - name: gitea-pvc + name: gitea-data-nfs labels: app: gitea spec: accessModes: - - ReadWriteOnce + - ReadWriteMany + capacity: + storage: 100Mi + nfs: + server: nfs-localhost + path: /gitea + mountOptions: ["vers=4"] +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: gitea-data + labels: + app: gitea +spec: + storageClassName: "" + accessModes: + - ReadWriteMany resources: requests: - storage: 20Gi + storage: 100Mi + selector: + matchLabels: + app: gitea --- apiVersion: v1 kind: Service diff --git a/kustomize/bases/gitea/kustomization.yaml b/kustomize/bases/gitea/kustomization.yaml index 4ed9f8e..b777c76 100644 --- a/kustomize/bases/gitea/kustomization.yaml +++ b/kustomize/bases/gitea/kustomization.yaml @@ -7,7 +7,7 @@ secretGenerator: type: Opaque behavior: create literals: - - host=mariadb.localhost:3306 + - host=172.18.1.0:3306 - database=gitea - username=gitea - password=changeme diff --git a/kustomize/bases/grafana/kustomization.yaml b/kustomize/bases/grafana/kustomization.yaml index 657f36e..63373a4 100644 --- a/kustomize/bases/grafana/kustomization.yaml +++ b/kustomize/bases/grafana/kustomization.yaml @@ -12,7 +12,7 @@ secretGenerator: type: Opaque behavior: create literals: - - host=mariadb.localhost:3306 + - host=172.18.1.0:3306 - database=grafana - username=grafana - password=changeme diff --git a/kustomize/bases/nextcloud/kustomization.yaml b/kustomize/bases/nextcloud/kustomization.yaml index 7f99a85..ff4055c 100644 --- a/kustomize/bases/nextcloud/kustomization.yaml +++ b/kustomize/bases/nextcloud/kustomization.yaml @@ -8,7 +8,7 @@ secretGenerator: type: Opaque behavior: create literals: - - host=mariadb.localhost:3306 + - host=172.18.1.0:3306 - database=nextcloud - username=nextcloud - password=changeme diff --git a/kustomize/bases/nextcloud/nextcloud-cronjob.yaml b/kustomize/bases/nextcloud/nextcloud-cronjob.yaml index a2ae5a3..a974fe4 100644 --- a/kustomize/bases/nextcloud/nextcloud-cronjob.yaml +++ b/kustomize/bases/nextcloud/nextcloud-cronjob.yaml @@ -16,13 +16,13 @@ spec: runAsUser: 33 runAsGroup: 33 volumeMounts: - - name: nextcloud-pvc + - name: nextcloud-data mountPath: /var/www/html command: - php - -f - /var/www/html/cron.php volumes: - - name: nextcloud-pvc + - name: nextcloud-data persistentVolumeClaim: - claimName: nextcloud-pvc + claimName: nextcloud-data diff --git a/kustomize/bases/nextcloud/nextcloud-deployment.yaml b/kustomize/bases/nextcloud/nextcloud-deployment.yaml index 3a1694b..64c4a5d 100644 --- a/kustomize/bases/nextcloud/nextcloud-deployment.yaml +++ b/kustomize/bases/nextcloud/nextcloud-deployment.yaml @@ -15,7 +15,7 @@ spec: spec: containers: - name: nextcloud - image: nextcloud:18.0.4 + image: nextcloud:19.0.2 env: - name: TRUSTED_PROXIES value: 10.0.0.0/8 @@ -43,25 +43,45 @@ spec: - name: http containerPort: 80 volumeMounts: - - name: nextcloud-pvc + - name: nextcloud-data mountPath: /var/www/html volumes: - - name: nextcloud-pvc + - name: nextcloud-data persistentVolumeClaim: - claimName: nextcloud-pvc + claimName: nextcloud-data --- apiVersion: v1 -kind: PersistentVolumeClaim +kind: PersistentVolume metadata: - name: nextcloud-pvc + name: nextcloud-data-nfs labels: app: nextcloud spec: accessModes: - - ReadWriteOnce + - ReadWriteMany + capacity: + storage: 100Mi + nfs: + server: nfs-localhost + path: /nextcloud + mountOptions: ["vers=4"] +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: nextcloud-data + labels: + app: nextcloud +spec: + storageClassName: "" + accessModes: + - ReadWriteMany resources: requests: - storage: 50Gi + storage: 100Mi + selector: + matchLabels: + app: nextcloud --- apiVersion: v1 kind: Service diff --git a/kustomize/overlays/dev/cert-manager/clusterissuer.yaml b/kustomize/overlays/dev/cert-manager/clusterissuer.yaml index 3793dc1..58f1934 100644 --- a/kustomize/overlays/dev/cert-manager/clusterissuer.yaml +++ b/kustomize/overlays/dev/cert-manager/clusterissuer.yaml @@ -16,7 +16,7 @@ spec: solvers: - selector: dnsZones: - - badjware.dev + - local.badjware.dev dns01: cnameStrategy: Follow digitalocean: diff --git a/kustomize/overlays/dev/kustomization.yaml b/kustomize/overlays/dev/kustomization.yaml index d650bfc..b4861f1 100644 --- a/kustomize/overlays/dev/kustomization.yaml +++ b/kustomize/overlays/dev/kustomization.yaml @@ -1,6 +1,6 @@ bases: - ../../namespaces/gitea - - ../../namespaces/grafana + # - ../../namespaces/grafana - ../../namespaces/nextcloud resources: diff --git a/kustomize/overlays/dev/placeholders.txt b/kustomize/overlays/dev/placeholders.txt index 2cb8da5..adc1c46 100644 --- a/kustomize/overlays/dev/placeholders.txt +++ b/kustomize/overlays/dev/placeholders.txt @@ -1,5 +1,5 @@ -DRONE_EXTERNAL_HOST=drone.localhost -GITEA_EXTERNAL_HOST=gitea.localhost -GRAFANA_EXTERNAL_HOST=grafana.localhost -KUBERNETES_DASHBOARD_EXTERNAL_HOST=kubernetes-dashboard.localhost -NEXTCLOUD_EXTERNAL_HOST=nextcloud.localhost +DRONE_EXTERNAL_HOST=drone.local.badjware.dev +GITEA_EXTERNAL_HOST=gitea.local.badjware.dev +GRAFANA_EXTERNAL_HOST=grafana.local.badjware.dev +KUBERNETES_DASHBOARD_EXTERNAL_HOST=kubernetes-dashboard.local.badjware.dev +NEXTCLOUD_EXTERNAL_HOST=nextcloud.local.badjware.dev diff --git a/setup-dev-cluster.sh b/setup-dev-cluster.sh index 8157173..a08e95c 100755 --- a/setup-dev-cluster.sh +++ b/setup-dev-cluster.sh @@ -1,4 +1,4 @@ -#!/bin/bash -e +#!/bin/bash -ex cluster_name='local' k3s_registry_config="$HOME/.config/k3d/registries.yaml" @@ -12,9 +12,9 @@ if [[ ! -f "$k3s_registry_cofing" ]]; then mkdir -p "$(dirname "$k3s_registry_config")" cat >"$k3s_registry_config" </dev/null; then +if ! docker ps -a | grep registry-localhost &>/dev/null; then docker volume create local_registry docker run -d \ - --name registry.localhost \ + --name registry-localhost \ --volume local_registry:/var/lib/registry \ --restart always \ -p 5000:5000 \ registry:2 - docker network connect "k3d-$cluster_name" registry.localhost + docker network connect "k3d-$cluster_name" registry-localhost fi # local mariadb database -if ! docker ps -a | grep mariadb.localhost &>/dev/null; then +if ! docker ps -a | grep mariadb-localhost &>/dev/null; then docker volume create local_mariadb docker run -d \ - --name mariadb.localhost \ + --name mariadb-localhost \ + --ip 172.18.1.0 \ --volume local_mariadb:/var/lib/mysql \ --restart always \ --env MYSQL_ROOT_PASSWORD=changeme \ -p 3306:3306 \ mariadb:10.5 - docker network connect "k3d-$cluster_name" mariadb.localhost + docker network connect "k3d-$cluster_name" mariadb-localhost sleep 10 fi -docker exec mariadb.localhost mysql -vv -uroot -pchangeme -e " +# local nfs server +if ! docker ps -a | grep nfs-localhost &>/dev/null; then + docker volume create local_nfs + docker run -d \ + --name nfs-localhost \ + --ip 172.18.1.1 \ + --volume nfs_local:/data \ + --volume /lib/modules:/lib/modules:ro \ + --restart always \ + --cap-add SYS_ADMIN \ + --cap-add SYS_MODULE \ + --env NFS_EXPORT_0='/data *(rw,async,insecure,no_subtree_check,no_root_squash,fsid=0)' \ + --env NFS_DISABLE_VERSION_3=YES \ + --env NFS_LOG_LEVEL=DEBUG \ + -p 2049:2049 \ + erichough/nfs-server:2.2.1 + docker network connect "k3d-$cluster_name" nfs-localhost + sleep 10 +fi + +docker exec mariadb-localhost mysql -vv -uroot -pchangeme -e " CREATE DATABASE IF NOT EXISTS gitea; CREATE USER IF NOT EXISTS 'gitea'@'%' IDENTIFIED BY 'changeme'; GRANT ALL PRIVILEGES ON gitea.* TO 'gitea'@'%'; @@ -77,4 +98,4 @@ FLUSH PRIVILEGES; k3d kubeconfig merge "$cluster_name" --switch-context >/dev/null kubectl apply -f "$auto_deploy_manifest" -kubectl get nodes \ No newline at end of file +kubectl get nodes