Skip to content
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

Feature 2368 helm k8s #2427

Merged
merged 50 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
30e9e4c
Initial helm chart for debugging purposes only.
mbjones Apr 18, 2024
d2e833b
Disable Ingress by default to avoid accidental deploys.
mbjones Apr 18, 2024
edda894
add configmap for config.js; git checkout static content
artntek Jun 3, 2024
3756462
doc update
artntek Jun 3, 2024
ea093a1
move pv/pvc yaml and add notes
artntek Jun 5, 2024
11bc6b5
final config.js
artntek Jun 5, 2024
efa461d
get source from official release zip, git, or PVC
artntek Jun 5, 2024
8e99644
move pv/pvc yaml
artntek Jun 5, 2024
8a7fac5
bump chart version
artntek Jun 5, 2024
a09abb8
set mcui version
artntek Jun 5, 2024
23261c6
use mcui version from chart yaml
artntek Jun 5, 2024
d14d29e
Update helm/README.md
artntek Jun 5, 2024
6f30219
adding global values so metacat chart can do overrides
artntek Jun 7, 2024
e887e9c
Merge branch 'feature-2368-helm-k8s' of github.com:NCEAS/metacatui in…
artntek Jun 7, 2024
ccb643e
mount configmap containing install script
artntek Jun 8, 2024
1dade31
last checkin before implementing script installation
artntek Jun 17, 2024
0fc0c4c
Merge branch 'develop' into feature-2368-helm-k8s
artntek Jun 17, 2024
e7c1bd5
not used
artntek Jun 19, 2024
a1ba8be
require theme; make config.js optional
artntek Jun 19, 2024
2f97b4a
handle different roots; autoconfig probes or make optional
artntek Jun 19, 2024
0fdc3b7
fix initContainer
artntek Jun 19, 2024
93fc142
rename for clarity
artntek Jun 19, 2024
da20230
enable pvc for custom theme
artntek Jun 20, 2024
cb1f3e2
example pv/pvc files
artntek Jun 20, 2024
d46df59
update app version
artntek Jul 1, 2024
53fd8c6
Merge branch 'main' into feature-2368-helm-k8s
artntek Jul 1, 2024
4049866
move root to global
artntek Jul 1, 2024
b7f1b4f
Update helm/README.md
artntek Jul 2, 2024
3d7a4e0
Update helm/README.md
artntek Jul 2, 2024
e26dcef
Update helm/README.md
artntek Jul 2, 2024
9e9d3f7
Update helm/README.md
artntek Jul 2, 2024
65183d0
Update helm/README.md
artntek Jul 2, 2024
60c3478
Update helm/admin/metacatui-customtheme-pvc.yaml
artntek Jul 2, 2024
817a12e
Update helm/values.yaml
artntek Jul 2, 2024
5e66f5f
Update helm/admin/metacatui-customtheme-pvc.yaml
artntek Jul 2, 2024
c998b37
Update helm/README.md
artntek Jul 2, 2024
2b6f427
Update helm/README.md
artntek Jul 2, 2024
becc7df
Update helm/README.md
artntek Jul 2, 2024
bfaf760
Update helm/README.md
artntek Jul 2, 2024
9304885
Update helm/README.md
artntek Jul 2, 2024
588f9a3
Update helm/README.md
artntek Jul 2, 2024
991c999
Update helm/README.md
artntek Jul 2, 2024
1101da0
Update helm/values.yaml
artntek Jul 2, 2024
5ea7d76
Update helm/README.md
artntek Jul 2, 2024
2b95d25
Update helm/README.md
artntek Jul 2, 2024
44b7a93
Update helm/README.md
artntek Jul 2, 2024
0d6ea3b
linting errors
artntek Jul 2, 2024
53b6611
add metadata to enable helm push to ghcr
artntek Jul 2, 2024
4f4cdb0
Merge branch 'develop' into feature-2368-helm-k8s
artntek Jul 8, 2024
f75cc64
.prettierignore helm directory contents
artntek Jul 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions helm/.helmignore
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/
24 changes: 24 additions & 0 deletions helm/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: metacatui
description: MetacatUI, a web interface for DataONE repositories

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.5.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "latest"
46 changes: 46 additions & 0 deletions helm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# MetacatUI Helm chart

This is a simple helm chart for debugging a MetacatUI deployment.
artntek marked this conversation as resolved.
Show resolved Hide resolved

