neo4j
by apecloud
Neo4j is a highly scalable, robust native graph database.
About this chart
Neo4j
Neo4j is a highly scalable, robust native graph database.
Features In KubeBlocks
Lifecycle Management
| Topology | Horizontalscaling | Vertical scaling | Expandvolume | Restart | Stop/Start | Configure | Expose | Switchover |
|---|---|---|---|---|---|---|---|---|
| cluster | Yes | No | Yes | Yes | Yes | No | Yes | N/A |
Versions
| Major Versions | Description |
|---|---|
| 4.4 | 4.4.42 |
| 5.26 | 5.26.5 |
Prerequisites
-
Kubernetes cluster >= v1.21
-
kubectlinstalled, refer to K8s Install Tools -
Helm, refer to Installing Helm
-
KubeBlocks installed and running, refer to Install Kubeblocks
-
Neo4j Addon Enabled, refer to Install Addons
-
Create K8s Namespace
demo, to keep resources created in this tutorial isolated:kubectl create ns demo
Examples
Create
Create a neo4j cluster with 1 replicas:
# cat examples/neo4j/cluster.yaml
apiVersion: apps.kubeblocks.io/v1
kind: Cluster
metadata:
name: neo4j-cluster
namespace: demo
spec:
# Specifies the behavior when a Cluster is deleted.
# - `DoNotTerminate`: Prevents deletion of the Cluster. This policy ensures that all resources remain intact.
# - `Delete`: Extends the `Halt` policy by also removing PVCs, leading to a thorough cleanup while removing all persistent data.
# - `WipeOut`: An aggressive policy that deletes all Cluster resources, including volume snapshots and backups in external storage. This results in complete data removal and should be used cautiously, primarily in non-production environments to avoid irreversible data loss.
terminationPolicy: Delete
# Specifies a list of ClusterComponentSpec objects used to define the individual components that make up a Cluster. This field allows for detailed configuration of each component within the Cluster.
# Note: `shardingSpecs` and `componentSpecs` cannot both be empty; at least one must be defined to configure a cluster.
# ClusterComponentSpec defines the specifications for a Component in a Cluster.
componentSpecs:
- name: neo4j
componentDef: neo4j
# The serviceVersion is used to determine the version of the Cluster. If the serviceVersion is not specified, the default value is the ServiceVersion defined in ComponentDefinition.
# ServiceVersion specifies the version of the Service expected to be
# provisioned by this Component.
# Valid options are: [4.4.42, 5.26.5, 2025.03.0]
serviceVersion: 5.26.5
# community version only support 1 replicas
replicas: 1
# Specifies the resources required by the Component.
resources:
limits:
cpu: "2"
memory: "2Gi"
requests:
cpu: "2"
memory: "2Gi"
# Specifies a list of PersistentVolumeClaim templates that define the storage
# requirements for the Component.
volumeClaimTemplates:
# Refers to the name of a volumeMount defined in
# `componentDefinition.spec.runtime.containers[*].volumeMounts
- name: data
spec:
# The name of the StorageClass required by the claim.
# If not specified, the StorageClass annotated with
# `storageclass.kubernetes.io/is-default-class=true` will be used by default
storageClassName: ""
accessModes:
- ReadWriteOnce
resources:
requests:
# Set the storage size as needed
storage: 20Gi
kubectl apply -f examples/neo4j/cluster.yaml
Vertical scaling
Vertical scaling up or down specified components requests and limits cpu or memory resource in the cluster
# cat examples/neo4j/verticalscale.yaml
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name: neo4j-verticalscaling
namespace: demo
spec:
# Specifies the name of the Cluster resource that this operation is targeting.
clusterName: neo4j-cluster
type: VerticalScaling
# Lists VerticalScaling objects, each specifying a component and its desired compute resources for vertical scaling.
verticalScaling:
- componentName: neo4j
# VerticalScaling refers to the process of adjusting the compute resources (e.g., CPU, memory) allocated to a Component. It defines the parameters required for the operation.
# Neo4j has a minimal resource request of 1 CPU and 2GB of memory.
requests:
cpu: '3'
memory: 3Gi
limits:
cpu: '3'
memory: 3Gi
kubectl apply -f examples/neo4j/verticalscale.yaml
Scale-up/down using Cluster API
Alternatively, you may update spec.componentSpecs.resources field to the desired resources for vertical scale.
spec:
componentSpecs:
- name: neo4j
componentDef: neo4j
replicas: 3
resources:
requests:
cpu: "1" # Update the resources to your need.
memory: "2Gi" # Update the resources to your need.
limits:
cpu: "2" # Update the resources to your need.
memory: "4Gi" # Update the resources to your need.
Expand volume
[!NOTE] Make sure the storage class you use supports volume expansion.
Check the storage class with following command:
kubectl get storageclass
If the ALLOWVOLUMEEXPANSION column is true, the storage class supports volume expansion.
To increase size of volume storage with the specified components in the cluster
Increase size of volume storage with the specified components in the cluster
# cat examples/neo4j/volumeexpand.yaml
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name: neo4j-volumeexpansion
namespace: demo
spec:
# Specifies the name of the Cluster resource that this operation is targeting.
clusterName: neo4j-cluster
type: VolumeExpansion
# Lists VolumeExpansion objects, each specifying a component and its corresponding volumeClaimTemplates that requires storage expansion.
volumeExpansion:
# Specifies the name of the Component.
- componentName: neo4j
# volumeClaimTemplates specifies the storage size and volumeClaimTemplate name.
volumeClaimTemplates:
- name: data
storage: 30Gi
kubectl apply -f examples/neo4j/volumeexpand.yaml
Volume expansion using Cluster API
Alternatively, you may update the spec.componentSpecs.volumeClaimTemplates.spec.resources.requests.storage field to the desired size.
spec:
componentSpecs:
- name: neo4j
componentDef: neo4j
replicas: 1
volumeClaimTemplates:
- name: data
spec:
storageClassName: ""
accessModes:
- ReadWriteOnce
resources:
requests:
# specify new size, and make sure it is larger than the current size
storage: 30Gi
Restart
Restart the specified components in the cluster:
# cat examples/neo4j/restart.yaml
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name: neo4j-restart
namespace: demo
spec:
# Specifies the name of the Cluster resource that this operation is targeting.
clusterName: neo4j-cluster
type: Restart
# Lists Components to be restarted. ComponentOps specifies the Component to be operated on.
restart:
# Specifies the name of the Component.
- componentName: neo4j
kubectl apply -f examples/neo4j/restart.yaml
Stop
Stop the cluster and release all the pods of the cluster, but the storage will be reserved
# cat examples/neo4j/stop.yaml
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name: neo4j-stop
namespace: demo
spec:
# Specifies the name of the Cluster resource that this operation is targeting.
clusterName: neo4j-cluster
type: Stop
kubectl apply -f examples/neo4j/stop.yaml
Start
Start the stopped cluster
# cat examples/neo4j/start.yaml
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name: neo4j-start
namespace: demo
spec:
# Specifies the name of the Cluster resource that this operation is targeting.
clusterName: neo4j-cluster
type: Start
kubectl apply -f examples/neo4j/start.yaml
Expose
Enable
# cat examples/neo4j/expose-enable.yaml
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name: neo4j-expose-enable
namespace: demo
spec:
# Specifies the type of this operation.
type: Expose
# Specifies the name of the Cluster resource that this operation is targeting.
clusterName: neo4j-cluster
# Lists Expose objects, each specifying a Component and its services to be exposed.
expose:
# Specifies the name of the Component.
- componentName: neo4j
# Specifies a list of OpsService. When an OpsService is exposed, a corresponding ClusterService will be added to `cluster.spec.services`.
services:
- name: internet
# Determines how the Service is exposed. Defaults to 'ClusterIP'.
# Valid options are `ClusterIP`, `NodePort`, and `LoadBalancer`.
serviceType: LoadBalancer
ports:
- name: http
port: 7474
targetPort: http
# Contains cloud provider related parameters if ServiceType is LoadBalancer.
# [NOTE] Following is an example for Aliyun ACK, please adjust the following annotations as needed.
annotations:
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-address-type: internet
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-charge-type: ""
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-spec: slb.s1.small
# Indicates whether the services will be exposed. 'Enable' exposes the services. while 'Disable' removes the exposed Service.
switch: Enable
kubectl apply -f examples/neo4j/expose-enable.yaml
Disable
# cat examples/neo4j/expose-disable.yaml
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name: neo4j-expose-disable
namespace: demo
spec:
# Specifies the name of the Cluster resource that this operation is targeting.
clusterName: neo4j-cluster
# Lists Expose objects, each specifying a Component and its services to be exposed.
expose:
# Specifies the name of the Component.
- componentName: neo4j
# Specifies a list of OpsService. When an OpsService is exposed, a corresponding ClusterService will be added to `cluster.spec.services`.
services:
- name: internet
serviceType: LoadBalancer
# Indicates whether the services will be exposed. 'Enable' exposes the services. while 'Disable' removes the exposed Service.
switch: Disable
# Specifies the maximum number of seconds the OpsRequest will wait for its start conditions to be met before aborting. If set to 0 (default), the start conditions must be met immediately for the OpsRequest to proceed.
preConditionDeadlineSeconds: 0
type: Expose
kubectl apply -f examples/neo4j/expose-disable.yaml
Expose SVC using Cluster API
Alternatively, you may expose service by updating spec.services
spec:
services:
# add annotation for cloud loadbalancer if
# services.spec.type is LoadBalancer
# here we use annotation for alibaba cloud for example
- annotations:
# aws annotations
service.beta.kubernetes.io/aws-load-balancer-type: nlb # Use Network Load Balancer
service.beta.kubernetes.io/aws-load-balancer-internal: "true" # or "false" for internet
componentSelector: neo4j
name: neo4j-vpc
serviceName: neo4j-vpc
spec: # defines the behavior of a K8s service.
ipFamilyPolicy: PreferDualStack
ports:
- name: tcp-neo4j
# port to expose
port: 7474 # port 7474 for neo4j http console
protocol: TCP
targetPort: http
type: LoadBalancer
If the service is of type LoadBalancer, please add annotations for cloud loadbalancer depending on the cloud provider you are using. Here list annotations for some cloud providers:
# alibaba cloud
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-address-type: "internet" # or "intranet"
# aws
service.beta.kubernetes.io/aws-load-balancer-type: nlb # Use Network Load Balancer
service.beta.kubernetes.io/aws-load-balancer-internal: "true" # or "false" for internet
# azure
service.beta.kubernetes.io/azure-load-balancer-internal: "true" # or "false" for internet
# gcp
networking.gke.io/load-balancer-type: "Internal" # for internal access
cloud.google.com/l4-rbs: "enabled" # for internet
Please consult your cloud provider for more accurate and update-to-date information.
Appendix
How to access Neo4j HTTP Console
To access the Neo4j HTTP console (at port 7474), you can:
- Option 1. Expose the Neo4j cluster service:
# cat examples/neo4j/expose-enable.yaml
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name: neo4j-expose-enable
namespace: demo
spec:
# Specifies the type of this operation.
type: Expose
# Specifies the name of the Cluster resource that this operation is targeting.
clusterName: neo4j-cluster
# Lists Expose objects, each specifying a Component and its services to be exposed.
expose:
# Specifies the name of the Component.
- componentName: neo4j
# Specifies a list of OpsService. When an OpsService is exposed, a corresponding ClusterService will be added to `cluster.spec.services`.
services:
- name: internet
# Determines how the Ser
Deploy neo4j with OpenTenant
Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has neo4j on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.
- Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
- Place the chartneo4j is pinned at v1.2.0-alpha.0 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
- ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below opentenant validate opentenant.yaml terraform init && terraform apply