From c362bda2b96e4a67c4c6beaeb979cbe17014b7b5 Mon Sep 17 00:00:00 2001 From: 5hubh49 Date: Mon, 30 Dec 2024 02:30:16 +0530 Subject: [PATCH 1/4] WIP: demo wordpress-microservice app --- .../wordpress-microservice/.helmignore | 23 +++++++ .../wordpress-microservice/Chart.lock | 6 ++ .../wordpress-microservice/Chart.yaml | 10 +++ .../manifests/embedded-cluster.yaml | 4 ++ .../manifests/k8s-app.yaml | 10 +++ .../manifests/kots-app.yaml | 14 +++++ .../manifests/wordpress-microservice.yaml | 17 +++++ .../templates/_helpers.tpl | 62 +++++++++++++++++++ .../templates/custom-metrics-config.yaml | 17 +++++ .../templates/mariadb-deployment.yaml | 41 ++++++++++++ .../templates/mariadb-service.yaml | 13 ++++ .../templates/wordpress-deployment.yaml | 39 ++++++++++++ .../templates/wordpress-service.yaml | 14 +++++ .../wordpress-microservice/values.yaml | 38 ++++++++++++ 14 files changed, 308 insertions(+) create mode 100644 applications/wordpress-microservice/.helmignore create mode 100644 applications/wordpress-microservice/Chart.lock create mode 100644 applications/wordpress-microservice/Chart.yaml create mode 100644 applications/wordpress-microservice/manifests/embedded-cluster.yaml create mode 100644 applications/wordpress-microservice/manifests/k8s-app.yaml create mode 100644 applications/wordpress-microservice/manifests/kots-app.yaml create mode 100644 applications/wordpress-microservice/manifests/wordpress-microservice.yaml create mode 100644 applications/wordpress-microservice/templates/_helpers.tpl create mode 100644 applications/wordpress-microservice/templates/custom-metrics-config.yaml create mode 100644 applications/wordpress-microservice/templates/mariadb-deployment.yaml create mode 100644 applications/wordpress-microservice/templates/mariadb-service.yaml create mode 100644 applications/wordpress-microservice/templates/wordpress-deployment.yaml create mode 100644 applications/wordpress-microservice/templates/wordpress-service.yaml create mode 100644 applications/wordpress-microservice/values.yaml diff --git a/applications/wordpress-microservice/.helmignore b/applications/wordpress-microservice/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/applications/wordpress-microservice/.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/applications/wordpress-microservice/Chart.lock b/applications/wordpress-microservice/Chart.lock new file mode 100644 index 0000000..118eeae --- /dev/null +++ b/applications/wordpress-microservice/Chart.lock @@ -0,0 +1,6 @@ +dependencies: +- name: replicated + repository: oci://registry.replicated.com/library + version: 1.0.0-beta.31 +digest: sha256:6d6190e56b76a579495d63a8d757870ddb449edb0ed239b1afe33a6ea363883b +generated: "2024-12-09T03:14:49.379125+05:30" diff --git a/applications/wordpress-microservice/Chart.yaml b/applications/wordpress-microservice/Chart.yaml new file mode 100644 index 0000000..fdd33b9 --- /dev/null +++ b/applications/wordpress-microservice/Chart.yaml @@ -0,0 +1,10 @@ +apiVersion: v2 +name: wordpress-microservice +description: A Helm chart for deploying WordPress with MariaDB +type: application +version: 0.1.1 +appVersion: 1.0.0 +dependencies: +- name: replicated + repository: oci://registry.replicated.com/library + version: 1.0.0-beta.31 diff --git a/applications/wordpress-microservice/manifests/embedded-cluster.yaml b/applications/wordpress-microservice/manifests/embedded-cluster.yaml new file mode 100644 index 0000000..1dc0190 --- /dev/null +++ b/applications/wordpress-microservice/manifests/embedded-cluster.yaml @@ -0,0 +1,4 @@ +apiVersion: embeddedcluster.replicated.com/v1beta1 +kind: Config +spec: + version: 1.19.0+k8s-1.30 diff --git a/applications/wordpress-microservice/manifests/k8s-app.yaml b/applications/wordpress-microservice/manifests/k8s-app.yaml new file mode 100644 index 0000000..0570845 --- /dev/null +++ b/applications/wordpress-microservice/manifests/k8s-app.yaml @@ -0,0 +1,10 @@ +apiVersion: app.k8s.io/v1beta1 +kind: Application +metadata: + name: "wordpress-microservice" +spec: + descriptor: + links: + - description: Open App + # needs to match applicationUrl in kots-app.yaml + url: "http://wordpress-microservice" diff --git a/applications/wordpress-microservice/manifests/kots-app.yaml b/applications/wordpress-microservice/manifests/kots-app.yaml new file mode 100644 index 0000000..8823ea1 --- /dev/null +++ b/applications/wordpress-microservice/manifests/kots-app.yaml @@ -0,0 +1,14 @@ +apiVersion: kots.io/v1beta1 +kind: Application +metadata: + name: wordpress-microservice +spec: + title: Wordpress-Microservice + statusInformers: + - deployment/wordpress-microservice + ports: + - serviceName: "wordpress-microservice" + servicePort: 80 + localPort: 30080 + applicationUrl: "http://wordpress-microservice" + icon: https://raw.githubusercontent.com/cncf/artwork/master/projects/kubernetes/icon/color/kubernetes-icon-color.png diff --git a/applications/wordpress-microservice/manifests/wordpress-microservice.yaml b/applications/wordpress-microservice/manifests/wordpress-microservice.yaml new file mode 100644 index 0000000..03cb11c --- /dev/null +++ b/applications/wordpress-microservice/manifests/wordpress-microservice.yaml @@ -0,0 +1,17 @@ +apiVersion: kots.io/v1beta2 +kind: HelmChart +metadata: + name: wordpress-microservice +spec: + # chart identifies a matching chart from a .tgz + chart: + name: wordpress-microservice + chartVersion: 0.1.1 + optionalValues: + - when: 'repl{{ eq Distribution "embedded-cluster" }}' + recursiveMerge: false + values: + service: + type: NodePort + nodePorts: + http: "30080" diff --git a/applications/wordpress-microservice/templates/_helpers.tpl b/applications/wordpress-microservice/templates/_helpers.tpl new file mode 100644 index 0000000..7c5d316 --- /dev/null +++ b/applications/wordpress-microservice/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "wordpress-microservice.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 "wordpress-microservice.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 "wordpress-microservice.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "wordpress-microservice.labels" -}} +helm.sh/chart: {{ include "wordpress-microservice.chart" . }} +{{ include "wordpress-microservice.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "wordpress-microservice.selectorLabels" -}} +app.kubernetes.io/name: {{ include "wordpress-microservice.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "wordpress-microservice.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "wordpress-microservice.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/applications/wordpress-microservice/templates/custom-metrics-config.yaml b/applications/wordpress-microservice/templates/custom-metrics-config.yaml new file mode 100644 index 0000000..5a0cf84 --- /dev/null +++ b/applications/wordpress-microservice/templates/custom-metrics-config.yaml @@ -0,0 +1,17 @@ +{{- if .Values.customMetrics.enabled }} +apiVersion: v1 +kind: ConfigMap +metadata: + name: custom-metrics-config + labels: + app: {{ .Chart.Name }} +data: + customMetrics.yaml: | + exporters: + {{- range .Values.customMetrics.exporters }} + - name: {{ .name }} + endpoint: {{ .endpoint }} + description: {{ .description }} + interval: {{ .interval }} + {{- end }} +{{- end }} diff --git a/applications/wordpress-microservice/templates/mariadb-deployment.yaml b/applications/wordpress-microservice/templates/mariadb-deployment.yaml new file mode 100644 index 0000000..88b07e7 --- /dev/null +++ b/applications/wordpress-microservice/templates/mariadb-deployment.yaml @@ -0,0 +1,41 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: mariadb + labels: + {{- include "wordpress-microservice.labels" . | nindent 4 }} +spec: + replicas: {{ .Values.mariadb.replicaCount }} + selector: + matchLabels: + app: mariadb + template: + metadata: + labels: + app: mariadb + spec: + containers: + - name: mariadb + image: "{{ .Values.mariadb.image.repository }}:{{ .Values.mariadb.image.tag }}" + imagePullPolicy: {{ .Values.mariadb.image.pullPolicy }} + ports: + - containerPort: 3306 + env: + - name: MYSQL_ROOT_PASSWORD + value: "{{ .Values.mariadb.env.MYSQL_ROOT_PASSWORD }}" + - name: MYSQL_DATABASE + value: "{{ .Values.mariadb.env.MYSQL_DATABASE }}" + - name: MYSQL_USER + value: "{{ .Values.mariadb.env.MYSQL_USER }}" + - name: MYSQL_PASSWORD + value: "{{ .Values.mariadb.env.MYSQL_PASSWORD }}" + +#Use the MySQL Exporter to collect metrics from MariaDB + - name: mysql-exporter + image: prom/mysqld-exporter:latest + env: + - name: DATA_SOURCE_NAME + value: "{{ .Values.mariadb.env.MYSQL_USER }}:{{ .Values.mariadb.env.MYSQL_PASSWORD }}@(127.0.0.1:3306)/{{ .Values.mariadb.env.MYSQL_DATABASE }}" + ports: + - containerPort: 9104 + name: metrics diff --git a/applications/wordpress-microservice/templates/mariadb-service.yaml b/applications/wordpress-microservice/templates/mariadb-service.yaml new file mode 100644 index 0000000..6647e85 --- /dev/null +++ b/applications/wordpress-microservice/templates/mariadb-service.yaml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: Service +metadata: + name: mariadb + labels: + {{- include "wordpress-microservice.labels" . | nindent 4 }} +spec: + type: {{ .Values.mariadb.service.type }} + ports: + - port: {{ .Values.mariadb.service.port }} + targetPort: 3306 + selector: + app: mariadb diff --git a/applications/wordpress-microservice/templates/wordpress-deployment.yaml b/applications/wordpress-microservice/templates/wordpress-deployment.yaml new file mode 100644 index 0000000..5794eeb --- /dev/null +++ b/applications/wordpress-microservice/templates/wordpress-deployment.yaml @@ -0,0 +1,39 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: wordpress + labels: + {{- include "wordpress-microservice.labels" . | nindent 4 }} +spec: + replicas: {{ .Values.wordpress.replicaCount }} + selector: + matchLabels: + app: wordpress + template: + metadata: + labels: + app: wordpress + spec: + containers: + - name: wordpress + image: "{{ .Values.wordpress.image.repository }}:{{ .Values.wordpress.image.tag }}" + imagePullPolicy: {{ .Values.wordpress.image.pullPolicy }} + ports: + - containerPort: 80 + env: + - name: WORDPRESS_DB_HOST + value: "{{ .Values.wordpress.env.WORDPRESS_DB_HOST }}" + - name: WORDPRESS_DB_USER + value: "{{ .Values.wordpress.env.WORDPRESS_DB_USER }}" + - name: WORDPRESS_DB_PASSWORD + value: "{{ .Values.wordpress.env.WORDPRESS_DB_PASSWORD }}" + - name: WORDPRESS_DB_NAME + value: "{{ .Values.wordpress.env.WORDPRESS_DB_NAME }}" + volumeMounts: + - name: custom-metrics-config + mountPath: /etc/custom-metrics + readOnly: true + volumes: + - name: custom-metrics-config + configMap: + name: custom-metrics-config diff --git a/applications/wordpress-microservice/templates/wordpress-service.yaml b/applications/wordpress-microservice/templates/wordpress-service.yaml new file mode 100644 index 0000000..a570289 --- /dev/null +++ b/applications/wordpress-microservice/templates/wordpress-service.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: Service +metadata: + name: wordpress + labels: + {{- include "wordpress-microservice.labels" . | nindent 4 }} +spec: + type: {{ .Values.wordpress.service.type }} + ports: + - port: {{ .Values.wordpress.service.port }} + targetPort: 80 + nodePort: {{ .Values.wordpress.service.nodePort }} + selector: + app: wordpress diff --git a/applications/wordpress-microservice/values.yaml b/applications/wordpress-microservice/values.yaml new file mode 100644 index 0000000..4e51b18 --- /dev/null +++ b/applications/wordpress-microservice/values.yaml @@ -0,0 +1,38 @@ +wordpress: + image: + repository: wordpress + tag: "latest" + pullPolicy: IfNotPresent + service: + type: NodePort + port: 80 + nodePort: 30080 + replicaCount: 1 + env: + WORDPRESS_DB_HOST: mariadb + WORDPRESS_DB_USER: wordpress_user + WORDPRESS_DB_PASSWORD: wordpress_password + WORDPRESS_DB_NAME: wordpress_db + +mariadb: + image: + repository: mariadb + tag: "latest" + pullPolicy: IfNotPresent + service: + type: ClusterIP + port: 3306 + replicaCount: 1 + env: + MYSQL_ROOT_PASSWORD: root_password + MYSQL_DATABASE: wordpress_db + MYSQL_USER: wordpress_user + MYSQL_PASSWORD: wordpress_password + +customMetrics: + enabled: true + exporters: + - name: mariadb-metrics + endpoint: "http://mariadb:9104/metrics" + description: "MariaDB custom metrics" + interval: 30s From 37360b6b2df2cacee2241dfd64fd1d54003bc632 Mon Sep 17 00:00:00 2001 From: 5hubh49 Date: Sat, 11 Jan 2025 02:34:54 +0530 Subject: [PATCH 2/4] feat: add custom-metrics in wordpress app --- .../wordpress-microservice/Chart.yaml | 2 +- .../manifests/kots-app.yaml | 2 +- .../manifests/wordpress-microservice.yaml | 2 +- .../templates/cronjob.yaml | 28 +++++++++++++++++++ .../templates/custom-metrics-config.yaml | 17 ----------- .../templates/mariadb-deployment.yaml | 16 +++++------ .../templates/wordpress-deployment.yaml | 16 +++++------ .../wordpress-microservice/values.yaml | 24 +++++++++++----- 8 files changed, 64 insertions(+), 43 deletions(-) create mode 100644 applications/wordpress-microservice/templates/cronjob.yaml delete mode 100644 applications/wordpress-microservice/templates/custom-metrics-config.yaml diff --git a/applications/wordpress-microservice/Chart.yaml b/applications/wordpress-microservice/Chart.yaml index fdd33b9..f266819 100644 --- a/applications/wordpress-microservice/Chart.yaml +++ b/applications/wordpress-microservice/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v2 name: wordpress-microservice description: A Helm chart for deploying WordPress with MariaDB type: application -version: 0.1.1 +version: 0.1.0 appVersion: 1.0.0 dependencies: - name: replicated diff --git a/applications/wordpress-microservice/manifests/kots-app.yaml b/applications/wordpress-microservice/manifests/kots-app.yaml index 8823ea1..609ccf0 100644 --- a/applications/wordpress-microservice/manifests/kots-app.yaml +++ b/applications/wordpress-microservice/manifests/kots-app.yaml @@ -5,7 +5,7 @@ metadata: spec: title: Wordpress-Microservice statusInformers: - - deployment/wordpress-microservice + - deployment/wordpress ports: - serviceName: "wordpress-microservice" servicePort: 80 diff --git a/applications/wordpress-microservice/manifests/wordpress-microservice.yaml b/applications/wordpress-microservice/manifests/wordpress-microservice.yaml index 03cb11c..5cb623a 100644 --- a/applications/wordpress-microservice/manifests/wordpress-microservice.yaml +++ b/applications/wordpress-microservice/manifests/wordpress-microservice.yaml @@ -6,7 +6,7 @@ spec: # chart identifies a matching chart from a .tgz chart: name: wordpress-microservice - chartVersion: 0.1.1 + chartVersion: 0.1.0 optionalValues: - when: 'repl{{ eq Distribution "embedded-cluster" }}' recursiveMerge: false diff --git a/applications/wordpress-microservice/templates/cronjob.yaml b/applications/wordpress-microservice/templates/cronjob.yaml new file mode 100644 index 0000000..f41fc13 --- /dev/null +++ b/applications/wordpress-microservice/templates/cronjob.yaml @@ -0,0 +1,28 @@ +apiVersion: batch/v1 +kind: CronJob +metadata: + name: {{ .Values.cronjob.name }} + namespace: {{ .Release.Namespace }} +spec: + schedule: "{{ .Values.cronjob.schedule }}" + jobTemplate: + spec: + template: + spec: + containers: + - name: metrics-reporter + image: "{{ .Values.cronjob.image }}" + command: ["sh", "-c"] + args: + - | + totalPosts=$((RANDOM % {{ .Values.cronjob.maxTotalPosts }} + 1)) + activeUsers=$((RANDOM % {{ .Values.cronjob.maxActiveUsers }} + 1)) + curl -X POST {{ .Values.cronjob.metricsEndpoint }} \ + -H "Content-Type: application/json" \ + -d "{ + \"data\": { + \"total_posts\": $totalPosts, + \"active_users\": $activeUsers + } + }" + restartPolicy: OnFailure diff --git a/applications/wordpress-microservice/templates/custom-metrics-config.yaml b/applications/wordpress-microservice/templates/custom-metrics-config.yaml deleted file mode 100644 index 5a0cf84..0000000 --- a/applications/wordpress-microservice/templates/custom-metrics-config.yaml +++ /dev/null @@ -1,17 +0,0 @@ -{{- if .Values.customMetrics.enabled }} -apiVersion: v1 -kind: ConfigMap -metadata: - name: custom-metrics-config - labels: - app: {{ .Chart.Name }} -data: - customMetrics.yaml: | - exporters: - {{- range .Values.customMetrics.exporters }} - - name: {{ .name }} - endpoint: {{ .endpoint }} - description: {{ .description }} - interval: {{ .interval }} - {{- end }} -{{- end }} diff --git a/applications/wordpress-microservice/templates/mariadb-deployment.yaml b/applications/wordpress-microservice/templates/mariadb-deployment.yaml index 88b07e7..1551269 100644 --- a/applications/wordpress-microservice/templates/mariadb-deployment.yaml +++ b/applications/wordpress-microservice/templates/mariadb-deployment.yaml @@ -31,11 +31,11 @@ spec: value: "{{ .Values.mariadb.env.MYSQL_PASSWORD }}" #Use the MySQL Exporter to collect metrics from MariaDB - - name: mysql-exporter - image: prom/mysqld-exporter:latest - env: - - name: DATA_SOURCE_NAME - value: "{{ .Values.mariadb.env.MYSQL_USER }}:{{ .Values.mariadb.env.MYSQL_PASSWORD }}@(127.0.0.1:3306)/{{ .Values.mariadb.env.MYSQL_DATABASE }}" - ports: - - containerPort: 9104 - name: metrics +# - name: mysql-exporter +# image: prom/mysqld-exporter:latest +# env: +# - name: DATA_SOURCE_NAME +# value: "{{ .Values.mariadb.env.MYSQL_USER }}:{{ .Values.mariadb.env.MYSQL_PASSWORD }}@(127.0.0.1:3306)/{{ .Values.mariadb.env.MYSQL_DATABASE }}" +# ports: +# - containerPort: 9104 +# name: metrics diff --git a/applications/wordpress-microservice/templates/wordpress-deployment.yaml b/applications/wordpress-microservice/templates/wordpress-deployment.yaml index 5794eeb..adadc77 100644 --- a/applications/wordpress-microservice/templates/wordpress-deployment.yaml +++ b/applications/wordpress-microservice/templates/wordpress-deployment.yaml @@ -29,11 +29,11 @@ spec: value: "{{ .Values.wordpress.env.WORDPRESS_DB_PASSWORD }}" - name: WORDPRESS_DB_NAME value: "{{ .Values.wordpress.env.WORDPRESS_DB_NAME }}" - volumeMounts: - - name: custom-metrics-config - mountPath: /etc/custom-metrics - readOnly: true - volumes: - - name: custom-metrics-config - configMap: - name: custom-metrics-config +# volumeMounts: +# - name: custom-metrics-config +# mountPath: /etc/custom-metrics +# readOnly: true +# volumes: +# - name: custom-metrics-config +# configMap: +# name: custom-metrics-config diff --git a/applications/wordpress-microservice/values.yaml b/applications/wordpress-microservice/values.yaml index 4e51b18..e2828e7 100644 --- a/applications/wordpress-microservice/values.yaml +++ b/applications/wordpress-microservice/values.yaml @@ -29,10 +29,20 @@ mariadb: MYSQL_USER: wordpress_user MYSQL_PASSWORD: wordpress_password -customMetrics: - enabled: true - exporters: - - name: mariadb-metrics - endpoint: "http://mariadb:9104/metrics" - description: "MariaDB custom metrics" - interval: 30s +#cronjob: +# name: custom-data-reporter +# schedule: "* * * * *" +# image: curlimages/curl:latest +# metricsEndpoint: "http://replicated:3000/api/v1/app/custom-metrics" +# data: +# numProjects: 5 +# weeklyActiveUsers: 10 + +cronjob: + name: custom-data-reporter + schedule: "*/2 * * * *" + image: curlimages/curl:latest + metricsEndpoint: "http://replicated:3000/api/v1/app/custom-metrics" + maxTotalPosts: 500 # Maximum value for totalPosts + maxActiveUsers: 100 # Maximum value for activeUsers + From 478ab1a487dc45efb4e5ef866dc2b5f0bd7ab684 Mon Sep 17 00:00:00 2001 From: 5hubh49 Date: Thu, 23 Jan 2025 09:16:56 +0530 Subject: [PATCH 3/4] feat: Add embedded or external database option --- .../wordpress-microservice/Chart.lock | 2 +- .../wordpress-microservice/Chart.yaml | 4 ++ .../templates/mariadb-deployment.yaml | 49 ++++++++++--------- .../templates/secret.yaml | 13 +++++ .../templates/wordpress-deployment.yaml | 22 ++++----- .../wordpress-microservice/values.yaml | 40 +++++++-------- 6 files changed, 74 insertions(+), 56 deletions(-) create mode 100644 applications/wordpress-microservice/templates/secret.yaml diff --git a/applications/wordpress-microservice/Chart.lock b/applications/wordpress-microservice/Chart.lock index 118eeae..c1c30e7 100644 --- a/applications/wordpress-microservice/Chart.lock +++ b/applications/wordpress-microservice/Chart.lock @@ -3,4 +3,4 @@ dependencies: repository: oci://registry.replicated.com/library version: 1.0.0-beta.31 digest: sha256:6d6190e56b76a579495d63a8d757870ddb449edb0ed239b1afe33a6ea363883b -generated: "2024-12-09T03:14:49.379125+05:30" +generated: "2025-01-23T02:55:34.026894+05:30" diff --git a/applications/wordpress-microservice/Chart.yaml b/applications/wordpress-microservice/Chart.yaml index f266819..6718d87 100644 --- a/applications/wordpress-microservice/Chart.yaml +++ b/applications/wordpress-microservice/Chart.yaml @@ -8,3 +8,7 @@ dependencies: - name: replicated repository: oci://registry.replicated.com/library version: 1.0.0-beta.31 +#- name: mariadb +# version: ">=10.3.0" +# repository: "https://charts.bitnami.com/bitnami" +# condition: database.embedded.mariadb.enabled diff --git a/applications/wordpress-microservice/templates/mariadb-deployment.yaml b/applications/wordpress-microservice/templates/mariadb-deployment.yaml index 1551269..fe855bd 100644 --- a/applications/wordpress-microservice/templates/mariadb-deployment.yaml +++ b/applications/wordpress-microservice/templates/mariadb-deployment.yaml @@ -1,11 +1,11 @@ +{{- if .Values.database.embedded }} apiVersion: apps/v1 kind: Deployment metadata: - name: mariadb - labels: - {{- include "wordpress-microservice.labels" . | nindent 4 }} + name: {{ .Release.Name }}-mariadb + namespace: {{ .Release.Namespace }} spec: - replicas: {{ .Values.mariadb.replicaCount }} + replicas: 1 selector: matchLabels: app: mariadb @@ -16,26 +16,29 @@ spec: spec: containers: - name: mariadb - image: "{{ .Values.mariadb.image.repository }}:{{ .Values.mariadb.image.tag }}" - imagePullPolicy: {{ .Values.mariadb.image.pullPolicy }} - ports: - - containerPort: 3306 + image: mariadb:10.5 env: - - name: MYSQL_ROOT_PASSWORD - value: "{{ .Values.mariadb.env.MYSQL_ROOT_PASSWORD }}" - name: MYSQL_DATABASE - value: "{{ .Values.mariadb.env.MYSQL_DATABASE }}" + valueFrom: + secretKeyRef: + name: {{ .Release.Name }}-db-secret + key: database - name: MYSQL_USER - value: "{{ .Values.mariadb.env.MYSQL_USER }}" + valueFrom: + secretKeyRef: + name: {{ .Release.Name }}-db-secret + key: username - name: MYSQL_PASSWORD - value: "{{ .Values.mariadb.env.MYSQL_PASSWORD }}" - -#Use the MySQL Exporter to collect metrics from MariaDB -# - name: mysql-exporter -# image: prom/mysqld-exporter:latest -# env: -# - name: DATA_SOURCE_NAME -# value: "{{ .Values.mariadb.env.MYSQL_USER }}:{{ .Values.mariadb.env.MYSQL_PASSWORD }}@(127.0.0.1:3306)/{{ .Values.mariadb.env.MYSQL_DATABASE }}" -# ports: -# - containerPort: 9104 -# name: metrics + valueFrom: + secretKeyRef: + name: {{ .Release.Name }}-db-secret + key: password + - name: MARIADB_ROOT_PASSWORD + valueFrom: + secretKeyRef: + name: {{ .Release.Name }}-db-secret + key: root-password + ports: + - containerPort: 3306 + name: mysql +{{- end }} diff --git a/applications/wordpress-microservice/templates/secret.yaml b/applications/wordpress-microservice/templates/secret.yaml new file mode 100644 index 0000000..480ae22 --- /dev/null +++ b/applications/wordpress-microservice/templates/secret.yaml @@ -0,0 +1,13 @@ +{{- if .Values.database.embedded }} +apiVersion: v1 +kind: Secret +metadata: + name: {{ .Release.Name }}-db-secret + namespace: {{ .Release.Namespace }} +type: Opaque +data: + username: {{ .Values.database.user | b64enc }} + password: {{ .Values.database.password | default (randAlphaNum 16) | b64enc }} + root-password: {{ .Values.database.rootPassword | default (randAlphaNum 16) | b64enc }} + database: {{ .Values.database.name | b64enc }} +{{- end }} diff --git a/applications/wordpress-microservice/templates/wordpress-deployment.yaml b/applications/wordpress-microservice/templates/wordpress-deployment.yaml index adadc77..f7e02a0 100644 --- a/applications/wordpress-microservice/templates/wordpress-deployment.yaml +++ b/applications/wordpress-microservice/templates/wordpress-deployment.yaml @@ -22,18 +22,16 @@ spec: - containerPort: 80 env: - name: WORDPRESS_DB_HOST - value: "{{ .Values.wordpress.env.WORDPRESS_DB_HOST }}" + value: "{{ if .Values.database.embedded }}{{ .Release.Name }}-mariadb{{ else }}{{ .Values.database.external.host }}{{ end }}" - name: WORDPRESS_DB_USER - value: "{{ .Values.wordpress.env.WORDPRESS_DB_USER }}" + valueFrom: + secretKeyRef: + name: {{ if .Values.database.embedded }}{{ .Release.Name }}-db-secret{{ else }}{{ .Values.database.external.secretName }}{{ end }} + key: username - name: WORDPRESS_DB_PASSWORD - value: "{{ .Values.wordpress.env.WORDPRESS_DB_PASSWORD }}" + valueFrom: + secretKeyRef: + name: {{ if .Values.database.embedded }}{{ .Release.Name }}-db-secret{{ else }}{{ .Values.database.external.secretName }}{{ end }} + key: password - name: WORDPRESS_DB_NAME - value: "{{ .Values.wordpress.env.WORDPRESS_DB_NAME }}" -# volumeMounts: -# - name: custom-metrics-config -# mountPath: /etc/custom-metrics -# readOnly: true -# volumes: -# - name: custom-metrics-config -# configMap: -# name: custom-metrics-config + value: "{{ .Values.database.name }}" diff --git a/applications/wordpress-microservice/values.yaml b/applications/wordpress-microservice/values.yaml index e2828e7..415e3f3 100644 --- a/applications/wordpress-microservice/values.yaml +++ b/applications/wordpress-microservice/values.yaml @@ -8,11 +8,6 @@ wordpress: port: 80 nodePort: 30080 replicaCount: 1 - env: - WORDPRESS_DB_HOST: mariadb - WORDPRESS_DB_USER: wordpress_user - WORDPRESS_DB_PASSWORD: wordpress_password - WORDPRESS_DB_NAME: wordpress_db mariadb: image: @@ -23,26 +18,31 @@ mariadb: type: ClusterIP port: 3306 replicaCount: 1 - env: - MYSQL_ROOT_PASSWORD: root_password - MYSQL_DATABASE: wordpress_db - MYSQL_USER: wordpress_user - MYSQL_PASSWORD: wordpress_password - -#cronjob: -# name: custom-data-reporter -# schedule: "* * * * *" -# image: curlimages/curl:latest -# metricsEndpoint: "http://replicated:3000/api/v1/app/custom-metrics" -# data: -# numProjects: 5 -# weeklyActiveUsers: 10 +# env: +# MYSQL_ROOT_PASSWORD: root_password +# MYSQL_DATABASE: wordpress_db +# MYSQL_USER: wordpress_user +# MYSQL_PASSWORD: wordpress_password cronjob: name: custom-data-reporter - schedule: "*/2 * * * *" + schedule: "*/5 * * * *" image: curlimages/curl:latest metricsEndpoint: "http://replicated:3000/api/v1/app/custom-metrics" maxTotalPosts: 500 # Maximum value for totalPosts maxActiveUsers: 100 # Maximum value for activeUsers +database: + embedded: true # Set to false to use an external database + name: wordpress_db + user: wordpress_user + password: "" # Auto-generated if left empty for embedded DB + rootPassword: "" # Auto-generated if left empty + host: "" # Empty for embedded DB; required for external DB + port: 3306 # Default MySQL/MariaDB port + + external: # External DB details (only used if embedded: false) + host: "" + user: "" + password: "" + name: "" From 8dd5d576f2aec079ccf8d93af129eb65169c1187 Mon Sep 17 00:00:00 2001 From: 5hubh49 Date: Tue, 4 Feb 2025 00:33:18 +0530 Subject: [PATCH 4/4] some helm app config changes --- applications/wordpress-microservice/Chart.lock | 6 +++--- applications/wordpress-microservice/Chart.yaml | 2 +- .../templates/cronjob.yaml | 3 ++- .../templates/mariadb-service.yaml | 2 +- .../wordpress-microservice/templates/secret.yaml | 16 ++++++++++++++-- applications/wordpress-microservice/values.yaml | 15 +++++++++------ 6 files changed, 30 insertions(+), 14 deletions(-) diff --git a/applications/wordpress-microservice/Chart.lock b/applications/wordpress-microservice/Chart.lock index c1c30e7..9a6abdf 100644 --- a/applications/wordpress-microservice/Chart.lock +++ b/applications/wordpress-microservice/Chart.lock @@ -1,6 +1,6 @@ dependencies: - name: replicated repository: oci://registry.replicated.com/library - version: 1.0.0-beta.31 -digest: sha256:6d6190e56b76a579495d63a8d757870ddb449edb0ed239b1afe33a6ea363883b -generated: "2025-01-23T02:55:34.026894+05:30" + version: 1.0.0 +digest: sha256:347f35218b0b2617efb740acf978b161d0a97b64dcb0349b519bfefa6c10dc76 +generated: "2025-02-03T03:05:00.742181+05:30" diff --git a/applications/wordpress-microservice/Chart.yaml b/applications/wordpress-microservice/Chart.yaml index 6718d87..53cf872 100644 --- a/applications/wordpress-microservice/Chart.yaml +++ b/applications/wordpress-microservice/Chart.yaml @@ -7,7 +7,7 @@ appVersion: 1.0.0 dependencies: - name: replicated repository: oci://registry.replicated.com/library - version: 1.0.0-beta.31 + version: ">=1.0.0-beta.31 <2.0.0" # keeps dependency updated within version 1.x but avoids an automatic upgrade to 2.x #- name: mariadb # version: ">=10.3.0" # repository: "https://charts.bitnami.com/bitnami" diff --git a/applications/wordpress-microservice/templates/cronjob.yaml b/applications/wordpress-microservice/templates/cronjob.yaml index f41fc13..ac78fce 100644 --- a/applications/wordpress-microservice/templates/cronjob.yaml +++ b/applications/wordpress-microservice/templates/cronjob.yaml @@ -11,7 +11,8 @@ spec: spec: containers: - name: metrics-reporter - image: "{{ .Values.cronjob.image }}" + image: "{{ .Values.cronjob.image.registry }}/{{ .Values.cronjob.image.repository }}:{{ .Values.cronjob.image.tag }}" + #image: "{{ .Values.cronjob.image }}" command: ["sh", "-c"] args: - | diff --git a/applications/wordpress-microservice/templates/mariadb-service.yaml b/applications/wordpress-microservice/templates/mariadb-service.yaml index 6647e85..1f1f2e6 100644 --- a/applications/wordpress-microservice/templates/mariadb-service.yaml +++ b/applications/wordpress-microservice/templates/mariadb-service.yaml @@ -10,4 +10,4 @@ spec: - port: {{ .Values.mariadb.service.port }} targetPort: 3306 selector: - app: mariadb + app: wordpress diff --git a/applications/wordpress-microservice/templates/secret.yaml b/applications/wordpress-microservice/templates/secret.yaml index 480ae22..a4d93bb 100644 --- a/applications/wordpress-microservice/templates/secret.yaml +++ b/applications/wordpress-microservice/templates/secret.yaml @@ -7,7 +7,19 @@ metadata: type: Opaque data: username: {{ .Values.database.user | b64enc }} - password: {{ .Values.database.password | default (randAlphaNum 16) | b64enc }} - root-password: {{ .Values.database.rootPassword | default (randAlphaNum 16) | b64enc }} + password: {{- $existingSecret := (lookup "v1" "Secret" .Release.Namespace (printf "%s-db-secret" .Release.Name)) -}} + {{- if and $existingSecret (index $existingSecret "data" "password") -}} + {{- index $existingSecret.data "password" -}} + {{- else -}} + {{ randAlphaNum 16 | b64enc }} + {{- end }} + root-password: + {{- if and $existingSecret (index $existingSecret "data" "root-password") -}} + {{- index $existingSecret.data "root-password" -}} + {{- else -}} + {{ randAlphaNum 16 | b64enc }} + {{- end }} + #password: {{ .Values.database.password | default (randAlphaNum 16) | b64enc }} + #root-password: {{ .Values.database.rootPassword | default (randAlphaNum 16) | b64enc }} database: {{ .Values.database.name | b64enc }} {{- end }} diff --git a/applications/wordpress-microservice/values.yaml b/applications/wordpress-microservice/values.yaml index 415e3f3..a83960c 100644 --- a/applications/wordpress-microservice/values.yaml +++ b/applications/wordpress-microservice/values.yaml @@ -11,23 +11,26 @@ wordpress: mariadb: image: + registry: docker.io repository: mariadb tag: "latest" + #image: + # repository: mariadb + # tag: "latest" pullPolicy: IfNotPresent service: type: ClusterIP port: 3306 replicaCount: 1 -# env: -# MYSQL_ROOT_PASSWORD: root_password -# MYSQL_DATABASE: wordpress_db -# MYSQL_USER: wordpress_user -# MYSQL_PASSWORD: wordpress_password cronjob: name: custom-data-reporter schedule: "*/5 * * * *" - image: curlimages/curl:latest + #image: curlimages/curl:latest + image: + registry: docker.io + repository: curlimages/curl + tag: latest metricsEndpoint: "http://replicated:3000/api/v1/app/custom-metrics" maxTotalPosts: 500 # Maximum value for totalPosts maxActiveUsers: 100 # Maximum value for activeUsers