From a72846d1a80ccc478088802b05ecc082da531e1e Mon Sep 17 00:00:00 2001 From: Sergio Neves Barros Date: Sun, 11 Dec 2022 15:54:39 +0000 Subject: [PATCH 1/7] added initial Kubernetes manifests to deploy the angles dashboard on a cluster (including the mongo database). --- setup/kubernetes/01-angles-namespace.yaml | 7 +++ setup/kubernetes/02-angles-config.yaml | 65 ++++++++++++++++++++++ setup/kubernetes/03-mongo-pod.yaml | 40 ++++++++++++++ setup/kubernetes/03-mongo-service.yaml | 14 +++++ setup/kubernetes/04-angles-pod.yaml | 67 +++++++++++++++++++++++ setup/kubernetes/04-angles-service.yaml | 31 +++++++++++ 6 files changed, 224 insertions(+) create mode 100644 setup/kubernetes/01-angles-namespace.yaml create mode 100644 setup/kubernetes/02-angles-config.yaml create mode 100644 setup/kubernetes/03-mongo-pod.yaml create mode 100644 setup/kubernetes/03-mongo-service.yaml create mode 100644 setup/kubernetes/04-angles-pod.yaml create mode 100644 setup/kubernetes/04-angles-service.yaml diff --git a/setup/kubernetes/01-angles-namespace.yaml b/setup/kubernetes/01-angles-namespace.yaml new file mode 100644 index 0000000..3ac1aa2 --- /dev/null +++ b/setup/kubernetes/01-angles-namespace.yaml @@ -0,0 +1,7 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: angles + labels: + name: angles +--- diff --git a/setup/kubernetes/02-angles-config.yaml b/setup/kubernetes/02-angles-config.yaml new file mode 100644 index 0000000..f5dfbcb --- /dev/null +++ b/setup/kubernetes/02-angles-config.yaml @@ -0,0 +1,65 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: angles-backend-config + namespace: angles +data: + REACT_APP_SWAGGER_ANGLES_API_URL: "127.0.0.1:3000" + REACT_APP_SWAGGER_SCHEMES: "http" + PORT: "3000" + BUILD_CLEAN_UP_AGE_IN_DAYS: "90" + +--- + +apiVersion: v1 +kind: ConfigMap +metadata: + name: angles-ui-config + namespace: angles +data: + PORT: "3001" + +--- + +apiVersion: v1 +kind: ConfigMap +metadata: + name: angles-mongo-config + namespace: angles +data: + MONGO_INITDB_ROOT_USERNAME: "admin" + MONGO_INITDB_ROOT_PASSWORD: "@nglesPassword" + MONGO_INITDB_DATABASE: "angles" + +--- + +apiVersion: v1 +kind: ConfigMap +metadata: + name: mongo-init + namespace: angles +data: + mongo-init.js: | + // Change the pwd value + db.createUser({ user: 'angleshq', pwd: '@nglesPassword', roles: ['readWrite'] }); + db.auth('angleshq', '@nglesPassword'); + + // create collections (which don't require setup) + db.createCollection('builds'); + db.createCollection('testexecutions'); + db.createCollection('teams'); + db.createCollection('phase'); + db.createCollection('environments'); + db.createCollection('baselines'); + db.createCollection('screenshots'); + + db.testexecutions.createIndex({ build: 1 }); + db.testexecutions.createIndex({ suite: 1, title: 1 }); + db.build.createIndex({ team: 1 }); + db.team.createIndex({ name: 1 }); + db.phase.createIndex({ name: 1 }); + db.environment.createIndex({ name: 1 }); + db.screenshots.createIndex({ build: 1 }); + db.screenshots.createIndex({ view: 1 }); + +--- diff --git a/setup/kubernetes/03-mongo-pod.yaml b/setup/kubernetes/03-mongo-pod.yaml new file mode 100644 index 0000000..50999c7 --- /dev/null +++ b/setup/kubernetes/03-mongo-pod.yaml @@ -0,0 +1,40 @@ +apiVersion: v1 +kind: Pod +metadata: + name: angles-mongo-database + namespace: angles + labels: + app.kubernetes.io/name: angles-mongo-database +spec: + containers: + - name: angles-mongo + image: mongo:4.4.13 + imagePullPolicy: IfNotPresent + resources: + limits: + cpu: '1500m' + memory: '1000Mi' + requests: + cpu: '1000m' + memory: '800Mi' + ports: + - containerPort: 27017 + hostPort: 27017 + envFrom: + - configMapRef: + name: angles-mongo-config + volumeMounts: + - mountPath: /data/db + name: angles-mongo-db + - mountPath: /data/configdb + name: angles-mongo-config + - name: mongo-init + mountPath: /docker-entrypoint-initdb.d/mongo-init.js + subPath: mongo-init.js + volumes: + - name: angles-mongo-db + - name: angles-mongo-config + - name: mongo-init + configMap: + name: mongo-init + diff --git a/setup/kubernetes/03-mongo-service.yaml b/setup/kubernetes/03-mongo-service.yaml new file mode 100644 index 0000000..5d86d37 --- /dev/null +++ b/setup/kubernetes/03-mongo-service.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: Service +metadata: + name: angles-database-service + namespace: angles +spec: + selector: + app.kubernetes.io/name: angles-mongo-database + type: ClusterIP + ports: + - name: mongo + protocol: TCP + port: 27017 + targetPort: 27017 diff --git a/setup/kubernetes/04-angles-pod.yaml b/setup/kubernetes/04-angles-pod.yaml new file mode 100644 index 0000000..c3210bb --- /dev/null +++ b/setup/kubernetes/04-angles-pod.yaml @@ -0,0 +1,67 @@ +apiVersion: v1 +kind: Pod +metadata: + name: angles-dashboard-backend + namespace: angles + labels: + app.kubernetes.io/name: angles-dashboard-backend +spec: + containers: + - name: angles + image: angleshq/angles:latest + imagePullPolicy: IfNotPresent + resources: + limits: + cpu: '1500m' + memory: '1000Mi' + requests: + cpu: '1000m' + memory: '800Mi' + ports: + - containerPort: 3000 + hostPort: 3000 + env: + - name: MONGO_URL + value: "mongodb://angleshq:%40nglesPassword@$(ANGLES_DATABASE_SERVICE_SERVICE_HOST):$(ANGLES_DATABASE_SERVICE_SERVICE_PORT)/angles" + envFrom: + - configMapRef: + name: angles-backend-config + volumeMounts: + - mountPath: /app/screenshots + name: angles-screenshots + - mountPath: /app/compares + name: angles-screenshot-compares + volumes: + - name: angles-screenshots + - name: angles-screenshot-compares + +--- + +apiVersion: v1 +kind: Pod +metadata: + name: angles-dashboard-frontend + namespace: angles + labels: + app.kubernetes.io/name: angles-dashboard-frontend +spec: + containers: + - name: angles-ui + image: angleshq/angles-ui:latest + imagePullPolicy: IfNotPresent + resources: + limits: + cpu: '1000m' + memory: '600Mi' + requests: + cpu: '750m' + memory: '400Mi' + ports: + - containerPort: 3001 + hostPort: 3001 + env: + - name: REACT_APP_ANGLES_API_URL + value: "http://$(ANGLES_BACKEND_SERVICE_SERVICE_HOST):$(ANGLES_BACKEND_SERVICE_SERVICE_PORT)" + envFrom: + - configMapRef: + name: angles-ui-config diff --git a/setup/kubernetes/04-angles-service.yaml b/setup/kubernetes/04-angles-service.yaml new file mode 100644 index 0000000..0655068 --- /dev/null +++ b/setup/kubernetes/04-angles-service.yaml @@ -0,0 +1,31 @@ +apiVersion: v1 +kind: Service +metadata: + name: angles-backend-service + namespace: angles +spec: + selector: + app.kubernetes.io/name: angles-dashboard-backend + type: ClusterIP + ports: + - name: webservice + protocol: TCP + port: 3001 + targetPort: 3001 + +--- + +apiVersion: v1 +kind: Service +metadata: + name: angles-frontend-service + namespace: angles +spec: + selector: + app.kubernetes.io/name: angles-dashboard-frontend + type: ClusterIP + ports: + - name: web + protocol: TCP + port: 3001 + targetPort: 3001 From 84fcf5a87f6bcd7acd6e56037936dc14571a391c Mon Sep 17 00:00:00 2001 From: Sergio Neves Barros Date: Sun, 11 Dec 2022 17:10:12 +0000 Subject: [PATCH 2/7] backend is on port 3000 --- setup/kubernetes/04-angles-service.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup/kubernetes/04-angles-service.yaml b/setup/kubernetes/04-angles-service.yaml index 0655068..811410e 100644 --- a/setup/kubernetes/04-angles-service.yaml +++ b/setup/kubernetes/04-angles-service.yaml @@ -10,8 +10,8 @@ spec: ports: - name: webservice protocol: TCP - port: 3001 - targetPort: 3001 + port: 3000 + targetPort: 3000 --- From 945a265825de597da315beadf2739e29d1a5374d Mon Sep 17 00:00:00 2001 From: Sergio Neves Barros Date: Sat, 17 Dec 2022 16:00:26 +0000 Subject: [PATCH 3/7] changing ports for kubernetes setup. --- setup/kubernetes/02-angles-config.yaml | 14 ++------------ setup/kubernetes/04-angles-pod.yaml | 13 ++++++------- setup/kubernetes/04-angles-service.yaml | 8 ++++---- 3 files changed, 12 insertions(+), 23 deletions(-) diff --git a/setup/kubernetes/02-angles-config.yaml b/setup/kubernetes/02-angles-config.yaml index f5dfbcb..516ecff 100644 --- a/setup/kubernetes/02-angles-config.yaml +++ b/setup/kubernetes/02-angles-config.yaml @@ -4,23 +4,13 @@ metadata: name: angles-backend-config namespace: angles data: - REACT_APP_SWAGGER_ANGLES_API_URL: "127.0.0.1:3000" + REACT_APP_SWAGGER_ANGLES_API_URL: "127.0.0.1:3002" REACT_APP_SWAGGER_SCHEMES: "http" - PORT: "3000" + PORT: "3002" BUILD_CLEAN_UP_AGE_IN_DAYS: "90" --- -apiVersion: v1 -kind: ConfigMap -metadata: - name: angles-ui-config - namespace: angles -data: - PORT: "3001" - ---- - apiVersion: v1 kind: ConfigMap metadata: diff --git a/setup/kubernetes/04-angles-pod.yaml b/setup/kubernetes/04-angles-pod.yaml index c3210bb..17670ca 100644 --- a/setup/kubernetes/04-angles-pod.yaml +++ b/setup/kubernetes/04-angles-pod.yaml @@ -18,8 +18,8 @@ spec: cpu: '1000m' memory: '800Mi' ports: - - containerPort: 3000 - hostPort: 3000 + - containerPort: 3002 + hostPort: 3002 env: - name: MONGO_URL value: "mongodb://angleshq:%40nglesPassword@$(ANGLES_DATABASE_SERVICE_SERVICE_HOST):$(ANGLES_DATABASE_SERVICE_SERVICE_PORT)/angles" @@ -57,11 +57,10 @@ spec: cpu: '750m' memory: '400Mi' ports: - - containerPort: 3001 - hostPort: 3001 + - containerPort: 3003 + hostPort: 3003 env: - name: REACT_APP_ANGLES_API_URL value: "http://$(ANGLES_BACKEND_SERVICE_SERVICE_HOST):$(ANGLES_BACKEND_SERVICE_SERVICE_PORT)" - envFrom: - - configMapRef: - name: angles-ui-config + - name: PORT + value: "3003" diff --git a/setup/kubernetes/04-angles-service.yaml b/setup/kubernetes/04-angles-service.yaml index 811410e..c9a6189 100644 --- a/setup/kubernetes/04-angles-service.yaml +++ b/setup/kubernetes/04-angles-service.yaml @@ -10,8 +10,8 @@ spec: ports: - name: webservice protocol: TCP - port: 3000 - targetPort: 3000 + port: 3002 + targetPort: 3002 --- @@ -27,5 +27,5 @@ spec: ports: - name: web protocol: TCP - port: 3001 - targetPort: 3001 + port: 3003 + targetPort: 3003 From 631c1fe5356d745355e1e4912647f60867db1a63 Mon Sep 17 00:00:00 2001 From: Sergio Neves Barros Date: Sun, 18 Dec 2022 21:22:33 +0000 Subject: [PATCH 4/7] added persistent local storage. --- setup/kubernetes/01-angles-storage.yaml | 66 +++++++++++++++++++++++++ setup/kubernetes/03-mongo-pod.yaml | 15 +++--- setup/kubernetes/04-angles-pod.yaml | 31 +++++++----- 3 files changed, 93 insertions(+), 19 deletions(-) create mode 100644 setup/kubernetes/01-angles-storage.yaml diff --git a/setup/kubernetes/01-angles-storage.yaml b/setup/kubernetes/01-angles-storage.yaml new file mode 100644 index 0000000..3c48df3 --- /dev/null +++ b/setup/kubernetes/01-angles-storage.yaml @@ -0,0 +1,66 @@ +# before creating a persistent volume have to create the disk. +# e.g. gcloud beta compute disks create --size=100GB angles-data-disk --region --replica-zones + +#apiVersion: v1 +#kind: PersistentVolume +#metadata: +# name: angles-persistent-volume +# namespace: angles +#spec: +# accessModes: +# - ReadWriteOnce +# persistentVolumeReclaimPolicy: Retain +# capacity: +# storage: 100Gi +# gcePersistentDisk: +# fsType: ext4 +# pdName: angles-data-disk +# storageClassName: gcp-disk +# +#--- +# +#apiVersion: v1 +#kind: PersistentVolumeClaim +#metadata: +# name: angles-persistent-volume-claim +# namespace: angles +#spec: +# accessModes: +# - ReadWriteOnce +# resources: +# requests: +# storage: 100Gi +# storageClassName: gcp-disk + +--- +# storage for local cluster e.g. k3d +apiVersion: v1 +kind: PersistentVolume +metadata: + name: angles-persistent-volume + namespace: angles + labels: + type: local +spec: + storageClassName: manual + capacity: + storage: 5Gi + accessModes: + - ReadWriteOnce + persistentVolumeReclaimPolicy: Retain + hostPath: + path: "/tmp/k3dvol" +--- + +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: angles-persistent-volume-claim + namespace: angles +spec: + storageClassName: manual + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 5Gi diff --git a/setup/kubernetes/03-mongo-pod.yaml b/setup/kubernetes/03-mongo-pod.yaml index 50999c7..bc4c6e0 100644 --- a/setup/kubernetes/03-mongo-pod.yaml +++ b/setup/kubernetes/03-mongo-pod.yaml @@ -24,17 +24,20 @@ spec: - configMapRef: name: angles-mongo-config volumeMounts: - - mountPath: /data/db - name: angles-mongo-db - - mountPath: /data/configdb - name: angles-mongo-config - name: mongo-init mountPath: /docker-entrypoint-initdb.d/mongo-init.js subPath: mongo-init.js + - mountPath: "/data/db" + subPath: "./db" + name: angles-persistent-volume + - mountPath: "/data/config" + subPath: "./config" + name: angles-persistent-volume volumes: - - name: angles-mongo-db - - name: angles-mongo-config - name: mongo-init configMap: name: mongo-init + - name: angles-persistent-volume + persistentVolumeClaim: + claimName: angles-persistent-volume-claim diff --git a/setup/kubernetes/04-angles-pod.yaml b/setup/kubernetes/04-angles-pod.yaml index 17670ca..1d0c786 100644 --- a/setup/kubernetes/04-angles-pod.yaml +++ b/setup/kubernetes/04-angles-pod.yaml @@ -13,10 +13,10 @@ spec: resources: limits: cpu: '1500m' - memory: '1000Mi' + memory: '1500Mi' requests: cpu: '1000m' - memory: '800Mi' + memory: '1000Mi' ports: - containerPort: 3002 hostPort: 3002 @@ -27,13 +27,16 @@ spec: - configMapRef: name: angles-backend-config volumeMounts: - - mountPath: /app/screenshots - name: angles-screenshots - - mountPath: /app/compares - name: angles-screenshot-compares + - mountPath: "/app/screenshots" + subPath: "./screenshots" + name: angles-persistent-volume + - mountPath: "/app/compares" + subPath: "./compares" + name: angles-persistent-volume volumes: - - name: angles-screenshots - - name: angles-screenshot-compares + - name: angles-persistent-volume + persistentVolumeClaim: + claimName: angles-persistent-volume-claim --- @@ -51,16 +54,18 @@ spec: imagePullPolicy: IfNotPresent resources: limits: - cpu: '1000m' - memory: '600Mi' + cpu: '2000m' + memory: '1500Mi' requests: - cpu: '750m' - memory: '400Mi' + cpu: '1500m' + memory: '1000Mi' ports: - containerPort: 3003 hostPort: 3003 env: - name: REACT_APP_ANGLES_API_URL - value: "http://$(ANGLES_BACKEND_SERVICE_SERVICE_HOST):$(ANGLES_BACKEND_SERVICE_SERVICE_PORT)" + # this url is what the front-end app should call. + # value: "http://$(ANGLES_BACKEND_SERVICE_SERVICE_HOST):$(ANGLES_BACKEND_SERVICE_SERVICE_PORT)" + value: "http://127.0.0.1:$(ANGLES_BACKEND_SERVICE_SERVICE_PORT)" - name: PORT value: "3003" From 13438e0463f7d67d02b54f9ca3d60c436c96dae0 Mon Sep 17 00:00:00 2001 From: Sergio Neves Barros Date: Sat, 14 Jan 2023 20:59:19 +0000 Subject: [PATCH 5/7] working towards being able to pass the passwords as arguments --- setup/kubernetes/02-angles-config.yaml | 6 ++++-- setup/kubernetes/03-mongo-pod.yaml | 11 +++++++++++ setup/kubernetes/04-angles-pod.yaml | 17 ++++++++++++++--- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/setup/kubernetes/02-angles-config.yaml b/setup/kubernetes/02-angles-config.yaml index 516ecff..9eceeba 100644 --- a/setup/kubernetes/02-angles-config.yaml +++ b/setup/kubernetes/02-angles-config.yaml @@ -8,6 +8,8 @@ data: REACT_APP_SWAGGER_SCHEMES: "http" PORT: "3002" BUILD_CLEAN_UP_AGE_IN_DAYS: "90" + MONGO_ANGLES_USERNAME: "angleshq" + MONGO_ANGLES_PASSWORD: "Password123" --- @@ -31,8 +33,8 @@ metadata: data: mongo-init.js: | // Change the pwd value - db.createUser({ user: 'angleshq', pwd: '@nglesPassword', roles: ['readWrite'] }); - db.auth('angleshq', '@nglesPassword'); + db.createUser({ user: 'angleshq', pwd: 'Password123', roles: ['readWrite'] }); + db.auth('angleshq', 'Password123'); // create collections (which don't require setup) db.createCollection('builds'); diff --git a/setup/kubernetes/03-mongo-pod.yaml b/setup/kubernetes/03-mongo-pod.yaml index bc4c6e0..2b101c9 100644 --- a/setup/kubernetes/03-mongo-pod.yaml +++ b/setup/kubernetes/03-mongo-pod.yaml @@ -23,6 +23,17 @@ spec: envFrom: - configMapRef: name: angles-mongo-config + env: + - name: MONGO_ANGLES_PASSWORD + valueFrom: + configMapKeyRef: + name: angles-backend-config + key: MONGO_ANGLES_PASSWORD + - name: MONGO_ANGLES_USERNAME + valueFrom: + configMapKeyRef: + name: angles-backend-config + key: MONGO_ANGLES_USERNAME volumeMounts: - name: mongo-init mountPath: /docker-entrypoint-initdb.d/mongo-init.js diff --git a/setup/kubernetes/04-angles-pod.yaml b/setup/kubernetes/04-angles-pod.yaml index 1d0c786..e531b04 100644 --- a/setup/kubernetes/04-angles-pod.yaml +++ b/setup/kubernetes/04-angles-pod.yaml @@ -20,12 +20,23 @@ spec: ports: - containerPort: 3002 hostPort: 3002 - env: - - name: MONGO_URL - value: "mongodb://angleshq:%40nglesPassword@$(ANGLES_DATABASE_SERVICE_SERVICE_HOST):$(ANGLES_DATABASE_SERVICE_SERVICE_PORT)/angles" envFrom: - configMapRef: name: angles-backend-config + env: +# - name: MONGO_PASSWORD +# valueFrom: +# configMapKeyRef: +# name: angles-mongo-config +# key: MONGO_ANGLES_PASSWORD +# - name: MONGO_USERNAME +# valueFrom: +# configMapKeyRef: +# name: angles-mongo-config +# key: MONGO_ANGLES_USERNAME + - name: MONGO_URL + value: "mongodb://$(MONGO_ANGLES_USERNAME):$(MONGO_ANGLES_PASSWORD)@$(ANGLES_DATABASE_SERVICE_SERVICE_HOST):$(ANGLES_DATABASE_SERVICE_SERVICE_PORT)/angles" + volumeMounts: - mountPath: "/app/screenshots" subPath: "./screenshots" From c4fa82a70b630371be53c9f06c38ac80fa0bfb37 Mon Sep 17 00:00:00 2001 From: Sergio Neves Barros Date: Sat, 14 Jan 2023 21:17:51 +0000 Subject: [PATCH 6/7] changed the init file to sh file, so that arguments can be passed through environment variables. db credentials are now in single locations and can be modified there. --- setup/kubernetes/02-angles-config.yaml | 46 ++++++++++++++------------ setup/kubernetes/03-mongo-pod.yaml | 4 +-- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/setup/kubernetes/02-angles-config.yaml b/setup/kubernetes/02-angles-config.yaml index 9eceeba..0229347 100644 --- a/setup/kubernetes/02-angles-config.yaml +++ b/setup/kubernetes/02-angles-config.yaml @@ -8,6 +8,7 @@ data: REACT_APP_SWAGGER_SCHEMES: "http" PORT: "3002" BUILD_CLEAN_UP_AGE_IN_DAYS: "90" + # change these credentials MONGO_ANGLES_USERNAME: "angleshq" MONGO_ANGLES_PASSWORD: "Password123" @@ -20,6 +21,7 @@ metadata: namespace: angles data: MONGO_INITDB_ROOT_USERNAME: "admin" + # change the admin password MONGO_INITDB_ROOT_PASSWORD: "@nglesPassword" MONGO_INITDB_DATABASE: "angles" @@ -31,27 +33,29 @@ metadata: name: mongo-init namespace: angles data: - mongo-init.js: | - // Change the pwd value - db.createUser({ user: 'angleshq', pwd: 'Password123', roles: ['readWrite'] }); - db.auth('angleshq', 'Password123'); + mongo-init.sh: | + mongo -- "$MONGO_INITDB_DATABASE" < Date: Sat, 14 Jan 2023 21:38:11 +0000 Subject: [PATCH 7/7] cleanup --- setup/kubernetes/04-angles-pod.yaml | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/setup/kubernetes/04-angles-pod.yaml b/setup/kubernetes/04-angles-pod.yaml index e531b04..83ec387 100644 --- a/setup/kubernetes/04-angles-pod.yaml +++ b/setup/kubernetes/04-angles-pod.yaml @@ -24,16 +24,6 @@ spec: - configMapRef: name: angles-backend-config env: -# - name: MONGO_PASSWORD -# valueFrom: -# configMapKeyRef: -# name: angles-mongo-config -# key: MONGO_ANGLES_PASSWORD -# - name: MONGO_USERNAME -# valueFrom: -# configMapKeyRef: -# name: angles-mongo-config -# key: MONGO_ANGLES_USERNAME - name: MONGO_URL value: "mongodb://$(MONGO_ANGLES_USERNAME):$(MONGO_ANGLES_PASSWORD)@$(ANGLES_DATABASE_SERVICE_SERVICE_HOST):$(ANGLES_DATABASE_SERVICE_SERVICE_PORT)/angles"