## Steps to get started for deployment in a Kubernetes cluster:

1. modify values.yaml as appropriate
2. install the helm chart:
```shell
artntek marked this conversation as resolved.
Show resolved Hide resolved
artntek marked this conversation as resolved.
Show resolved Hide resolved
artntek marked this conversation as resolved.
Show resolved Hide resolved
artntek marked this conversation as resolved.
Show resolved Hide resolved
artntek marked this conversation as resolved.
Show resolved Hide resolved
$ helm -n knb upgrade --install knbmcui ./helm
```
There's no need to set up any persistent storage - the chart will automatically check out the
metacatui static content from GitHub, and install it on an "emptyDir" that is automatically
created for you.
artntek marked this conversation as resolved.
Show resolved Hide resolved


artntek marked this conversation as resolved.
Show resolved Hide resolved
## Steps to get started for development on localhost (e.g. Rancher Desktop/Docker Desktop):

artntek marked this conversation as resolved.
Show resolved Hide resolved
0. Create a namespace `mcui` for the deployment (or pick another of your liking)
1. Create a PV that is mapped to a local `hostPath` directory that contains the web files to deploy
2. Create a PVC for the PV
3. Create a nginx deployment behind an ingress that mounts the PVC where nginx expects its web files to live

artntek marked this conversation as resolved.
Show resolved Hide resolved
To deploy this, you need to 1) create the PV and PVC for your system layout, 2) modify the values.yaml to your hostname for the Ingress definition, and 3) install the helm chart:

```shell
$ helm -n mcui upgrade --install --debug mcui ./helm
Release "mcui" has been upgraded. Happy Helming!
NAME: mcui
LAST DEPLOYED: Wed Apr 17 19:45:58 2024
NAMESPACE: mcui
STATUS: deployed
REVISION: 11
NOTES:
1. Get the application URL by running these commands:
http://firn.local/
```

You can now edit the MetacatUI files and changes will be immediately visible in your chart. You will likely need to edit the `config.js` file to get a minimal setup working. For example, I used the `config/config.js` with these contents:
artntek marked this conversation as resolved.
Show resolved Hide resolved

