From 2c2ce69328eece474e86b493118cf2dff1212460 Mon Sep 17 00:00:00 2001 From: Phong Nguyen Date: Mon, 6 May 2024 16:02:39 +0700 Subject: [PATCH] create memgraph-lab chart (#18) Add Memgraph-lab helm chart. --- .pre-commit-config.yaml | 2 +- CONTRIBUTING.md | 2 +- README.md | 17 ++++ charts/memgraph-lab/.helmignore | 23 +++++ charts/memgraph-lab/Chart.yaml | 23 +++++ charts/memgraph-lab/README.md | 51 ++++++++++ charts/memgraph-lab/templates/NOTES.txt | 26 ++++++ charts/memgraph-lab/templates/_helpers.tpl | 62 +++++++++++++ charts/memgraph-lab/templates/deployment.yaml | 69 ++++++++++++++ charts/memgraph-lab/templates/hpa.yaml | 32 +++++++ charts/memgraph-lab/templates/ingress.yaml | 61 ++++++++++++ charts/memgraph-lab/templates/service.yaml | 19 ++++ .../templates/serviceaccount.yaml | 12 +++ .../templates/tests/test-connection.yaml | 15 +++ charts/memgraph-lab/values.yaml | 93 +++++++++++++++++++ 15 files changed, 505 insertions(+), 2 deletions(-) create mode 100644 charts/memgraph-lab/.helmignore create mode 100644 charts/memgraph-lab/Chart.yaml create mode 100644 charts/memgraph-lab/README.md create mode 100644 charts/memgraph-lab/templates/NOTES.txt create mode 100644 charts/memgraph-lab/templates/_helpers.tpl create mode 100644 charts/memgraph-lab/templates/deployment.yaml create mode 100644 charts/memgraph-lab/templates/hpa.yaml create mode 100644 charts/memgraph-lab/templates/ingress.yaml create mode 100644 charts/memgraph-lab/templates/service.yaml create mode 100644 charts/memgraph-lab/templates/serviceaccount.yaml create mode 100644 charts/memgraph-lab/templates/tests/test-connection.yaml create mode 100644 charts/memgraph-lab/values.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 35a3feb..10e9587 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,7 +5,7 @@ repos: - id: trailing-whitespace - id: end-of-file-fixer - id: check-yaml - exclude: ^charts/memgraph/templates/ + exclude: ^charts/(memgraph|memgraph-lab)/templates/ - id: check-json - id: mixed-line-ending - id: check-merge-conflict diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 76c6811..f955a55 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -34,7 +34,7 @@ There are two main types of contributions: 1. **Bug fixes** 2. **New features** -Both types of fixes should be applied to the `main` branch. +Both types of fixes should be applied to the `release` branch, that is currently active based on the upcoming [milestone](https://github.com/memgraph/helm-charts/milestone/2) for example `release-0.1.3` branch. In order for a pull request to be merged, a review by two code owners is required and the tests need to pass remotely. diff --git a/README.md b/README.md index 3fc853a..16f62f4 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ Welcome to the Memgraph Helm Charts repository. This repository provides Helm ch ## Available charts - [**Memgraph standalone**](#memgraph-standalone) +- [**Memgraph Lab**](#memgraph-lab) ## Prerequisites Helm version 3 or above installed. @@ -42,6 +43,22 @@ Once Memgraph is installed, you can access it using the provided services and en To upgrade or uninstall a deployed Memgraph release, you can use the `helm upgrade` or `helm uninstall` commands, respectively. Refer to the [Helm documentation](https://helm.sh/docs/) for more details on these commands. +## Memgraph lab +Deploys Memgraph Lab. +For detailed information and usage instructions, please refer to the [chart's individual README file](./charts/memgraph-lab/README.md). + +To install Memgraph Lab, run the following command: + +``` +helm install my-release memgraph/memgraph-lab +``` +Replace `my-release` with a name of your choice for the release. + + +Refer to the [Data visualization in Memgraph Lab](https://memgraph.com/docs/data-visualization) for details on how to connect to and interact with Memgraph. + +To upgrade or uninstall a deployed Memgraph release, you can use the `helm upgrade` or `helm uninstall` commands, respectively. Refer to the [Helm documentation](https://helm.sh/docs/) for more details on these commands. + ## Contributing Contributions are welcome! If you have any improvements, bug fixes, or new charts to add, please follow the contribution guidelines outlined in the [`CONTRIBUTING.md`](https://github.com/memgraph/helm-charts/blob/main/CONTRIBUTING.md) file. If you have questions and are unsure of how to contribute, please join our Discord server to get in touch with us. diff --git a/charts/memgraph-lab/.helmignore b/charts/memgraph-lab/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/charts/memgraph-lab/.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/memgraph-lab/Chart.yaml b/charts/memgraph-lab/Chart.yaml new file mode 100644 index 0000000..79ab84f --- /dev/null +++ b/charts/memgraph-lab/Chart.yaml @@ -0,0 +1,23 @@ +apiVersion: v2 +name: memgraph-lab +home: https://memgraph.com/ +type: application +# Chart version, should be incremented each time the chart changes, including appVersion. +version: 0.1.0 +# Version number of the docker image memgraph/lab. +# Use it with quotes. +appVersion: "2.13.0" +description: Memgraph Lab Helm Chart +keywords: +- graph +- database +- cypher +- analytics +icon: https://public-assets.memgraph.com/memgraph-logo/logo-large.png +sources: +- https://github.com/memgraph/memgraph +maintainers: +- name: Memgraph + email: tech@memgraph.com +- name: Phong Nguyen + email: tewnut@gmail.com diff --git a/charts/memgraph-lab/README.md b/charts/memgraph-lab/README.md new file mode 100644 index 0000000..cae70a0 --- /dev/null +++ b/charts/memgraph-lab/README.md @@ -0,0 +1,51 @@ +## Memgraph Lab Kubernetes Helm Chart +A Helm Chart for deploying Memgraph Lab on Kubernetes. + +## Installing the Memgraph Lab Helm Chart +To install the Memgraph Lab Helm Chart, follow the steps below: +``` +helm install memgraph/memgraph-lab +``` +Replace `` with a name of your choice for the release. + +## Changing the default chart values +To change the default chart values, run the command with the specified set of flags: +``` +helm install memgraph/memgraph-lab --set =,=,... +``` +Or you can modify a `values.yaml` file and override the desired values: +``` +helm install memgraph/memgraph-lab -f values.yaml +``` + +## Configuration Options + +The following table lists the configurable parameters of the Memgraph Lab chart and their default values. + +| Parameter | Description | Default | +| ---------------------------- | ------------------------------------------------------------------------------------------------------- | -------------------------------------- | +| `image.repository` | Memgraph Lab Docker image repository | `memgraph/memgraph-lab` | +| `image.tag` | Specific tag for the Memgraph Lab Docker image. Overrides the image tag whose default is chart version. | `""` (Defaults to chart's app version) | +| `image.pullPolicy` | Image pull policy | `IfNotPresent` | +| `replicaCount` | Number of Memgraph Lab instances to run. | `1` | +| `service.type` | Kubernetes service type | `ClusterIP` | +| `service.port` | Kubernetes service port | `3000` | +| `service.targetPort` | Kubernetes service target port | `3000` | +| `service.protocol` | Protocol used by the service | `TCP` | +| `service.annotations` | Annotations to add to the service | `{}` | +| `podAnnotations` | Annotations to add to the pod | `{}` | +| `resources` | CPU/Memory resource requests/limits. Left empty by default. | `{}` (See note on uncommenting) | +| `serviceAccount.create` | Specifies whether a service account should be created | `true` | +| `serviceAccount.annotations` | Annotations to add to the service account | `{}` | +| `serviceAccount.name` | The name of the service account to use. If not set and create is true, a name is generated. | `""` | + +Memgraph Lab can be further configured with environment variables in your `values.yaml` file. + +```yaml +env: + - name: QUICK_CONNECT_MG_HOST + value: memgraph + - name: QUICK_CONNECT_MG_PORT + value: "7687" +``` +Check all supported environment variables from the Memgraph website, [Data Visualization Section](https://memgraph.com/docs/data-visualization/install-and-connect#environment-variables) diff --git a/charts/memgraph-lab/templates/NOTES.txt b/charts/memgraph-lab/templates/NOTES.txt new file mode 100644 index 0000000..b278baf --- /dev/null +++ b/charts/memgraph-lab/templates/NOTES.txt @@ -0,0 +1,26 @@ +Thank you for installing Memgraph Lab! 🎉 + +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 "memgraph-lab.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 "memgraph-lab.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "memgraph-lab.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 "memgraph-lab.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 }} + +2. Specify your MemgraphDB instance ip address and port in Memgraph Lab GUI. diff --git a/charts/memgraph-lab/templates/_helpers.tpl b/charts/memgraph-lab/templates/_helpers.tpl new file mode 100644 index 0000000..7f98280 --- /dev/null +++ b/charts/memgraph-lab/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "memgraph-lab.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 "memgraph-lab.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 "memgraph-lab.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "memgraph-lab.labels" -}} +helm.sh/chart: {{ include "memgraph-lab.chart" . }} +{{ include "memgraph-lab.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "memgraph-lab.selectorLabels" -}} +app.kubernetes.io/name: {{ include "memgraph-lab.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "memgraph-lab.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "memgraph-lab.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/charts/memgraph-lab/templates/deployment.yaml b/charts/memgraph-lab/templates/deployment.yaml new file mode 100644 index 0000000..bc40420 --- /dev/null +++ b/charts/memgraph-lab/templates/deployment.yaml @@ -0,0 +1,69 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "memgraph-lab.fullname" . }} + labels: + {{- include "memgraph-lab.labels" . | nindent 4 }} +spec: + {{- if not .Values.autoscaling.enabled }} + replicas: {{ .Values.replicaCount }} + {{- end }} + selector: + matchLabels: + {{- include "memgraph-lab.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "memgraph-lab.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "memgraph-lab.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: + httpGet: + path: / + port: http + readinessProbe: + httpGet: + path: / + port: http + resources: + {{- toYaml .Values.resources | nindent 12 }} + {{- with .Values.env }} + env: + {{- range . }} + - name: {{ .name }} + value: "{{ .value }}" + {{- 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 }} diff --git a/charts/memgraph-lab/templates/hpa.yaml b/charts/memgraph-lab/templates/hpa.yaml new file mode 100644 index 0000000..471df08 --- /dev/null +++ b/charts/memgraph-lab/templates/hpa.yaml @@ -0,0 +1,32 @@ +{{- if .Values.autoscaling.enabled }} +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "memgraph-lab.fullname" . }} + labels: + {{- include "memgraph-lab.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "memgraph-lab.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/memgraph-lab/templates/ingress.yaml b/charts/memgraph-lab/templates/ingress.yaml new file mode 100644 index 0000000..56dcd9d --- /dev/null +++ b/charts/memgraph-lab/templates/ingress.yaml @@ -0,0 +1,61 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "memgraph-lab.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 "memgraph-lab.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/memgraph-lab/templates/service.yaml b/charts/memgraph-lab/templates/service.yaml new file mode 100644 index 0000000..7634ce1 --- /dev/null +++ b/charts/memgraph-lab/templates/service.yaml @@ -0,0 +1,19 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "memgraph-lab.fullname" . }} + labels: + {{- include "memgraph-lab.labels" . | nindent 4 }} + {{- with .Values.service.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + {{- include "memgraph-lab.selectorLabels" . | nindent 4 }} diff --git a/charts/memgraph-lab/templates/serviceaccount.yaml b/charts/memgraph-lab/templates/serviceaccount.yaml new file mode 100644 index 0000000..d10f4bd --- /dev/null +++ b/charts/memgraph-lab/templates/serviceaccount.yaml @@ -0,0 +1,12 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "memgraph-lab.serviceAccountName" . }} + labels: + {{- include "memgraph-lab.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} diff --git a/charts/memgraph-lab/templates/tests/test-connection.yaml b/charts/memgraph-lab/templates/tests/test-connection.yaml new file mode 100644 index 0000000..bfe2aa3 --- /dev/null +++ b/charts/memgraph-lab/templates/tests/test-connection.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "memgraph-lab.fullname" . }}-test-connection" + labels: + {{- include "memgraph-lab.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ include "memgraph-lab.fullname" . }}:{{ .Values.service.port }}'] + restartPolicy: Never diff --git a/charts/memgraph-lab/values.yaml b/charts/memgraph-lab/values.yaml new file mode 100644 index 0000000..16b6cf3 --- /dev/null +++ b/charts/memgraph-lab/values.yaml @@ -0,0 +1,93 @@ +image: + repository: memgraph/lab + # Overrides the image tag whose default is v{{ .Chart.AppVersion }} + tag: "" + pullPolicy: IfNotPresent + +replicaCount: 1 + +service: + type: ClusterIP + port: 3000 + targetPort: 3000 + protocol: TCP + annotations: {} + +# Annotations to add to the statefulSet +statefulSetAnnotations: {} +# Annotations to add to the Pod +podAnnotations: {} + +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 + +serviceAccount: + # Specifies whether a service account should be created + create: 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: "" + + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +# Supported env variables: https://memgraph.com/docs/data-visualization/install-and-connect#environment-variables +env: + - name: QUICK_CONNECT_MG_HOST + value: memgraph + - name: QUICK_CONNECT_MG_PORT + value: "7687" + +podSecurityContext: {} + # fsGroup: 2000 + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +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 + + +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + +nodeSelector: {} + +tolerations: [] + +affinity: {}