Kubernetes

Memgraph can be deployed on Kubernetes. The easiest way to do that is with Helm, the package manager for Kubernetes. Helm uses a packaging format called charts. A chart is a collection of files that describe a related set of Kubernetes resources.

Currently, we prepared and released the following charts:

The Helm charts are published on Artifact Hub. For details on the implementation of the Helm charts, check Memgraph Helm charts repository.

Due to numerous possible use cases and deployment setups via Kubernetes, the provided Helm charts are a starting point you can modify according to your needs. This page will highlight some of the specific parts of the Helm charts that you might want to adjust.

Memgraph standalone Helm chart

Memgraph is a stateful application (database), hence the Helm chart for standalone Memgraph is configured to deploy Memgraph as a Kubernetes StatefulSet workload.

It will deploy a single Memgraph instance in a single pod.

Typically, when deploying a stateful application like Memgraph, a StatefulSet workload is used to ensure that each pod has a unique identity and stable network identity. When deploying Memgraph, it is also necessary to define a PersistentVolumeClaims to store the data directory (/var/lib/memgraph). This enables the data to be persisted even if the pod is restarted or deleted.

Storage configuration

By default, the Helm chart will create a PersistentVolumeClaim (PVC) for storage and logs. If the storage class for PVC is not defined, PVC will use the default one available in the cluster. The storage class can be configured in the values.yaml file. To avoid losing your data, make sure you have Retain reclaim policy set on your storage class. If you delete PersistentVolumeClaim without having Retain reclaim policy, you will lose your data because PersistentVolume will get deleted too. The alternative to creating a new storage class is to patch your existing storage class by applying the Retain policy. This is necessary because the default Kubernetes policy is Delete. The patching can be done using the following bash script:

#!/bin/bash
 
# Get all Persistent Volume names
PVS=$(kubectl get pv --no-headers -o custom-columns=":metadata.name")
 
# Loop through each PV and patch it
for pv in $PVS; do
  echo "Patching PV: $pv"
  kubectl patch pv $pv -p '{"spec":{"persistentVolumeReclaimPolicy":"Retain"}}'
done
 
echo
 
 
An example of a storage class for AWS EBS volumes: 
 