```javascript
MetacatUI.AppConfig = {
root: "/",
baseUrl: "https://dev.nceas.ucsb.edu/knb/d1/mn"
}
artntek marked this conversation as resolved.
Show resolved Hide resolved
artntek marked this conversation as resolved.
Show resolved Hide resolved
```
18 changes: 18 additions & 0 deletions helm/admin/metacatui-pv.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## EXAMPLE file for manually creating a Persistent Volume to store the metacatui source code,
## typically for development purposes (so edits can be seen in realtime).
## Needed only if 'source.from:' is set to 'pvc' in values.yaml.
##
apiVersion: v1
kind: PersistentVolume
metadata:
name: metacatui-pv
spec:
accessModes:
- ReadWriteOnce
artntek marked this conversation as resolved.
Show resolved Hide resolved
artntek marked this conversation as resolved.
Show resolved Hide resolved
capacity:
storage: 10Gi
hostPath:
path: /your/host/path/here # e.g. /Users/jones/development/metacatui/src
artntek marked this conversation as resolved.
Show resolved Hide resolved
artntek marked this conversation as resolved.
Show resolved Hide resolved
type: ""
persistentVolumeReclaimPolicy: Retain
volumeMode: Filesystem
18 changes: 18 additions & 0 deletions helm/admin/metacatui-pvc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## EXAMPLE file for manually creating a Persistent Volume Claim to access the PV containing the
## metacatui source code (see metacatui-pv.yaml), typically for development purposes.
## Needed only if 'source.from:' is set to 'pvc' in values.yaml.
##
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: metacatui-pvc
namespace: mcui
spec:
accessModes:
- ReadWriteOnce
artntek marked this conversation as resolved.
Show resolved Hide resolved
artntek marked this conversation as resolved.
Show resolved Hide resolved
resources:
requests:
storage: 10Gi
storageClassName: ""
volumeMode: Filesystem
volumeName: metacatui-pv
15 changes: 15 additions & 0 deletions helm/config/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
MetacatUI.AppConfig = {
{{- $ignoreList := list "enabled" "root" "baseUrl" -}}
artntek marked this conversation as resolved.
Show resolved Hide resolved
{{- range $key, $value := .Values.appConfig }}
{{- if not (has $key $ignoreList) }}
{{- if eq (typeOf $value) "string" }}
{{- $key | nindent 4 }}: {{ $value | quote }},
{{- else }}
{{- $key | nindent 4 }}: {{ $value }},
{{- end }}
{{- end }}
{{- end -}}
{{/* These go last, so we can handle the trailing comma */}}
root: {{ required "root is REQUIRED" .Values.appConfig.root | quote }},
baseUrl: {{ required "baseUrl is REQUIRED" .Values.appConfig.baseUrl | quote }}
}
Binary file added helm/templates/.ingress.yaml.swp
Binary file not shown.
22 changes: 22 additions & 0 deletions helm/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -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 "metacatui.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 the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "metacatui.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "metacatui.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 "metacatui.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 }}
62 changes: 62 additions & 0 deletions helm/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "metacatui.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 "metacatui.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 "metacatui.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "metacatui.labels" -}}
helm.sh/chart: {{ include "metacatui.chart" . }}
{{ include "metacatui.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "metacatui.selectorLabels" -}}
app.kubernetes.io/name: {{ include "metacatui.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "metacatui.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "metacatui.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
9 changes: 9 additions & 0 deletions helm/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Load all files in the "config" directory into a ConfigMap
apiVersion: v1
artntek marked this conversation as resolved.
Show resolved Hide resolved
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-metacatui-configjs
artntek marked this conversation as resolved.
Show resolved Hide resolved
artntek marked this conversation as resolved.
Show resolved Hide resolved
labels:
{{- include "metacatui.labels" . | nindent 4 }}
data:
{{ (tpl (.Files.Glob "config/*").AsConfig . ) | nindent 4 }}
123 changes: 123 additions & 0 deletions helm/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
apiVersion: apps/v1
artntek marked this conversation as resolved.
Show resolved Hide resolved
artntek marked this conversation as resolved.
Show resolved Hide resolved
kind: Deployment
metadata:
name: {{ include "metacatui.fullname" . }}
labels:
{{- include "metacatui.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "metacatui.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "metacatui.labels" . | nindent 8 }}
{{- with .Values.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "metacatui.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
{{- if not (eq .Values.source.from "pvc") }}
initContainers:
{{- if (eq .Values.source.from "git") }}
- name: git-clone
image: alpine/git:latest
command:
- sh
- -c
- >
start=$(date +%s);
git clone -b {{ .Values.source.git.revision }} --depth 1 {{ .Values.source.git.repoUrl }} /metacatui;
finish=$(date +%s);
echo "git clone -b {{ .Values.source.git.revision }} took $((finish - start)) sec";
{{- else }}
- name: get-source
image: busybox:latest
command:
- sh
- -c
- >
start=$(date +%s);
FILENAME={{ .Values.source.package.version }}.zip;
wget -O ./$FILENAME {{ .Values.source.package.location }}/$FILENAME;
unzip $FILENAME -d /tmp/;
mv /tmp/metacatui-{{ .Values.source.package.version }}/* /metacatui/;
finish=$(date +%s);
echo "$FILENAME download and install took $((finish - start)) sec";
{{- end }}
volumeMounts:
- name: {{ .Release.Name }}-mcui-source-files
mountPath: /metacatui
{{- end }}
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
{{- with .Values.livenessProbe }}
livenessProbe:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.readinessProbe }}
readinessProbe:
{{- toYaml . | nindent 12 }}
{{- end }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
volumeMounts:
{{- if .Values.appConfig.enabled }}
- name: {{ .Release.Name }}-mcui-config-vol
mountPath: /usr/share/nginx/html/config/config.js
subPath: config.js
{{- end }}
- name: {{ .Release.Name }}-mcui-source-files
mountPath: "/usr/share/nginx/html"
subPath: "src"
{{- with .Values.volumeMounts }}
{{- toYaml . | nindent 12 }}
{{- end }}
volumes:
{{- if .Values.appConfig.enabled }}
- name: {{ .Release.Name }}-mcui-config-vol
configMap:
name: {{ .Release.Name }}-metacatui-configjs
defaultMode: 0644
{{- end }}
{{- if not .Values.source.pvc }}
- name: {{ .Release.Name }}-mcui-source-files
emptyDir: {}
{{- else }}
{{- with .Values.volumes }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- 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 }}
Loading
Loading