From 78b74210f79b4d77918134e5caee74f82d5030f8 Mon Sep 17 00:00:00 2001 From: Florian Wilhelm Date: Wed, 26 Jun 2024 12:21:41 +0200 Subject: [PATCH 1/5] Bootstrap kubernetes deployment for GLVD --- docs/kubernetes-deployment.md | 9 +++ kubernetes-deployment.yaml | 115 ++++++++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+) create mode 100644 docs/kubernetes-deployment.md create mode 100644 kubernetes-deployment.yaml diff --git a/docs/kubernetes-deployment.md b/docs/kubernetes-deployment.md new file mode 100644 index 0000000..c4bb3a8 --- /dev/null +++ b/docs/kubernetes-deployment.md @@ -0,0 +1,9 @@ + +```bash +# create a random password for the database +kubectl create secret generic postgres-password --type=string --from-literal=password=$(pwgen 42 1) + +# create deployment (needs the password secret) +# this will be starting the data ingestion process which takes a while for the first time +kubectl apply -f kubernetes-deployment.yaml +``` diff --git a/kubernetes-deployment.yaml b/kubernetes-deployment.yaml new file mode 100644 index 0000000..e6ec99c --- /dev/null +++ b/kubernetes-deployment.yaml @@ -0,0 +1,115 @@ +kind: Deployment +apiVersion: apps/v1 +metadata: + labels: + app: glvd + name: glvd +spec: + replicas: 1 + selector: + matchLabels: + app: "glvd" + strategy: {} + template: + metadata: + labels: + app: glvd + spec: + containers: + - image: ghcr.io/gardenlinux/glvd-api:edge_bare + name: glvd-api + resources: + requests: + cpu: "1" + memory: "2Gi" + limits: + cpu: "2" + memory: "4Gi" + env: + # cf https://github.com/spring-projects/spring-lifecycle-smoke-tests/tree/main/data/data-jpa#prevent-early-database-interaction + - name: SPRING_DATASOURCE_URL + value: "jdbc:postgresql://localhost:5432/glvd" + - name: SPRING_DATASOURCE_USERNAME + value: glvd + - name: SPRING_DATASOURCE_PASSWORD + valueFrom: + secretKeyRef: + name: postgres-password + key: password + - name: SPRING_JPA_DATABASEPLATFORM + value: "org.hibernate.dialect.PostgreSQLDialect" + - name: SPRING_JPA_PROPERTIES_HIBERNATE_BOOT_ALLOW_JDBC_METADATA_ACCESS + value: "false" + - name: SPRING_JPA_HIBERNATE_DDLAUTO + value: "none" + - name: SPRING_SQL_INIT_MODE + value: "never" + - image: ghcr.io/gardenlinux/glvd-postgres:edgenotls + name: glvd-postgres + resources: + requests: + cpu: "1" + memory: "2Gi" + limits: + cpu: "2" + memory: "4Gi" + ports: + - containerPort: 5432 + hostPort: 5432 + env: + - name: POSTGRES_USER + value: glvd + - name: POSTGRES_DATABASE + value: glvd + - name: POSTGRES_PASSWORD + valueFrom: + secretKeyRef: + name: postgres-password + key: password + - name: POSTGRES_HOST + value: glvd-postgres + - name: POSTGRES_PORT + value: "5432" + # TODO: data-ingestion should be running as a cron job + - name: data-ingestion + image: ghcr.io/gardenlinux/glvd:edge + resources: + requests: + cpu: "1" + memory: "2Gi" + limits: + cpu: "2" + memory: "4Gi" + command: + - /bin/bash + - -c + - sleep 5 && echo start && /usr/local/src/ingest-postgres.sh && echo done && sleep infinity + env: + - name: PGUSER + value: glvd + - name: PGDATABASE + value: glvd + - name: PGPASSWORD + valueFrom: + secretKeyRef: + name: postgres-password + key: password + - name: PGHOST + value: localhost + - name: PGPORT + value: "5432" +--- +apiVersion: v1 +kind: Service +metadata: + labels: + app: glvd + name: glvd +spec: + ports: + - port: 8080 + protocol: TCP + targetPort: 8080 + selector: + app: glvd + type: LoadBalancer From 7761f1cdc80079cef521f7d4c4939710f0263f4e Mon Sep 17 00:00:00 2001 From: Florian Wilhelm Date: Wed, 26 Jun 2024 15:38:09 +0200 Subject: [PATCH 2/5] add postgres volume --- docs/kubernetes-deployment.md | 19 +++++++++++++++++++ kubernetes-deployment.yaml | 23 +++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/docs/kubernetes-deployment.md b/docs/kubernetes-deployment.md index c4bb3a8..08502a3 100644 --- a/docs/kubernetes-deployment.md +++ b/docs/kubernetes-deployment.md @@ -1,3 +1,9 @@ +# GLVD Kubernetes deployment + +This deployment guide is work in progress. +It is intended for development purposes so stakeholders can get a running version of the current development version of GLVD. + +Assuming you have a Kubernetes cluster with enough resources (8 cpu, 16 GiB memory), that ideally should be located in the US, the following should give you a running cluster: ```bash # create a random password for the database @@ -6,4 +12,17 @@ kubectl create secret generic postgres-password --type=string --from-literal=pas # create deployment (needs the password secret) # this will be starting the data ingestion process which takes a while for the first time kubectl apply -f kubernetes-deployment.yaml + +# check the progress, the last line should say 'done' +kubectl logs -c data-ingestion glvd-SOME-ID + +# get hostname of external service (this assumes only one hostname exists) +HOSTNAME=$(kubectl get svc glvd -o template --template '{{range .status.loadBalancer.ingress}}{{.hostname}}{{end}}') + +# check for readiness +curl http://$HOSTNAME:8080/readiness + +# use the API as described here https://gardenlinux.github.io/glvd-api/ +# but use the HOSTNAME variable instead of glvd.gardenlinux.io for now +curl http://$HOSTNAME:8080/v1/cves/debian_linux/bookworm ``` diff --git a/kubernetes-deployment.yaml b/kubernetes-deployment.yaml index e6ec99c..df1258a 100644 --- a/kubernetes-deployment.yaml +++ b/kubernetes-deployment.yaml @@ -1,3 +1,17 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: glvd-postgres-pvc +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 5Gi + storageClassName: 'default' + +--- + kind: Deployment apiVersion: apps/v1 metadata: @@ -15,6 +29,10 @@ spec: labels: app: glvd spec: + volumes: + - name: glvd-postgres-storage + persistentVolumeClaim: + claimName: glvd-postgres-pvc containers: - image: ghcr.io/gardenlinux/glvd-api:edge_bare name: glvd-api @@ -70,6 +88,11 @@ spec: value: glvd-postgres - name: POSTGRES_PORT value: "5432" + - name: PGDATA + value: /var/lib/postgresql/data/pgdata + volumeMounts: + - mountPath: "/var/lib/postgresql/data" + name: glvd-postgres-storage # TODO: data-ingestion should be running as a cron job - name: data-ingestion image: ghcr.io/gardenlinux/glvd:edge From 32ec247d43a8f5bb745a9c67fa58815461827be7 Mon Sep 17 00:00:00 2001 From: Florian Wilhelm Date: Fri, 28 Jun 2024 11:33:52 +0200 Subject: [PATCH 3/5] restructure deployment --- 00-glvd-pvc.yaml | 11 ++++++ ...deployment.yaml => 01-glvd-deployment.yaml | 37 ++++--------------- 02-glvd-service.yaml | 14 +++++++ docs/kubernetes-deployment.md | 8 +++- 4 files changed, 40 insertions(+), 30 deletions(-) create mode 100644 00-glvd-pvc.yaml rename kubernetes-deployment.yaml => 01-glvd-deployment.yaml (89%) create mode 100644 02-glvd-service.yaml diff --git a/00-glvd-pvc.yaml b/00-glvd-pvc.yaml new file mode 100644 index 0000000..3b119e8 --- /dev/null +++ b/00-glvd-pvc.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: glvd-postgres-pvc +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 5Gi + storageClassName: 'default' diff --git a/kubernetes-deployment.yaml b/01-glvd-deployment.yaml similarity index 89% rename from kubernetes-deployment.yaml rename to 01-glvd-deployment.yaml index df1258a..be3dc9e 100644 --- a/kubernetes-deployment.yaml +++ b/01-glvd-deployment.yaml @@ -1,17 +1,3 @@ -apiVersion: v1 -kind: PersistentVolumeClaim -metadata: - name: glvd-postgres-pvc -spec: - accessModes: - - ReadWriteOnce - resources: - requests: - storage: 5Gi - storageClassName: 'default' - ---- - kind: Deployment apiVersion: apps/v1 metadata: @@ -62,6 +48,14 @@ spec: value: "none" - name: SPRING_SQL_INIT_MODE value: "never" + livenessProbe: + httpGet: + path: "/actuator/health/liveness" + port: 8080 + readinessProbe: + httpGet: + path: "/actuator/health/readiness" + port: 8080 - image: ghcr.io/gardenlinux/glvd-postgres:edgenotls name: glvd-postgres resources: @@ -121,18 +115,3 @@ spec: value: localhost - name: PGPORT value: "5432" ---- -apiVersion: v1 -kind: Service -metadata: - labels: - app: glvd - name: glvd -spec: - ports: - - port: 8080 - protocol: TCP - targetPort: 8080 - selector: - app: glvd - type: LoadBalancer diff --git a/02-glvd-service.yaml b/02-glvd-service.yaml new file mode 100644 index 0000000..b00f6d3 --- /dev/null +++ b/02-glvd-service.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + app: glvd + name: glvd +spec: + ports: + - port: 8080 + protocol: TCP + targetPort: 8080 + selector: + app: glvd + type: LoadBalancer diff --git a/docs/kubernetes-deployment.md b/docs/kubernetes-deployment.md index 08502a3..3068f0e 100644 --- a/docs/kubernetes-deployment.md +++ b/docs/kubernetes-deployment.md @@ -9,9 +9,15 @@ Assuming you have a Kubernetes cluster with enough resources (8 cpu, 16 GiB memo # create a random password for the database kubectl create secret generic postgres-password --type=string --from-literal=password=$(pwgen 42 1) +# create persistent volume claim for postgres storage +kubectl apply -f 00-glvd-pvc.yaml + # create deployment (needs the password secret) # this will be starting the data ingestion process which takes a while for the first time -kubectl apply -f kubernetes-deployment.yaml +kubectl apply -f 01-glvd-deployment.yaml + +# create service to expose the api http interface +kubectl apply -f 02-glvd-service.yaml # check the progress, the last line should say 'done' kubectl logs -c data-ingestion glvd-SOME-ID From 5c12872ccfdd164363d81a36dbe3b4a793533315 Mon Sep 17 00:00:00 2001 From: Florian Wilhelm Date: Thu, 5 Sep 2024 12:31:40 +0200 Subject: [PATCH 4/5] improve k8s deployment --- 00-glvd-pvc.yaml | 11 ---- 00_db-statefulset.yaml | 96 ++++++++++++++++++++++++++++++++ 01-glvd-deployment.yaml | 117 --------------------------------------- 01_glvd-deployment.yaml | 118 ++++++++++++++++++++++++++++++++++++++++ 02-glvd-service.yaml | 14 ----- 02_ingestion-job.yaml | 67 +++++++++++++++++++++++ 6 files changed, 281 insertions(+), 142 deletions(-) delete mode 100644 00-glvd-pvc.yaml create mode 100644 00_db-statefulset.yaml delete mode 100644 01-glvd-deployment.yaml create mode 100644 01_glvd-deployment.yaml delete mode 100644 02-glvd-service.yaml create mode 100644 02_ingestion-job.yaml diff --git a/00-glvd-pvc.yaml b/00-glvd-pvc.yaml deleted file mode 100644 index 3b119e8..0000000 --- a/00-glvd-pvc.yaml +++ /dev/null @@ -1,11 +0,0 @@ -apiVersion: v1 -kind: PersistentVolumeClaim -metadata: - name: glvd-postgres-pvc -spec: - accessModes: - - ReadWriteOnce - resources: - requests: - storage: 5Gi - storageClassName: 'default' diff --git a/00_db-statefulset.yaml b/00_db-statefulset.yaml new file mode 100644 index 0000000..5b1ec5b --- /dev/null +++ b/00_db-statefulset.yaml @@ -0,0 +1,96 @@ +apiVersion: v1 +kind: Service +metadata: + name: glvd-database + labels: + app.kubernetes.io/name: glvd + gardenlinux.io/glvd-component: database +spec: + selector: + app.kubernetes.io/name: glvd + gardenlinux.io/glvd-component: database + ports: + - protocol: TCP + port: 5432 + name: postgres + targetPort: postgres + type: ClusterIP + clusterIP: None +--- +apiVersion: v1 +kind: Secret +metadata: + name: postgres-credentials + labels: + app.kubernetes.io/name: glvd + gardenlinux.io/glvd-component: database +stringData: + username: glvd + password: change-me-i-am-not-secure123 +--- +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: glvd-database + labels: + app.kubernetes.io/name: glvd + gardenlinux.io/glvd-component: database +spec: + replicas: 1 + serviceName: "glvd-database" + selector: + matchLabels: + app.kubernetes.io/name: glvd + gardenlinux.io/glvd-component: database + template: + metadata: + labels: + app.kubernetes.io/name: glvd + gardenlinux.io/glvd-component: database + spec: + containers: + - image: ghcr.io/gardenlinux/glvd-postgres:edgefulldata + name: glvd-postgres + resources: + requests: + cpu: "1" + memory: "2Gi" + limits: + cpu: "2" + memory: "4Gi" + ports: + - containerPort: 5432 + protocol: TCP + name: postgres + env: + - name: POSTGRES_DATABASE + value: glvd + - name: POSTGRES_USER + valueFrom: + secretKeyRef: + name: postgres-credentials + key: username + - name: POSTGRES_PASSWORD + valueFrom: + secretKeyRef: + name: postgres-credentials + key: password + - name: POSTGRES_HOST + value: glvd-postgres + - name: POSTGRES_PORT + value: "5432" + - name: PGDATA + value: /var/lib/postgresql/data/pgdata + volumeMounts: + - mountPath: "/var/lib/postgresql/data" + name: postgres-storage + volumeClaimTemplates: + - metadata: + name: postgres-storage + spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 5Gi + storageClassName: 'default' diff --git a/01-glvd-deployment.yaml b/01-glvd-deployment.yaml deleted file mode 100644 index be3dc9e..0000000 --- a/01-glvd-deployment.yaml +++ /dev/null @@ -1,117 +0,0 @@ -kind: Deployment -apiVersion: apps/v1 -metadata: - labels: - app: glvd - name: glvd -spec: - replicas: 1 - selector: - matchLabels: - app: "glvd" - strategy: {} - template: - metadata: - labels: - app: glvd - spec: - volumes: - - name: glvd-postgres-storage - persistentVolumeClaim: - claimName: glvd-postgres-pvc - containers: - - image: ghcr.io/gardenlinux/glvd-api:edge_bare - name: glvd-api - resources: - requests: - cpu: "1" - memory: "2Gi" - limits: - cpu: "2" - memory: "4Gi" - env: - # cf https://github.com/spring-projects/spring-lifecycle-smoke-tests/tree/main/data/data-jpa#prevent-early-database-interaction - - name: SPRING_DATASOURCE_URL - value: "jdbc:postgresql://localhost:5432/glvd" - - name: SPRING_DATASOURCE_USERNAME - value: glvd - - name: SPRING_DATASOURCE_PASSWORD - valueFrom: - secretKeyRef: - name: postgres-password - key: password - - name: SPRING_JPA_DATABASEPLATFORM - value: "org.hibernate.dialect.PostgreSQLDialect" - - name: SPRING_JPA_PROPERTIES_HIBERNATE_BOOT_ALLOW_JDBC_METADATA_ACCESS - value: "false" - - name: SPRING_JPA_HIBERNATE_DDLAUTO - value: "none" - - name: SPRING_SQL_INIT_MODE - value: "never" - livenessProbe: - httpGet: - path: "/actuator/health/liveness" - port: 8080 - readinessProbe: - httpGet: - path: "/actuator/health/readiness" - port: 8080 - - image: ghcr.io/gardenlinux/glvd-postgres:edgenotls - name: glvd-postgres - resources: - requests: - cpu: "1" - memory: "2Gi" - limits: - cpu: "2" - memory: "4Gi" - ports: - - containerPort: 5432 - hostPort: 5432 - env: - - name: POSTGRES_USER - value: glvd - - name: POSTGRES_DATABASE - value: glvd - - name: POSTGRES_PASSWORD - valueFrom: - secretKeyRef: - name: postgres-password - key: password - - name: POSTGRES_HOST - value: glvd-postgres - - name: POSTGRES_PORT - value: "5432" - - name: PGDATA - value: /var/lib/postgresql/data/pgdata - volumeMounts: - - mountPath: "/var/lib/postgresql/data" - name: glvd-postgres-storage - # TODO: data-ingestion should be running as a cron job - - name: data-ingestion - image: ghcr.io/gardenlinux/glvd:edge - resources: - requests: - cpu: "1" - memory: "2Gi" - limits: - cpu: "2" - memory: "4Gi" - command: - - /bin/bash - - -c - - sleep 5 && echo start && /usr/local/src/ingest-postgres.sh && echo done && sleep infinity - env: - - name: PGUSER - value: glvd - - name: PGDATABASE - value: glvd - - name: PGPASSWORD - valueFrom: - secretKeyRef: - name: postgres-password - key: password - - name: PGHOST - value: localhost - - name: PGPORT - value: "5432" diff --git a/01_glvd-deployment.yaml b/01_glvd-deployment.yaml new file mode 100644 index 0000000..d0943bb --- /dev/null +++ b/01_glvd-deployment.yaml @@ -0,0 +1,118 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: glvd-config + labels: + app.kubernetes.io/name: glvd + gardenlinux.io/glvd-component: glvd-tracker +data: + connectionString: jdbc:postgresql://glvd-database-0.glvd-database:5432/glvd + databaseName: glvd +--- +apiVersion: v1 +kind: Service +metadata: + name: glvd + labels: + app.kubernetes.io/name: glvd + gardenlinux.io/glvd-component: glvd-tracker +spec: + ports: + - port: 8080 + protocol: TCP + targetPort: glvd + selector: + app.kubernetes.io/name: glvd + gardenlinux.io/glvd-component: glvd-tracker + type: ClusterIP +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: glvd + labels: + app.kubernetes.io/name: glvd + gardenlinux.io/glvd-component: glvd-tracker +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/name: glvd + gardenlinux.io/glvd-component: glvd-tracker + template: + metadata: + labels: + app.kubernetes.io/name: glvd + gardenlinux.io/glvd-component: glvd-tracker + spec: + containers: + - image: ghcr.io/gardenlinux/glvd-api:edge + name: glvd-api + # resources: + # requests: + # cpu: "1" + # memory: "2Gi" + # limits: + # cpu: "2" + # memory: "4Gi" + ports: + - containerPort: 8080 + protocol: TCP + name: glvd + env: + # cf https://github.com/spring-projects/spring-lifecycle-smoke-tests/tree/main/data/data-jpa#prevent-early-database-interaction + - name: SPRING_DATASOURCE_URL + valueFrom: + configMapKeyRef: + name: glvd-config + key: connectionString + - name: SPRING_DATASOURCE_USERNAME + valueFrom: + secretKeyRef: + name: postgres-credentials + key: username + - name: SPRING_DATASOURCE_PASSWORD + valueFrom: + secretKeyRef: + name: postgres-credentials + key: password + - name: SPRING_JPA_DATABASEPLATFORM + value: "org.hibernate.dialect.PostgreSQLDialect" + - name: SPRING_JPA_PROPERTIES_HIBERNATE_BOOT_ALLOW_JDBC_METADATA_ACCESS + value: "false" + - name: SPRING_JPA_HIBERNATE_DDLAUTO + value: "none" + - name: SPRING_SQL_INIT_MODE + value: "never" + livenessProbe: + httpGet: + path: "/actuator/health/liveness" + port: 8080 + readinessProbe: + httpGet: + path: "/actuator/health/readiness" + port: 8080 + +--- +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: glvd-api-ingress + annotations: + cert.gardener.cloud/purpose: managed +spec: + rules: + - host: glvd.ingress.glvd.gardnlinux.shoot.canary.k8s-hana.ondemand.com + http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: glvd + port: + number: 8080 + tls: + - hosts: + - glvd.ingress.glvd.gardnlinux.shoot.canary.k8s-hana.ondemand.com + secretName: glvd-ingress-tls diff --git a/02-glvd-service.yaml b/02-glvd-service.yaml deleted file mode 100644 index b00f6d3..0000000 --- a/02-glvd-service.yaml +++ /dev/null @@ -1,14 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - labels: - app: glvd - name: glvd -spec: - ports: - - port: 8080 - protocol: TCP - targetPort: 8080 - selector: - app: glvd - type: LoadBalancer diff --git a/02_ingestion-job.yaml b/02_ingestion-job.yaml new file mode 100644 index 0000000..9ec0653 --- /dev/null +++ b/02_ingestion-job.yaml @@ -0,0 +1,67 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: glvd-ingestion + labels: + app.kubernetes.io/name: glvd + gardenlinux.io/glvd-component: glvd-ingestion +data: + databaseName: glvd + databaseHost: glvd-database-0.glvd-database + databasePort: "5432" +--- +apiVersion: batch/v1 +kind: Job +metadata: + name: glvd-ingestion + labels: + app.kubernetes.io/name: glvd + gardenlinux.io/glvd-component: glvd-ingestion +spec: + template: + metadata: + labels: + app.kubernetes.io/name: glvd + gardenlinux.io/glvd-component: glvd-ingestion + spec: + restartPolicy: OnFailure + containers: + - name: data-ingestion + image: ghcr.io/gardenlinux/glvd:edge + resources: + requests: + cpu: "1" + memory: "2Gi" + limits: + cpu: "2" + memory: "4Gi" + command: + - /bin/bash + - -c + - sleep 5 && echo start && /usr/local/src/ingest-postgres.sh && echo done && sleep infinity + env: + - name: PGDATABASE + valueFrom: + configMapKeyRef: + name: glvd-ingestion + key: databaseName + - name: PGUSER + valueFrom: + secretKeyRef: + name: postgres-credentials + key: username + - name: PGPASSWORD + valueFrom: + secretKeyRef: + name: postgres-credentials + key: password + - name: PGHOST + valueFrom: + configMapKeyRef: + name: glvd-ingestion + key: databaseHost + - name: PGPORT + valueFrom: + configMapKeyRef: + name: glvd-ingestion + key: databasePort From 3dce79b94599102c2b8be5835bb9f4a31b7e4521 Mon Sep 17 00:00:00 2001 From: Florian Wilhelm Date: Thu, 19 Sep 2024 09:27:18 +0200 Subject: [PATCH 5/5] wip --- 00_db-statefulset.yaml | 29 ++--- 01_glvd-deployment.yaml | 2 +- charts/glvd/.helmignore | 23 ++++ charts/glvd/Chart.yaml | 6 + charts/glvd/templates/NOTES.txt | 22 ++++ charts/glvd/templates/_helpers.tpl | 62 ++++++++++ charts/glvd/templates/deployment.yaml | 68 +++++++++++ charts/glvd/templates/hpa.yaml | 32 ++++++ charts/glvd/templates/ingress.yaml | 61 ++++++++++ charts/glvd/templates/service.yaml | 15 +++ charts/glvd/templates/serviceaccount.yaml | 13 +++ .../glvd/templates/tests/test-connection.yaml | 15 +++ charts/glvd/values.yaml | 107 ++++++++++++++++++ 13 files changed, 436 insertions(+), 19 deletions(-) create mode 100644 charts/glvd/.helmignore create mode 100644 charts/glvd/Chart.yaml create mode 100644 charts/glvd/templates/NOTES.txt create mode 100644 charts/glvd/templates/_helpers.tpl create mode 100644 charts/glvd/templates/deployment.yaml create mode 100644 charts/glvd/templates/hpa.yaml create mode 100644 charts/glvd/templates/ingress.yaml create mode 100644 charts/glvd/templates/service.yaml create mode 100644 charts/glvd/templates/serviceaccount.yaml create mode 100644 charts/glvd/templates/tests/test-connection.yaml create mode 100644 charts/glvd/values.yaml diff --git a/00_db-statefulset.yaml b/00_db-statefulset.yaml index 5b1ec5b..a864eec 100644 --- a/00_db-statefulset.yaml +++ b/00_db-statefulset.yaml @@ -17,16 +17,16 @@ spec: type: ClusterIP clusterIP: None --- -apiVersion: v1 -kind: Secret -metadata: - name: postgres-credentials - labels: - app.kubernetes.io/name: glvd - gardenlinux.io/glvd-component: database -stringData: - username: glvd - password: change-me-i-am-not-secure123 +# apiVersion: v1 +# kind: Secret +# metadata: +# name: postgres-credentials +# labels: +# app.kubernetes.io/name: glvd +# gardenlinux.io/glvd-component: database +# stringData: +# username: glvd +# password: change-me-i-am-not-secure123 --- apiVersion: apps/v1 kind: StatefulSet @@ -49,15 +49,8 @@ spec: gardenlinux.io/glvd-component: database spec: containers: - - image: ghcr.io/gardenlinux/glvd-postgres:edgefulldata + - image: ghcr.io/gardenlinux/glvd-postgres:latest name: glvd-postgres - resources: - requests: - cpu: "1" - memory: "2Gi" - limits: - cpu: "2" - memory: "4Gi" ports: - containerPort: 5432 protocol: TCP diff --git a/01_glvd-deployment.yaml b/01_glvd-deployment.yaml index d0943bb..4142bbb 100644 --- a/01_glvd-deployment.yaml +++ b/01_glvd-deployment.yaml @@ -46,7 +46,7 @@ spec: gardenlinux.io/glvd-component: glvd-tracker spec: containers: - - image: ghcr.io/gardenlinux/glvd-api:edge + - image: ghcr.io/gardenlinux/glvd-api:latest name: glvd-api # resources: # requests: diff --git a/charts/glvd/.helmignore b/charts/glvd/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/charts/glvd/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/charts/glvd/Chart.yaml b/charts/glvd/Chart.yaml new file mode 100644 index 0000000..6b90e43 --- /dev/null +++ b/charts/glvd/Chart.yaml @@ -0,0 +1,6 @@ +apiVersion: v2 +name: glvd +description: A Helm chart for glvd +type: application +version: 0.1.0 +appVersion: "0.0.1" diff --git a/charts/glvd/templates/NOTES.txt b/charts/glvd/templates/NOTES.txt new file mode 100644 index 0000000..550b5f5 --- /dev/null +++ b/charts/glvd/templates/NOTES.txt @@ -0,0 +1,22 @@ +1. Get the application URL by running these commands: +{{- if .Values.ingress.enabled }} +{{- range $host := .Values.ingress.hosts }} + {{- range .paths }} + http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }} + {{- end }} +{{- end }} +{{- else if contains "NodePort" .Values.service.type }} + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "glvd.fullname" . }}) + export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") + echo http://$NODE_IP:$NODE_PORT +{{- else if contains "LoadBalancer" .Values.service.type }} + NOTE: It may take a few minutes for the LoadBalancer IP to be available. + You can watch its status by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "glvd.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "glvd.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") + echo http://$SERVICE_IP:{{ .Values.service.port }} +{{- else if contains "ClusterIP" .Values.service.type }} + export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "glvd.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}") + echo "Visit http://127.0.0.1:8080 to use your application" + kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT +{{- end }} diff --git a/charts/glvd/templates/_helpers.tpl b/charts/glvd/templates/_helpers.tpl new file mode 100644 index 0000000..e9301d6 --- /dev/null +++ b/charts/glvd/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "glvd.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "glvd.fullname" -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.nameOverride }} +{{- if contains $name .Release.Name }} +{{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "glvd.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "glvd.labels" -}} +helm.sh/chart: {{ include "glvd.chart" . }} +{{ include "glvd.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "glvd.selectorLabels" -}} +app.kubernetes.io/name: {{ include "glvd.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "glvd.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "glvd.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/charts/glvd/templates/deployment.yaml b/charts/glvd/templates/deployment.yaml new file mode 100644 index 0000000..b6821d7 --- /dev/null +++ b/charts/glvd/templates/deployment.yaml @@ -0,0 +1,68 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "glvd.fullname" . }} + labels: + {{- include "glvd.labels" . | nindent 4 }} +spec: + {{- if not .Values.autoscaling.enabled }} + replicas: {{ .Values.replicaCount }} + {{- end }} + selector: + matchLabels: + {{- include "glvd.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "glvd.labels" . | nindent 8 }} + {{- with .Values.podLabels }} + {{- toYaml . | nindent 8 }} + {{- end }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "glvd.serviceAccountName" . }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: {{ .Chart.Name }} + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - name: http + containerPort: {{ .Values.service.port }} + protocol: TCP + livenessProbe: + {{- toYaml .Values.livenessProbe | nindent 12 }} + readinessProbe: + {{- toYaml .Values.readinessProbe | nindent 12 }} + resources: + {{- toYaml .Values.resources | nindent 12 }} + {{- with .Values.volumeMounts }} + volumeMounts: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.volumes }} + volumes: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/charts/glvd/templates/hpa.yaml b/charts/glvd/templates/hpa.yaml new file mode 100644 index 0000000..43a9a28 --- /dev/null +++ b/charts/glvd/templates/hpa.yaml @@ -0,0 +1,32 @@ +{{- if .Values.autoscaling.enabled }} +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "glvd.fullname" . }} + labels: + {{- include "glvd.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "glvd.fullname" . }} + minReplicas: {{ .Values.autoscaling.minReplicas }} + maxReplicas: {{ .Values.autoscaling.maxReplicas }} + metrics: + {{- if .Values.autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} + {{- end }} + {{- if .Values.autoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + target: + type: Utilization + averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }} + {{- end }} +{{- end }} diff --git a/charts/glvd/templates/ingress.yaml b/charts/glvd/templates/ingress.yaml new file mode 100644 index 0000000..e6aeae1 --- /dev/null +++ b/charts/glvd/templates/ingress.yaml @@ -0,0 +1,61 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "glvd.fullname" . -}} +{{- $svcPort := .Values.service.port -}} +{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }} + {{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }} + {{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className}} + {{- end }} +{{- end }} +{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1 +{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1beta1 +{{- else -}} +apiVersion: extensions/v1beta1 +{{- end }} +kind: Ingress +metadata: + name: {{ $fullName }} + labels: + {{- include "glvd.labels" . | nindent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }} + ingressClassName: {{ .Values.ingress.className }} + {{- end }} + {{- if .Values.ingress.tls }} + tls: + {{- range .Values.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . | quote }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} + {{- end }} + rules: + {{- range .Values.ingress.hosts }} + - host: {{ .host | quote }} + http: + paths: + {{- range .paths }} + - path: {{ .path }} + {{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }} + pathType: {{ .pathType }} + {{- end }} + backend: + {{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }} + service: + name: {{ $fullName }} + port: + number: {{ $svcPort }} + {{- else }} + serviceName: {{ $fullName }} + servicePort: {{ $svcPort }} + {{- end }} + {{- end }} + {{- end }} +{{- end }} diff --git a/charts/glvd/templates/service.yaml b/charts/glvd/templates/service.yaml new file mode 100644 index 0000000..31fbf99 --- /dev/null +++ b/charts/glvd/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "glvd.fullname" . }} + labels: + {{- include "glvd.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + {{- include "glvd.selectorLabels" . | nindent 4 }} diff --git a/charts/glvd/templates/serviceaccount.yaml b/charts/glvd/templates/serviceaccount.yaml new file mode 100644 index 0000000..b43958b --- /dev/null +++ b/charts/glvd/templates/serviceaccount.yaml @@ -0,0 +1,13 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "glvd.serviceAccountName" . }} + labels: + {{- include "glvd.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +automountServiceAccountToken: {{ .Values.serviceAccount.automount }} +{{- end }} diff --git a/charts/glvd/templates/tests/test-connection.yaml b/charts/glvd/templates/tests/test-connection.yaml new file mode 100644 index 0000000..7b01880 --- /dev/null +++ b/charts/glvd/templates/tests/test-connection.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "glvd.fullname" . }}-test-connection" + labels: + {{- include "glvd.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ include "glvd.fullname" . }}:{{ .Values.service.port }}'] + restartPolicy: Never diff --git a/charts/glvd/values.yaml b/charts/glvd/values.yaml new file mode 100644 index 0000000..3d339b5 --- /dev/null +++ b/charts/glvd/values.yaml @@ -0,0 +1,107 @@ +# Default values for glvd. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: nginx + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "" + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +serviceAccount: + # Specifies whether a service account should be created + create: true + # Automatically mount a ServiceAccount's API credentials? + automount: true + # Annotations to add to the service account + annotations: {} + # The name of the service account to use. + # If not set and create is true, a name is generated using the fullname template + name: "" + +podAnnotations: {} +podLabels: {} + +podSecurityContext: {} + # fsGroup: 2000 + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +service: + type: ClusterIP + port: 80 + +ingress: + enabled: false + className: "" + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: chart-example.local + paths: + - path: / + pathType: ImplementationSpecific + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + +resources: {} + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + +livenessProbe: + httpGet: + path: / + port: http +readinessProbe: + httpGet: + path: / + port: http + +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + +# Additional volumes on the output Deployment definition. +volumes: [] +# - name: foo +# secret: +# secretName: mysecret +# optional: false + +# Additional volumeMounts on the output Deployment definition. +volumeMounts: [] +# - name: foo +# mountPath: "/etc/foo" +# readOnly: true + +nodeSelector: {} + +tolerations: [] + +affinity: {}