```yaml
storageClass:
  name: "gp2"
  provisioner: "kubernetes.io/aws-ebs"
  storageType: "gp2"
  fsType: "ext4"
  reclaimPolicy: "Retain"
  volumeBindingMode: "Immediate"

Default template for a storage class is part of the Helm chart and can be found in the repository. If you don’t want to create a new storage class, set storageClass.create to false.

More details on the configuration options can be found in the configuration section.

Secrets

The Helm chart allows you to use Kubernetes secrets to store Memgraph credentials. By default, the secrets are disabled. If you want to use secrets, you can enable them in the values.yaml file.

The secrets are prepared to work for environment variables MEMGRAPH_USER and MEMGRAPH_PASSWORD.

Probes

Memgraph standalone chart uses startup, readiness and liveness probes. The startup probe is used to determine when a container application has started. The liveness probe is used to determine when a container should be restarted. The readiness probe is used to determine when a container is ready to start accepting traffic. The startup probe will succeed only after the recovery of the Memgraph has finished. Liveness and readiness probes will start after the startup probe succeeds. By default, the startup probe has to succeed within 2 hours. If the recovery from backup takes longer than that, update the configuration to the value that is high enough. The liveness and readiness probe have to succeed at least once in 5 minutes for a pod to be considered ready.

System configuration

The Helm chart will set the linux kernel vm.max_map_count parameter to 262144 by default to ensure Memgraph won’t run into issues with memory mapping.

The vm.max_map_count parameter is a kernel parameter that specifies the maximum number of memory map areas a process may have. This change will be applied to all nodes in the cluster. If you want to disable this feature, you can set sysctlInitContainer.enabled to false in the values.yaml file.

Installing Memgraph standalone Helm chart

To include a standalone Memgraph into your Kubernetes cluster, you need to add the repository and install Memgraph.

The steps below will work in the Minikube environment, but you can also use them in other Kubernetes environments with minor adjustments.

Add the repository

Add the Memgraph Helm chart repository to your local Helm setup by running the following command:

helm repo add memgraph https://memgraph.github.io/helm-charts

Make sure to update the repository to fetch the latest Helm charts available:

helm repo update

Install Memgraph

To install Memgraph Helm chart, run the following command:

helm install <release-name> memgraph/memgraph

Replace <release-name> with the name of the release you chose.

When installing a chart, it’s best practice to specify the exact version you want to use. Using the latest tag can lead to issues, as a pod restart may pull a newer image, potentially causing unexpected changes or incompatibilities.

Install Memgraph standalone chart with minikube

If you are installing Memgraph standalone chart locally with minikube, we are strongly recommending to enable csi-hostpath-driver and use its storage class. Otherwise, you could have problems with attaching PVCs to pods.

  1. Enable csi-hostpath-driver
minikube addons disable storage-provisioner
minikube addons disable default-storageclass
minikube addons enable volumesnapshots
minikube addons enable csi-hostpath-driver
  1. Create a storage class with csi-hostpath-driver as a provider (file sc.yaml)
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: csi-hostpath-delayed
provisioner: hostpath.csi.k8s.io
volumeBindingMode: WaitForFirstConsumer
reclaimPolicy: Delete
  1. kubectl apply -f sc.yaml

  2. Set storageClassName to csi-hostpath-delayed in values.yaml

Access Memgraph

Once Memgraph is installed, you can access it using the provided services and endpoints, such as various client libraries, command-line interface mgconsole or visual user interface Memgraph Lab.

Configuration options

The following table lists the configurable parameters of the Memgraph chart and their default values.

ParameterDescriptionDefault
image.repositoryMemgraph Docker image repositorymemgraph/memgraph
image.tagSpecific tag for the Memgraph Docker image. Overrides the image tag whose default is chart version."" (Defaults to chart’s app version)
image.pullPolicyImage pull policyIfNotPresent
memgraphUserIdThe user id that is hardcoded in Memgraph and Mage images101
memgraphGroupIdThe group id that is hardcoded in Memgraph and Mage images103
useImagePullSecretsOverride the default imagePullSecretsfalse
imagePullSecretsSpecify image pull secrets- name: regcred
replicaCountNumber of Memgraph instances to run. Note: no replication or HA support.1
affinity.nodeKeyKey for node affinity (Preferred)""
affinity.nodeValueValue for node affinity (Preferred)""
nodeSelectorConstrain which nodes your Memgraph pod is eligible to be scheduled on, based on the labels on the nodes. Left empty by default.{}
service.typeKubernetes service typeClusterIP
service.enableBoltEnable Bolt protocoltrue
service.boltPortBolt protocol port7687
service.enableWebsocketMonitoringEnable WebSocket monitoringfalse
service.websocketPortMonitoringWebSocket monitoring port7444
service.enableHttpMonitoringEnable HTTP monitoringfalse
service.httpPortMonitoringHTTP monitoring port9091
service.annotationsAnnotations to add to the service{}
service.labelsLabels to add to the service{}
persistentVolumeClaim.createStorageClaimEnable creation of a Persistent Volume Claim for storagetrue
persistentVolumeClaim.storageClassNameStorage class name for the persistent volume claim""
persistentVolumeClaim.storageSizeSize of the persistent volume claim for storage10Gi
persistentVolumeClaim.libStorageAccessModeAccess mode for the PVC of the lib storageReadWriteOnce
persistentVolumeClaim.existingClaimUse an existing Persistent Volume Claimmemgraph-0
persistentVolumeClaim.storageVolumeNameName of an existing Volume to create a PVC for""
persistentVolumeClaim.createLogStorageEnable creation of a Persistent Volume Claim for logstrue
persistentVolumeClaim.logStorageClassNameStorage class name for the persistent volume claim for logs""
persistentVolumeClaim.logStorageSizeSize of the persistent volume claim for logs1Gi
persistentVolumeClaim.createUserClaimCreate a Dynamic Persistant Volume Claim for Configs, Certificates (e.g. Bolt cert ) and rest of User related filesfalse
persistentVolumeClaim.userStorageClassNameStorage class name for the persistent volume claim for user storage""
persistentVolumeClaim.userStorageSizeSize of the persistent volume claim for user storage1Gi
persistentVolumeClaim.userStorageAccessModeStorage Class Access Mode. If you need a different pod to add data into Memgraph (e.g. CSV files) set this to “ReadWriteMany”ReadWriteOnce
persistentVolumeClaim.userMountPathWhere to mount the userStorageClass you should set this variable if you are enabling the UserClaim""
memgraphConfigList of strings defining Memgraph configuration settings["--also-log-to-stderr=true"]
secrets.enabledEnable the use of Kubernetes secrets for Memgraph credentialsfalse
secrets.nameThe name of the Kubernetes secret containing Memgraph credentialsmemgraph-secrets
secrets.userKeyThe key in the Kubernetes secret for the Memgraph user, the value is passed to the MEMGRAPH_USER envUSER
secrets.passwordKeyThe key in the Kubernetes secret for the Memgraph password, the value is passed to the MEMGRAPH_PASSWORDPASSWORD
memgraphEnterpriseLicenseMemgraph Enterprise License""
memgraphOrganizationNameOrganization name for Memgraph Enterprise License""
statefulSetAnnotationsAnnotations to add to the stateful set{}
podAnnotationsAnnotations to add to the pod{}
resourcesCPU/Memory resource requests/limits. Left empty by default.{}
tolerationsA toleration is applied to a pod and allows the pod to be scheduled on nodes with matching taints. Left empty by default.[]
serviceAccount.createSpecifies whether a service account should be createdtrue
serviceAccount.annotationsAnnotations to add to the service account{}
serviceAccount.nameThe name of the service account to use. If not set and create is true, a name is generated.""
container.terminationGracePeriodSecondsGrace period for pod termination1800
container.livenessProbe.execIf defined, will be used instead of a default K8s’s probe.""
container.livenessProbe.tcpSocket.portPort used for TCP connection. Should be the same as bolt port.7687
container.livenessProbe.failureThresholdFailure threshold for liveness probe20
container.livenessProbe.timeoutSecondsInitial delay for readiness probe10
container.livenessProbe.periodSecondsPeriod seconds for readiness probe5
container.readinessProbe.execIf defined, will be used instead of a default K8s’s probe.""
container.readinessProbe.tcpSocket.portPort used for TCP connection. Should be the same as bolt port.7687
container.readinessProbe.failureThresholdFailure threshold for readiness probe20
container.readinessProbe.timeoutSecondsInitial delay for readiness probe10
container.readinessProbe.periodSecondsPeriod seconds for readiness probe5
container.startupProbe.execIf defined, will be used instead of a default K8s’s probe.""
container.startupProbe.tcpSocket.portPort used for TCP connection. Should be the same as bolt port.7687
container.startupProbe.failureThresholdFailure threshold for startup probe1440
container.startupProbe.periodSecondsPeriod seconds for startup probe10
nodeSelectorsNode selectors for pod. Left empty by default.{}
customQueryModulesList of custom Query modules that should be mounted to Memgraph Pod[]
storageClass.createIf set to true, new StorageClass will be created.false
storageClass.nameName of the StorageClass"memgraph-generic-storage-class"
storageClass.provisionerProvisioner for the StorageClass""
storageClass.storageTypeType of storage for the StorageClass""
storageClass.fsTypeFilesystem type for the StorageClass""
storageClass.reclaimPolicyReclaim policy for the StorageClassRetain
storageClass.volumeBindingModeVolume binding mode for the StorageClassImmediate
initContainersUser specific init containers[]
sysctlInitContainer.enabledEnable the init container to set sysctl parameterstrue
sysctlInitContainer.maxMapCountValue for vm.max_map_count to be set by the init container262144
sysctlInitContainer.image.repositoryBusybox image repositorylibrary/busybox
sysctlInitContainer.image.tagSpecific tag for the Busybox Docker imagelatest
sysctlInitContainer.image.pullPolicyImage pull policy for busyboxIfNotPresent
lifecycleHooksFor the memgraph container(s) to automate configuration before or after startup[]
extraVolumesOptionally specify extra list of additional volumes[]
extraVolumeMountsOptionally specify extra list of additional volumeMounts[]
extraEnvEnv variables that users can define[]
userContainers.dataContainers that users can specifiy that will be run aside from the main Memgraph container on data instances.[]
userContainers.coordinatorsContainers that users can specifiy that will be run aside from the main Memgraph container on coordinators.[]

To change the default chart values, provide your own values.yaml file during the installation:

helm install <resource-name> memgraph/memgraph -f values.yaml

Default chart values can also be changed by setting the values of appropriate parameters:

helm install <resource-name> memgraph/memgraph --set <flag1>=<value1>,<flag2>=<value2>,...

Memgraph will start with the --also-log-to-stderr=true flag, meaning the logs will also be written to the standard error output and you can access logs using the kubectl logs command. To modify other Memgraph database settings, you should update the memgraphConfig parameter. It should be a list of strings defining the values of Memgraph configuration settings. For example, this is how you can define memgraphConfig parameter in your values.yaml:

memgraphConfig: 
  - "--also-log-to-stderr=true"
  - "--log-level=TRACE"

For all available database settings, refer to the Configuration settings reference guide.

Memgraph high availability Helm chart

Please continue on our Memgraph high availability Helm chart setup.

Memgraph Lab 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 <release-name> memgraph/memgraph-lab

Replace <release-name> 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 <resource-name> memgraph/memgraph-lab --set <flag1>=<value1>,<flag2>=<value2>,...

Or you can modify a values.yaml file and override the desired values:

helm install <resource-name> memgraph/memgraph-lab -f values.yaml

Configuration options

The following table lists the configurable parameters of the Memgraph Lab chart and their default values.

ParameterDescriptionDefault
image.repositoryMemgraph Lab Docker image repositorymemgraph/memgraph-lab
image.tagSpecific tag for the Memgraph Lab Docker image. Overrides the image tag whose default is chart version."" (Defaults to chart’s app version)
image.pullPolicyImage pull policyIfNotPresent
replicaCountNumber of Memgraph Lab instances to run.1
service.typeKubernetes service typeClusterIP
service.portKubernetes service port3000
service.targetPortKubernetes service target port3000
service.protocolProtocol used by the serviceTCP
service.annotationsAnnotations to add to the service{}
podAnnotationsAnnotations to add to the pod{}
resourcesCPU/Memory resource requests/limits. Left empty by default.{} (See note on uncommenting)
serviceAccount.createSpecifies whether a service account should be createdtrue
serviceAccount.annotationsAnnotations to add to the service account{}
serviceAccount.nameThe name of the service account to use. If not set and create is true, a name is generated.""
secrets.enabledEnable the use of Kubernetes secrets. Will be injected as env variables.false
secrets.nameThe name of the Kubernetes secret that will be used.memgraph-secrets
secrets.keysKeys from the secrets.name that will be stored as env variables inside the pod.[]

Memgraph Lab can be further configured with environment variables in your values.yaml file.

env:
  - name: QUICK_CONNECT_MG_HOST
    value: memgraph
  - name: QUICK_CONNECT_MG_PORT
    value: "7687"
  - name: KEEP_ALIVE_TIMEOUT_MS
    value: 65000

In case you added Nginx Ingress service or web server for a reverse proxy, update the following proxy timeout annotations to avoid potential timeouts:

proxy_read_timeout X;
proxy_connect_timeout X;
proxy_send_timeout X;

where X is the number of seconds the connection (request query) can be alive. Additionally, update the Memgraph Lab KEEP_ALIVE_TIMEOUT_MS environment variable to a higher value to ensure that Memgraph Lab stays connected to Memgraph when running queries over 65 seconds.

Refer to the Memgraph Lab documentation for details on how to configure Memgraph Lab.

kube