-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add wordpress-microservice app into this repo #25
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
dependencies: | ||
- name: replicated | ||
repository: oci://registry.replicated.com/library | ||
version: 1.0.0 | ||
digest: sha256:347f35218b0b2617efb740acf978b161d0a97b64dcb0349b519bfefa6c10dc76 | ||
generated: "2025-02-03T03:05:00.742181+05:30" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
apiVersion: v2 | ||
name: wordpress-microservice | ||
description: A Helm chart for deploying WordPress with MariaDB | ||
type: application | ||
version: 0.1.0 | ||
appVersion: 1.0.0 | ||
dependencies: | ||
- name: replicated | ||
repository: oci://registry.replicated.com/library | ||
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" | ||
# condition: database.embedded.mariadb.enabled |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
apiVersion: embeddedcluster.replicated.com/v1beta1 | ||
kind: Config | ||
spec: | ||
version: 1.19.0+k8s-1.30 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
apiVersion: kots.io/v1beta1 | ||
kind: Application | ||
metadata: | ||
name: wordpress-microservice | ||
spec: | ||
title: Wordpress-Microservice | ||
statusInformers: | ||
- deployment/wordpress | ||
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.0 | ||
optionalValues: | ||
- when: 'repl{{ eq Distribution "embedded-cluster" }}' | ||
recursiveMerge: false | ||
values: | ||
service: | ||
type: NodePort | ||
nodePorts: | ||
http: "30080" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
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.registry }}/{{ .Values.cronjob.image.repository }}:{{ .Values.cronjob.image.tag }}" | ||
#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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{{- if .Values.database.embedded }} | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A few things to mention here:
|
||
metadata: | ||
name: {{ .Release.Name }}-mariadb | ||
namespace: {{ .Release.Namespace }} | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: mariadb | ||
template: | ||
metadata: | ||
labels: | ||
app: mariadb | ||
spec: | ||
containers: | ||
- name: mariadb | ||
image: mariadb:10.5 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a best practice to give users the flexibility to override different parts of the image. For example, someone may need to change the registry that's used, but might want to use the default tag that you specify in the chart. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
env: | ||
- name: MYSQL_DATABASE | ||
valueFrom: | ||
secretKeyRef: | ||
name: {{ .Release.Name }}-db-secret | ||
key: database | ||
- name: MYSQL_USER | ||
valueFrom: | ||
secretKeyRef: | ||
name: {{ .Release.Name }}-db-secret | ||
key: username | ||
- name: MYSQL_PASSWORD | ||
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 }} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: wordpress |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{{- 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: {{- $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 }} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same feedback i gave on the other Deployment objects applies here as well. |
||
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: "{{ if .Values.database.embedded }}{{ .Release.Name }}-mariadb{{ else }}{{ .Values.database.external.host }}{{ end }}" | ||
- name: 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 | ||
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.database.name }}" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use a helper function instead of hardcoding |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
wordpress: | ||
image: | ||
repository: wordpress | ||
tag: "latest" | ||
pullPolicy: IfNotPresent | ||
service: | ||
type: NodePort | ||
port: 80 | ||
nodePort: 30080 | ||
replicaCount: 1 | ||
|
||
mariadb: | ||
image: | ||
registry: docker.io | ||
repository: mariadb | ||
tag: "latest" | ||
#image: | ||
# repository: mariadb | ||
# tag: "latest" | ||
pullPolicy: IfNotPresent | ||
service: | ||
type: ClusterIP | ||
port: 3306 | ||
replicaCount: 1 | ||
|
||
cronjob: | ||
name: custom-data-reporter | ||
schedule: "*/5 * * * *" | ||
#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 | ||
|
||
database: | ||
embedded: true # Set to false to use an external database | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see you have the conditional for embedded vs. external but i don't see any option to provide a URI or an existing secret for connecting to that 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: "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few things to consider in this resource.
Keep in mind to support airgap deployments or deployments using the registry proxy that you'll need additional templating for the images to make that work. Something that you can follow up on in a future story or decide to add in this PR. I'd say generally give a look at the documenation for configuring this resource - https://docs.replicated.com/vendor/helm-native-v2-using
It's also a good practice to use
helmUpgradeFlags
to specify a timeout and/or the--wait
flag for the charts that you install. See - https://docs.replicated.com/reference/custom-resource-helmchart-v2#helmupgradeflags