From 5ec18e9521038afd02bdb726d08bcab2327d8eaf Mon Sep 17 00:00:00 2001 From: Phong Nguyen Date: Mon, 6 May 2024 16:02:39 +0700 Subject: [PATCH 1/6] 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: {} From 7d2fb81fea49033c8b3e207df6e11a2a0724dcf9 Mon Sep 17 00:00:00 2001 From: Ante Javor Date: Thu, 16 May 2024 12:17:36 +0200 Subject: [PATCH 2/6] Memgraph high-availabilty chart (#19) In this PR we are introducing the first version of Memgraph in HA config. Memgraph HA cluster includes 3 coordinators, 2 data instances by default. The cluster setup is performed via the cluster-setup job. --------- Co-authored-by: Andi Skrgat --- .pre-commit-config.yaml | 2 +- README.md | 20 +++ charts/memgraph-high-availability/.helmignore | 23 ++++ charts/memgraph-high-availability/Chart.yaml | 29 +++++ charts/memgraph-high-availability/README.md | 72 +++++++++++ .../templates/NOTES.txt | 15 +++ .../templates/_helpers.tpl | 44 +++++++ .../templates/cluster-setup.yaml | 51 ++++++++ .../templates/coordinators.yaml | 116 +++++++++++++++++ .../templates/data.yaml | 118 ++++++++++++++++++ .../templates/services-coordinators.yaml | 39 ++++++ .../templates/services-data.yaml | 43 +++++++ .../templates/tests/test-cluster-setup.yaml | 53 ++++++++ .../templates/tests/test-connection.yaml | 29 +++++ charts/memgraph-high-availability/values.yaml | 100 +++++++++++++++ 15 files changed, 753 insertions(+), 1 deletion(-) create mode 100644 charts/memgraph-high-availability/.helmignore create mode 100644 charts/memgraph-high-availability/Chart.yaml create mode 100644 charts/memgraph-high-availability/README.md create mode 100644 charts/memgraph-high-availability/templates/NOTES.txt create mode 100644 charts/memgraph-high-availability/templates/_helpers.tpl create mode 100644 charts/memgraph-high-availability/templates/cluster-setup.yaml create mode 100644 charts/memgraph-high-availability/templates/coordinators.yaml create mode 100644 charts/memgraph-high-availability/templates/data.yaml create mode 100644 charts/memgraph-high-availability/templates/services-coordinators.yaml create mode 100644 charts/memgraph-high-availability/templates/services-data.yaml create mode 100644 charts/memgraph-high-availability/templates/tests/test-cluster-setup.yaml create mode 100644 charts/memgraph-high-availability/templates/tests/test-connection.yaml create mode 100644 charts/memgraph-high-availability/values.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 10e9587..947699f 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|memgraph-lab)/templates/ + exclude: ^charts/(memgraph|memgraph-lab|memgraph-high-availability)/templates/ - id: check-json - id: mixed-line-ending - id: check-merge-conflict diff --git a/README.md b/README.md index 16f62f4..5426d10 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ Welcome to the Memgraph Helm Charts repository. This repository provides Helm ch ## Available charts - [**Memgraph standalone**](#memgraph-standalone) - [**Memgraph Lab**](#memgraph-lab) +- [**Memgraph high availability](#memgraph-high-availability) ## Prerequisites Helm version 3 or above installed. @@ -59,6 +60,25 @@ Refer to the [Data visualization in Memgraph Lab](https://memgraph.com/docs/data 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 high availability +Deploys high available Memgraph cluster, that includes two data instances and three coordinators. + +For detailed information and usage instructions, please refer to the [chart's individual README file](./charts/memgraph/README.md). + +To install Memgraph standalone, run the following command: + +``` +helm install my-release memgraph/memgraph-high-availability --set memgraph.env.MEMGRAPH_ENTERPRISE_LICENSE=,memgraph.env.MEMGRAPH_ORGANIZATION_NAME= +``` +Replace `my-release` with a name of your choice for the release. + + +Once Memgraph cluster is up and running, you can access it using the provided services and endpoints. Refer to the [Memgraph documentation](https://memgraph.com/docs/memgraph/connect-to-memgraph) 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-high-availability/.helmignore b/charts/memgraph-high-availability/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/charts/memgraph-high-availability/.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-high-availability/Chart.yaml b/charts/memgraph-high-availability/Chart.yaml new file mode 100644 index 0000000..23525e5 --- /dev/null +++ b/charts/memgraph-high-availability/Chart.yaml @@ -0,0 +1,29 @@ +apiVersion: v2 +name: memgraph-high-availability +description: A Helm chart for Kubernetes with Memgraph High availabiliy capabilites + +version: 0.1.0 +appVersion: "2.17.0" + +type: application + +keywords: +- memgraph +- graph +- database +- cypher +- analytics +- high-availability + +icon: https://public-assets.memgraph.com/memgraph-logo/logo-large.png + +home: https://memgraph.com/ + +sources: +- "https://github.com/memgraph/memgraph" +- "https://github.com/memgraph/helm-charts" + + +maintainers: +- name: Memgraph + email: tech@memgraph.com diff --git a/charts/memgraph-high-availability/README.md b/charts/memgraph-high-availability/README.md new file mode 100644 index 0000000..51010ae --- /dev/null +++ b/charts/memgraph-high-availability/README.md @@ -0,0 +1,72 @@ +## Memgraph high availability Kubernetes Helm Chart +A Helm Chart for deploying Memgraph in [high-availability setup](https://memgraph.com/docs/clustering/high-availability). + +Memgraph HA cluster includes 3 coordinators, 2 data instances by default. The cluster setup is performed via the cluster-setup job. The HA cluster is still work in progress and started with "--experimental-enabled=high-availability". +The cluster is started in the configuration without the node selector, which means that in the current configuration, it is not highly available if the node fails. + +## Installing the Memgraph Helm Chart +To install the Memgraph HA Helm Chart, follow the steps below: +``` +helm install memgraph/memgraph-high-availability --set memgraph.env.MEMGRAPH_ENTERPRISE_LICENSE=,memgraph.env.MEMGRAPH_ORGANIZATION_NAME= +``` +Replace `` with a name of your choice for the release and set the enterprise license. + +## Changing the default chart values +To change the default chart values, run the command with the specified set of flags: +``` +helm install memgraph/memgraph-high-availability --set =,=,... +``` +Or you can modify a `values.yaml` file and override the desired values: +``` +helm install memgraph/memgraph-high-availability-f values.yaml +``` + + +## Configuration Options + +The following table lists the configurable parameters of the Memgraph chart and their default values. + +| Parameter | Description | Default | +|---------------------------------------------|-----------------------------------------------------------------------------------------------------|-----------------------------------------| +| `memgraph.image.repository` | Memgraph Docker image repository | `memgraph/memgraph` | +| `memgraph.image.tag` | Specific tag for the Memgraph Docker image. Overrides the image tag whose default is chart version. | `2.17.0` | +| `memgraph.image.pullPolicy` | Image pull policy | `IfNotPresent` | +| `memgraph.env.MEMGRAPH_ENTERPRISE_LICENSE` | Memgraph enterprise license | `` | +| `memgraph.env.MEMGRAPH_ORGANIZATION_NAME` | Organization name | `` | +| `memgraph.probes.startup.failureThreshold` | Startup probe failure threshold | `30` | +| `memgraph.probes.startup.periodSeconds` | Startup probe period in seconds | `10` | +| `memgraph.probes.readiness.initialDelaySeconds` | Readiness probe initial delay in seconds | `5` | +| `memgraph.probes.readiness.periodSeconds` | Readiness probe period in seconds | `5` | +| `memgraph.probes.liveness.initialDelaySeconds` | Liveness probe initial delay in seconds | `30` | +| `memgraph.probes.liveness.periodSeconds` | Liveness probe period in seconds | `10` | +| `memgraph.data.volumeClaim.storagePVC` | Enable storage PVC | `true` | +| `memgraph.data.volumeClaim.storagePVCSize` | Size of the storage PVC | `1Gi` | +| `memgraph.data.volumeClaim.logPVC` | Enable log PVC | `false` | +| `memgraph.data.volumeClaim.logPVCSize` | Size of the log PVC | `256Mi` | +| `memgraph.coordinators.volumeClaim.storagePVC` | Enable storage PVC for coordinators | `true` | +| `memgraph.coordinators.volumeClaim.storagePVCSize` | Size of the storage PVC for coordinators | `1Gi` | +| `memgraph.coordinators.volumeClaim.logPVC` | Enable log PVC for coordinators | `false` | +| `memgraph.coordinators.volumeClaim.logPVCSize` | Size of the log PVC for coordinators | `256Mi` | +| `data` | Configuration for data instances | See `data` section | +| `coordinators` | Configuration for coordinator instances | See `coordinators` section | + +For the `data` and `coordinators` sections, each item in the list has the following parameters: + +| Parameter | Description | Default | +|---------------------------------------------|-----------------------------------------------------------------------------------------------------|-----------------------------------------| +| `id` | ID of the instance | `0` for data, `1` for coordinators | +| `boltPort` | Bolt port of the instance | `7687` | +| `managementPort` (data only) | Management port of the data instance | `10000` | +| `replicationPort` (data only) | Replication port of the data instance | `20000` | +| `coordinatorPort` (coordinators only) | Coordinator port of the coordinator instance | `12000` | +| `args` | List of arguments for the instance | See `args` section | + +The `args` section contains a list of arguments for the instance. The default values are the same for all instances: + +```markdown +- "--also-log-to-stderr" +- "--log-level=TRACE" +- "--replication-restore-state-on-startup=true" +``` + +For all available database settings, refer to the [Configuration settings reference guide](https://memgraph.com/docs/memgraph/reference-guide/configuration). diff --git a/charts/memgraph-high-availability/templates/NOTES.txt b/charts/memgraph-high-availability/templates/NOTES.txt new file mode 100644 index 0000000..71f966a --- /dev/null +++ b/charts/memgraph-high-availability/templates/NOTES.txt @@ -0,0 +1,15 @@ +Thank you for installing the Memgraph High-availability cluster! 🎉 + +Memgraph HA cluster includes 3 coordinators, 2 data instances by default. The cluster setup is performed via the cluster-setup job. The HA cluster is still work in progress and started with "--experimental-enabled=high-availability". +The cluster is started in the configuration without the node selector, which means that in the current configuration, it is not highly available if the node fails. + +The cluster setup requires the proper enterprise license to work since HA is an enterprise feature. + +You can connect to Memgraph instances via Lab, mgconsole, or any other client. By default, all Memgraph instances (coordinators and data instances) listen on port 7687 for a bolt connection. +Make sure your are connecting to the correct ip address and port. For details check the configuration on your cloud provider(aws, gcp, azure, etc.) + +If you are connecting via mgconsole, you can use the following command: + +mgconsole --host --port + +If you are connecting via Lab, specify your instance IP address and port in Memgraph Lab GUI. diff --git a/charts/memgraph-high-availability/templates/_helpers.tpl b/charts/memgraph-high-availability/templates/_helpers.tpl new file mode 100644 index 0000000..c43a5d1 --- /dev/null +++ b/charts/memgraph-high-availability/templates/_helpers.tpl @@ -0,0 +1,44 @@ + +{{/* Full name of the application */}} +{{- define "memgraph.fullname" -}} +{{- if .Values.fullnameOverride -}} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else -}} +{{- $name := default .Chart.Name .Values.nameOverride -}} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end -}} +{{- end -}} + + + +{{/* Define the chart version and app version */}} +{{- define "memgraph.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end -}} + + +{{/* Define the name of the application */}} +{{- define "memgraph.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end -}} + + +{{/* Common labels */}} +{{- define "memgraph.labels" -}} +app.kubernetes.io/name: {{ include "memgraph.name" . }} +helm.sh/chart: {{ include "memgraph.chart" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end -}} + + +{{/* +Create the name of the service account to use +*/}} +{{- define "memgraph.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "memgraph.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/charts/memgraph-high-availability/templates/cluster-setup.yaml b/charts/memgraph-high-availability/templates/cluster-setup.yaml new file mode 100644 index 0000000..b046eb4 --- /dev/null +++ b/charts/memgraph-high-availability/templates/cluster-setup.yaml @@ -0,0 +1,51 @@ +apiVersion: batch/v1 +kind: Job +metadata: + name: memgraph-setup +spec: + template: + spec: + containers: + - name: memgraph-setup + image: memgraph/memgraph:2.16.0 + command: ["/bin/bash", "-c"] + args: + - | + # Install netcat + echo "Installing netcat..." + apt-get update && apt-get install -y netcat-openbsd + + # Wait until the pods are available + echo "Waiting for pods to become available for Bolt connection..." + until nc -z memgraph-coordinator-1.default.svc.cluster.local 7687; do sleep 1; done + until nc -z memgraph-coordinator-2.default.svc.cluster.local 7687; do sleep 1; done + until nc -z memgraph-coordinator-3.default.svc.cluster.local 7687; do sleep 1; done + until nc -z memgraph-data-0.default.svc.cluster.local 7687; do sleep 1; done + until nc -z memgraph-data-1.default.svc.cluster.local 7687; do sleep 1; done + echo "Pods are available for Bolt connection!" + + sleep 5 + + # Run the mgconsole commands + echo "Running mgconsole commands..." + echo 'ADD COORDINATOR 2 WITH CONFIG {"bolt_server": "memgraph-coordinator-2.default.svc.cluster.local:7687", "coordinator_server": "memgraph-coordinator-2.default.svc.cluster.local:12000"};' | mgconsole --host memgraph-coordinator-1.default.svc.cluster.local --port 7687 + echo 'ADD COORDINATOR 3 WITH CONFIG {"bolt_server": "memgraph-coordinator-3.default.svc.cluster.local:7687", "coordinator_server": "memgraph-coordinator-3.default.svc.cluster.local:12000"};' | mgconsole --host memgraph-coordinator-1.default.svc.cluster.local --port 7687 + echo 'REGISTER INSTANCE instance_1 WITH CONFIG {"bolt_server": "memgraph-data-0.default.svc.cluster.local:7687", "management_server": "memgraph-data-0.default.svc.cluster.local:10000", "replication_server": "memgraph-data-0.default.svc.cluster.local:20000"};' | mgconsole --host memgraph-coordinator-1.default.svc.cluster.local --port 7687 + echo 'REGISTER INSTANCE instance_2 WITH CONFIG {"bolt_server": "memgraph-data-1.default.svc.cluster.local:7687", "management_server": "memgraph-data-1.default.svc.cluster.local:10000", "replication_server": "memgraph-data-1.default.svc.cluster.local:20000"};' | mgconsole --host memgraph-coordinator-1.default.svc.cluster.local --port 7687 + echo 'SET INSTANCE instance_1 TO MAIN;' | mgconsole --host memgraph-coordinator-1.default.svc.cluster.local --port 7687 + sleep 3 + echo "SHOW INSTANCES on coord1" + echo 'SHOW INSTANCES;' | mgconsole --host memgraph-coordinator-1.default.svc.cluster.local --port 7687 + echo "SHOW INSTANCES on coord2" + echo 'SHOW INSTANCES;' | mgconsole --host memgraph-coordinator-2.default.svc.cluster.local --port 7687 + echo "SHOW INSTANCES on coord3" + echo 'SHOW INSTANCES;' | mgconsole --host memgraph-coordinator-3.default.svc.cluster.local --port 7687 + echo "RETURN 0 on 1st data instance" + echo 'RETURN 0;' | mgconsole --host memgraph-data-0.default.svc.cluster.local --port 7687 + echo "RETURN 0 on 2nd data instance" + echo 'RETURN 0;' | mgconsole --host memgraph-data-1.default.svc.cluster.local --port 7687 + securityContext: + runAsUser: 0 + + restartPolicy: Never + backoffLimit: 4 diff --git a/charts/memgraph-high-availability/templates/coordinators.yaml b/charts/memgraph-high-availability/templates/coordinators.yaml new file mode 100644 index 0000000..0dbf75e --- /dev/null +++ b/charts/memgraph-high-availability/templates/coordinators.yaml @@ -0,0 +1,116 @@ +{{- range $index, $coordinator := .Values.coordinators }} +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: memgraph-coordinator-{{ $coordinator.id }} +spec: + serviceName: "memgraph-coordinator-{{ $coordinator.id }}" + replicas: 1 + selector: + matchLabels: + app: memgraph-coordinator-{{ $coordinator.id }} + template: + metadata: + labels: + app: memgraph-coordinator-{{ $coordinator.id }} + spec: + initContainers: + - name: init + image: "{{ $.Values.memgraph.image.repository }}:{{ $.Values.memgraph.image.tag }}" + volumeMounts: + {{- if $.Values.memgraph.coordinators.volumeClaim.storagePVC }} + - name: memgraph-coordinator-{{ $coordinator.id }}-lib-storage + mountPath: /var/lib/memgraph + {{- end }} + {{- if $.Values.memgraph.coordinators.volumeClaim.logPVC }} + - name: memgraph-coordinator-{{ $coordinator.id }}-log-storage + mountPath: /var/log/memgraph + {{- end }} + command: [ "/bin/sh","-c" ] + args: [ "chown -R memgraph:memgraph /var/log; chown -R memgraph:memgraph /var/lib" ] + securityContext: + privileged: true + readOnlyRootFilesystem: false + capabilities: + drop: [ "all" ] + add: [ "CHOWN" ] + runAsUser: 0 + runAsNonRoot: false + containers: + - name: memgraph-coordinator + image: "{{ $.Values.memgraph.image.repository }}:{{ $.Values.memgraph.image.tag }}" + imagePullPolicy: {{ $.Values.memgraph.image.pullPolicy }} + ports: + - containerPort: {{ $coordinator.boltPort }} + - containerPort: {{ $coordinator.coordinatorPort }} + args: + {{- range $arg := $coordinator.args }} + - "{{ $arg }}" + {{- end }} + env: + - name: MEMGRAPH_ENTERPRISE_LICENSE + value: "{{ $.Values.memgraph.env.MEMGRAPH_ENTERPRISE_LICENSE }}" + - name: MEMGRAPH_ORGANIZATION_NAME + value: "{{ $.Values.memgraph.env.MEMGRAPH_ORGANIZATION_NAME }}" + livenessProbe: + exec: + command: + - sh + - -c + - echo 'SHOW INSTANCES;' | mgconsole --host localhost --port {{ $coordinator.boltPort }} + initialDelaySeconds: {{ $.Values.memgraph.probes.liveness.initialDelaySeconds }} + periodSeconds: {{ $.Values.memgraph.probes.liveness.periodSeconds }} + readinessProbe: + exec: + command: + - sh + - -c + - echo 'SHOW INSTANCES;' | mgconsole --host localhost --port {{ $coordinator.boltPort }} + initialDelaySeconds: {{ $.Values.memgraph.probes.readiness.initialDelaySeconds }} + periodSeconds: {{ $.Values.memgraph.probes.readiness.periodSeconds }} + startupProbe: + exec: + command: + - sh + - -c + - echo 'SHOW INSTANCES;' | mgconsole --host localhost --port {{ $coordinator.boltPort }} + failureThreshold: {{ $.Values.memgraph.probes.startup.failureThreshold }} + periodSeconds: {{ $.Values.memgraph.probes.startup.periodSeconds }} + volumeMounts: + {{- if $.Values.memgraph.coordinators.volumeClaim.storagePVC }} + - name: memgraph-coordinator-{{ $coordinator.id }}-lib-storage + mountPath: /var/lib/memgraph + {{- end }} + {{- if $.Values.memgraph.coordinators.volumeClaim.logPVC}} + - name: memgraph-coordinator-{{ $coordinator.id }}-log-storage + mountPath: /var/log/memgraph + {{- end }} + volumeClaimTemplates: + {{- if $.Values.memgraph.coordinators.volumeClaim.storagePVC }} + - metadata: + name: memgraph-coordinator-{{ $coordinator.id }}-lib-storage + spec: + accessModes: + - "ReadWriteOnce" + {{- if $.Values.memgraph.coordinators.volumeClaim.storagePVCClassName }} + storageClassName: {{ $.Values.memgraph.coordinators.volumeClaim.storagePVCClassName }} + {{- end }} + resources: + requests: + storage: {{ $.Values.memgraph.coordinators.volumeClaim.storagePVCSize }} + {{- end }} + {{- if $.Values.memgraph.coordinators.volumeClaim.logPVC }} + - metadata: + name: memgraph-coordinator-{{ $coordinator.id }}-log-storage + spec: + accessModes: + - "ReadWriteOnce" + {{- if $.Values.memgraph.coordinators.volumeClaim.logPVCClassName }} + storageClassName: {{ $.Values.memgraph.coordinators.volumeClaim.logPVCClassName }} + {{- end }} + resources: + requests: + storage: {{ $.Values.memgraph.coordinators.volumeClaim.storagePVC.logPVCSize }} + {{- end }} +--- +{{- end }} diff --git a/charts/memgraph-high-availability/templates/data.yaml b/charts/memgraph-high-availability/templates/data.yaml new file mode 100644 index 0000000..a3bbad3 --- /dev/null +++ b/charts/memgraph-high-availability/templates/data.yaml @@ -0,0 +1,118 @@ +{{- range $index, $data := .Values.data }} +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: memgraph-data-{{ $data.id }} +spec: + serviceName: "memgraph-data-{{ $data.id }}" + replicas: 1 + selector: + matchLabels: + app: memgraph-data-{{ $data.id }} + template: + metadata: + labels: + app: memgraph-data-{{ $data.id }} + spec: + initContainers: + - name: init + image: "{{ $.Values.memgraph.image.repository }}:{{ $.Values.memgraph.image.tag }}" + volumeMounts: + {{- if $.Values.memgraph.data.volumeClaim.storagePVC }} + - name: memgraph-data-{{ $data.id }}-lib-storage + mountPath: /var/lib/memgraph + {{- end }} + {{- if $.Values.memgraph.data.volumeClaim.logPVC }} + - name: memgraph-data-{{ $data.id }}-log-storage + mountPath: /var/log/memgraph + {{- end }} + command: [ "/bin/sh","-c" ] + args: [ "chown -R memgraph:memgraph /var/log; chown -R memgraph:memgraph /var/lib" ] + securityContext: + privileged: true + readOnlyRootFilesystem: false + capabilities: + drop: [ "all" ] + add: [ "CHOWN" ] + runAsUser: 0 + runAsNonRoot: false + containers: + - name: memgraph-data + image: "{{ $.Values.memgraph.image.repository }}:{{ $.Values.memgraph.image.tag }}" + imagePullPolicy: {{ $.Values.memgraph.image.pullPolicy }} + ports: + - containerPort: {{ $data.boltPort }} + - containerPort: {{ $data.managementPort }} + - containerPort: {{ $data.replicationPort }} + args: + {{- range $arg := $data.args }} + - "{{ $arg }}" + {{- end }} + env: + - name: MEMGRAPH_ENTERPRISE_LICENSE + value: "{{ $.Values.memgraph.env.MEMGRAPH_ENTERPRISE_LICENSE }}" + - name: MEMGRAPH_ORGANIZATION_NAME + value: "{{ $.Values.memgraph.env.MEMGRAPH_ORGANIZATION_NAME }}" + livenessProbe: + exec: + command: + - sh + - -c + - echo 'RETURN 0;' | mgconsole --host localhost --port {{ $data.boltPort }} + initialDelaySeconds: {{ $.Values.memgraph.probes.liveness.initialDelaySeconds }} + periodSeconds: {{ $.Values.memgraph.probes.liveness.periodSeconds }} + readinessProbe: + exec: + command: + - sh + - -c + - echo 'RETURN 0;' | mgconsole --host localhost --port {{ $data.boltPort }} + initialDelaySeconds: {{ $.Values.memgraph.probes.readiness.initialDelaySeconds }} + periodSeconds: {{ $.Values.memgraph.probes.readiness.periodSeconds }} + startupProbe: + exec: + command: + - sh + - -c + - echo 'RETURN 0;' | mgconsole --host localhost --port {{ $data.boltPort }} + failureThreshold: {{ $.Values.memgraph.probes.startup.failureThreshold }} + periodSeconds: {{ $.Values.memgraph.probes.startup.periodSeconds }} + volumeMounts: + {{- if $.Values.memgraph.data.volumeClaim.storagePVC }} + - name: memgraph-data-{{ $data.id }}-lib-storage + mountPath: /var/lib/memgraph + {{- end }} + {{- if $.Values.memgraph.data.volumeClaim.logPVC}} + - name: memgraph-data-{{ $data.id }}-log-storage + mountPath: /var/log/memgraph + {{- end }} + volumeClaimTemplates: + {{- if $.Values.memgraph.data.volumeClaim.storagePVC }} + - metadata: + name: memgraph-data-{{ $data.id }}-lib-storage + spec: + accessModes: + - "ReadWriteOnce" + {{- if $.Values.memgraph.data.volumeClaim.storagePVCClassName }} + storageClassName: {{ $.Values.memgraph.data.volumeClaim.storagePVCClassName }} + {{- end }} + resources: + requests: + storage: {{ $.Values.memgraph.data.volumeClaim.storagePVCSize }} + {{- end }} + {{- if $.Values.memgraph.data.volumeClaim.logPVC }} + - metadata: + name: memgraph-data-{{ $data.id }}-log-storage + spec: + accessModes: + - "ReadWriteOnce" + {{- if $.Values.memgraph.data.volumeClaim.logPVCClassName }} + storageClassName: {{ $.Values.memgraph.data.volumeClaim.logPVCClassName }} + {{- end }} + resources: + requests: + storage: {{ $.Values.memgraph.data.volumeClaim.logPVCSize }} + {{- end }} + +--- +{{- end }} diff --git a/charts/memgraph-high-availability/templates/services-coordinators.yaml b/charts/memgraph-high-availability/templates/services-coordinators.yaml new file mode 100644 index 0000000..62742c9 --- /dev/null +++ b/charts/memgraph-high-availability/templates/services-coordinators.yaml @@ -0,0 +1,39 @@ +# Service for coordinator instances internal +{{- range .Values.coordinators }} +--- +apiVersion: v1 +kind: Service +metadata: + name: memgraph-coordinator-{{ .id }} +spec: + type: ClusterIP + selector: + app: memgraph-coordinator-{{ .id }} + ports: + - protocol: TCP + name: bolt + port: {{ .boltPort }} + targetPort: {{ .boltPort }} + - protocol: TCP + name: coordinator + port: {{ .coordinatorPort }} + targetPort: {{ .coordinatorPort }} +{{- end }} + +# Service for coordinators instances external +{{- range .Values.coordinators }} +--- +apiVersion: v1 +kind: Service +metadata: + name: memgraph-coordinator-{{ .id }}-external +spec: + type: NodePort + selector: + app: memgraph-coordinator-{{ .id }} + ports: + - protocol: TCP + name: bolt + port: 7687 + targetPort: 7687 +{{- end }} diff --git a/charts/memgraph-high-availability/templates/services-data.yaml b/charts/memgraph-high-availability/templates/services-data.yaml new file mode 100644 index 0000000..30b5c22 --- /dev/null +++ b/charts/memgraph-high-availability/templates/services-data.yaml @@ -0,0 +1,43 @@ +# Service for data instances internal +{{- range .Values.data }} +--- +apiVersion: v1 +kind: Service +metadata: + name: memgraph-data-{{ .id }} +spec: + type: ClusterIP + selector: + app: memgraph-data-{{ .id }} + ports: + - protocol: TCP + name: bolt + port: {{ .boltPort }} + targetPort: {{ .boltPort }} + - protocol: TCP + name: management + port: {{ .managementPort }} + targetPort: {{ .managementPort }} + - protocol: TCP + name: replication + port: {{ .replicationPort }} + targetPort: {{ .replicationPort }} +{{- end }} + +# Service for data instances external +{{- range .Values.data }} +--- +apiVersion: v1 +kind: Service +metadata: + name: memgraph-data-{{ .id }}-external +spec: + type: NodePort + selector: + app: memgraph-data-{{ .id }} + ports: + - protocol: TCP + name: bolt + port: {{ .boltPort }} + targetPort: {{ .boltPort }} +{{- end }} diff --git a/charts/memgraph-high-availability/templates/tests/test-cluster-setup.yaml b/charts/memgraph-high-availability/templates/tests/test-cluster-setup.yaml new file mode 100644 index 0000000..3bb7c57 --- /dev/null +++ b/charts/memgraph-high-availability/templates/tests/test-cluster-setup.yaml @@ -0,0 +1,53 @@ +apiVersion: batch/v1 +kind: Job +metadata: + name: "{{ .Release.Name }}-memgraph-test-cluster-setup" + labels: + {{- include "memgraph.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test +spec: + template: + metadata: + labels: + app: memgraph + spec: + containers: + - name: memgraph-test-cluster-setup + image: memgraph/memgraph:2.16.0 + command: ["/bin/bash", "-c"] + args: + - | + echo "Running cluster test setup..." + result=$(echo 'SHOW INSTANCES;' | mgconsole --host memgraph-coordinator-1.default.svc.cluster.local --port 7687) + echo "$result" + + # Use awk to check if all instances have health status "up" and there are exactly 5 instances + echo "$result" | awk ' + BEGIN { + FS = "|" + instance_count = 0 + health_ok = 1 + } + NR > 3 && NR <= 8 { + gsub(/^ *| *$/, "", $6) # Trim spaces from health + health = $6 + print "Health: [" health "]" # Debug print + instance_count++ + if (health != "up") { + health_ok = 0 + print "Non-up health found: [" health "]" # Debug print + } + } + END { + print "Instance count: " instance_count # Debug print + print "Health OK: " health_ok # Debug print + if (instance_count == 5 && health_ok == 1) { + print "All instances are up and there are exactly 5 instances." + } else { + print "Check failed. Either not all instances are up or the count is not 5." + } + } + ' + restartPolicy: Never + backoffLimit: 3 diff --git a/charts/memgraph-high-availability/templates/tests/test-connection.yaml b/charts/memgraph-high-availability/templates/tests/test-connection.yaml new file mode 100644 index 0000000..272c41c --- /dev/null +++ b/charts/memgraph-high-availability/templates/tests/test-connection.yaml @@ -0,0 +1,29 @@ +apiVersion: batch/v1 +kind: Job +metadata: + name: "{{ .Release.Name }}-memgraph-test-connection" + labels: + {{- include "memgraph.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test +spec: + template: + spec: + containers: + - name: memgraph-test + image: memgraph/memgraph:2.16.0 + command: ["/bin/sh", "-c"] + args: + - | + echo "Running connection test on data instances..." + echo "RETURN 0;" | mgconsole --host memgraph-data-0.default.svc.cluster.local --port 7687 + echo "RETURN 0;" | mgconsole --host memgraph-data-1.default.svc.cluster.local --port 7687 + + echo "Running a connection test on coordinator instances..." + echo "SHOW INSTANCES;" | mgconsole --host memgraph-coordinator-1.default.svc.cluster.local --port 7687 + echo "SHOW INSTANCES;" | mgconsole --host memgraph-coordinator-2.default.svc.cluster.local --port 7687 + echo "SHOW INSTANCES;" | mgconsole --host memgraph-coordinator-3.default.svc.cluster.local --port 7687 + + + restartPolicy: Never + backoffLimit: 3 diff --git a/charts/memgraph-high-availability/values.yaml b/charts/memgraph-high-availability/values.yaml new file mode 100644 index 0000000..44a48b8 --- /dev/null +++ b/charts/memgraph-high-availability/values.yaml @@ -0,0 +1,100 @@ +# Default values for memgraph-high-availability. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates.| + +memgraph: + image: + repository: memgraph/memgraph + tag: 2.17.0 + pullPolicy: IfNotPresent + env: + MEMGRAPH_ENTERPRISE_LICENSE: "" + MEMGRAPH_ORGANIZATION_NAME: "" + probes: + startup: + failureThreshold: 30 + periodSeconds: 10 + readiness: + initialDelaySeconds: 5 + periodSeconds: 5 + liveness: + initialDelaySeconds: 30 + periodSeconds: 10 + data: + volumeClaim: + storagePVCClassName: "" + storagePVC: true + storagePVCSize: "1Gi" + logPVCClassName: "" + logPVC: false + logPVCSize: "256Mi" + coordinators: + volumeClaim: + storagePVCClassName: "" + storagePVC: true + storagePVCSize: "1Gi" + logPVCClassName: "" + logPVC: false + logPVCSize: "256Mi" + + + +data: +- id: "0" + boltPort: 7687 + managementPort: 10000 + replicationPort: 20000 + args: + - "--experimental-enabled=high-availability" + - "--management-port=10000" + - "--bolt-port=7687" + - "--also-log-to-stderr" + - "--log-level=TRACE" + - "--replication-restore-state-on-startup=true" + +- id: "1" + boltPort: 7687 + managementPort: 10000 + replicationPort: 20000 + args: + - "--experimental-enabled=high-availability" + - "--management-port=10000" + - "--bolt-port=7687" + - "--also-log-to-stderr" + - "--log-level=TRACE" + - "--replication-restore-state-on-startup=true" + +coordinators: +- id: "1" + boltPort: 7687 + coordinatorPort: 12000 + args: + - "--experimental-enabled=high-availability" + - "--coordinator-id=1" + - "--coordinator-port=12000" + - "--bolt-port=7687" + - "--also-log-to-stderr" + - "--log-level=TRACE" + - "--replication-restore-state-on-startup=true" +- id: "2" + boltPort: 7687 + coordinatorPort: 12000 + args: + - "--experimental-enabled=high-availability" + - "--coordinator-id=2" + - "--coordinator-port=12000" + - "--bolt-port=7687" + - "--also-log-to-stderr" + - "--log-level=TRACE" + - "--replication-restore-state-on-startup=true" +- id: "3" + boltPort: 7687 + coordinatorPort: 12000 + args: + - "--experimental-enabled=high-availability" + - "--coordinator-id=3" + - "--coordinator-port=12000" + - "--bolt-port=7687" + - "--also-log-to-stderr" + - "--log-level=TRACE" + - "--replication-restore-state-on-startup=true" From a1e4ab7007b7869f7a6bda882532eb0b07950ece Mon Sep 17 00:00:00 2001 From: Ante Javor Date: Thu, 16 May 2024 13:54:46 +0200 Subject: [PATCH 3/6] Grammar fixes (#23) * Grammar updates. --- charts/memgraph-high-availability/README.md | 6 +++--- charts/memgraph-lab/README.md | 2 +- charts/memgraph-lab/templates/NOTES.txt | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/charts/memgraph-high-availability/README.md b/charts/memgraph-high-availability/README.md index 51010ae..7c07444 100644 --- a/charts/memgraph-high-availability/README.md +++ b/charts/memgraph-high-availability/README.md @@ -1,10 +1,10 @@ -## Memgraph high availability Kubernetes Helm Chart -A Helm Chart for deploying Memgraph in [high-availability setup](https://memgraph.com/docs/clustering/high-availability). +## Helm chart for Memgraph high availability cluster +A Helm Chart for deploying Memgraph in [high availability setup](https://memgraph.com/docs/clustering/high-availability). Memgraph HA cluster includes 3 coordinators, 2 data instances by default. The cluster setup is performed via the cluster-setup job. The HA cluster is still work in progress and started with "--experimental-enabled=high-availability". The cluster is started in the configuration without the node selector, which means that in the current configuration, it is not highly available if the node fails. -## Installing the Memgraph Helm Chart +## Installing the Memgraph HA Helm Chart To install the Memgraph HA Helm Chart, follow the steps below: ``` helm install memgraph/memgraph-high-availability --set memgraph.env.MEMGRAPH_ENTERPRISE_LICENSE=,memgraph.env.MEMGRAPH_ORGANIZATION_NAME= diff --git a/charts/memgraph-lab/README.md b/charts/memgraph-lab/README.md index cae70a0..ad18727 100644 --- a/charts/memgraph-lab/README.md +++ b/charts/memgraph-lab/README.md @@ -48,4 +48,4 @@ env: - 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) +Refer to the [Memgraph Lab documentation](https://memgraph.com/docs/data-visualization) for details on how to connect to and interact with Memgraph. diff --git a/charts/memgraph-lab/templates/NOTES.txt b/charts/memgraph-lab/templates/NOTES.txt index b278baf..6d143cb 100644 --- a/charts/memgraph-lab/templates/NOTES.txt +++ b/charts/memgraph-lab/templates/NOTES.txt @@ -23,4 +23,4 @@ Thank you for installing Memgraph Lab! 🎉 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. +2. Specify your MemgraphDB instance IP address and port in Memgraph Lab GUI. From f5421428c8d90430649185e3c4da7f69b5908c1b Mon Sep 17 00:00:00 2001 From: katarinasupe Date: Wed, 22 May 2024 14:48:25 +0200 Subject: [PATCH 4/6] Update to Memgraph 2.17 --- charts/memgraph-high-availability/templates/cluster-setup.yaml | 2 +- .../templates/tests/test-cluster-setup.yaml | 2 +- .../templates/tests/test-connection.yaml | 2 +- charts/memgraph/templates/tests/test-connection.yaml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/charts/memgraph-high-availability/templates/cluster-setup.yaml b/charts/memgraph-high-availability/templates/cluster-setup.yaml index b046eb4..8376ccc 100644 --- a/charts/memgraph-high-availability/templates/cluster-setup.yaml +++ b/charts/memgraph-high-availability/templates/cluster-setup.yaml @@ -7,7 +7,7 @@ spec: spec: containers: - name: memgraph-setup - image: memgraph/memgraph:2.16.0 + image: memgraph/memgraph:2.17.0 command: ["/bin/bash", "-c"] args: - | diff --git a/charts/memgraph-high-availability/templates/tests/test-cluster-setup.yaml b/charts/memgraph-high-availability/templates/tests/test-cluster-setup.yaml index 3bb7c57..45b9927 100644 --- a/charts/memgraph-high-availability/templates/tests/test-cluster-setup.yaml +++ b/charts/memgraph-high-availability/templates/tests/test-cluster-setup.yaml @@ -14,7 +14,7 @@ spec: spec: containers: - name: memgraph-test-cluster-setup - image: memgraph/memgraph:2.16.0 + image: memgraph/memgraph:2.17.0 command: ["/bin/bash", "-c"] args: - | diff --git a/charts/memgraph-high-availability/templates/tests/test-connection.yaml b/charts/memgraph-high-availability/templates/tests/test-connection.yaml index 272c41c..ef61c87 100644 --- a/charts/memgraph-high-availability/templates/tests/test-connection.yaml +++ b/charts/memgraph-high-availability/templates/tests/test-connection.yaml @@ -11,7 +11,7 @@ spec: spec: containers: - name: memgraph-test - image: memgraph/memgraph:2.16.0 + image: memgraph/memgraph:2.17.0 command: ["/bin/sh", "-c"] args: - | diff --git a/charts/memgraph/templates/tests/test-connection.yaml b/charts/memgraph/templates/tests/test-connection.yaml index f164143..3bb8032 100644 --- a/charts/memgraph/templates/tests/test-connection.yaml +++ b/charts/memgraph/templates/tests/test-connection.yaml @@ -11,7 +11,7 @@ spec: spec: containers: - name: memgraph-test - image: memgraph/memgraph:2.16.0 + image: memgraph/memgraph:2.17.0 command: ["/bin/sh", "-c"] args: - | From 051e5ea6f63c9231de322a17023332dd2fdbe15b Mon Sep 17 00:00:00 2001 From: katarinasupe Date: Wed, 22 May 2024 15:02:01 +0200 Subject: [PATCH 5/6] change app version --- charts/memgraph/Chart.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/memgraph/Chart.yaml b/charts/memgraph/Chart.yaml index 945b448..1fdb1e3 100644 --- a/charts/memgraph/Chart.yaml +++ b/charts/memgraph/Chart.yaml @@ -3,7 +3,7 @@ name: memgraph home: https://memgraph.com/ type: application version: 0.1.2 -appVersion: "2.16.0" +appVersion: "2.17.0" description: MemgraphDB Helm Chart keywords: - graph From caf5b4c0f877facb405630b3f470f8da12df9639 Mon Sep 17 00:00:00 2001 From: katarinasupe Date: Thu, 23 May 2024 11:25:38 +0200 Subject: [PATCH 6/6] add codeowner --- .github/CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 261f658..b62b671 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1 +1 @@ -* @antejavor @katarinasupe +* @antejavor @katarinasupe @as51340