Neo4j recently released a distribution of Neo4j Enterprise Causal Clustering on Pivotal Container Service (PKS). This distribution makes it easy to spin up a clustered, highly available graph database on top of Kubernetes quickly and easily.
This article is going to describe what this is all about, and how to get started with it! To discuss and connect with other community members doing this, make sure to drop by the Neo4j Community Site’s cloud topic.
You can find Neo4j on Pivotal’s PivNet site here. You’ll want to start by downloading both artifacts, the Neo4j Docker image, and the Neo4j Helm Chart package. You’ll also want to check out the documentation that comes with it.
The first thing to do is to load the downloaded docker image on to your local machine, like so:
$ docker load < causal-cluster_image.*.tgz
Loaded image: gcr.io/neo4j-pivotal/causal-cluster:3.5.7-master-eb023576dddee4f8cdc5afb6041c796f460f8a46
Next, unarchive the downloaded helm chart:
$ tar zxvf neo4j-3.5.7.tgz
Finally, we’ll use helm to install Neo4j as a package into our Kubernetes cluster. Take special note of the parameters being provided here and adjust according to your needs. For full descriptions of what these parameters do, and what your other options are, check the documentation.
Take special note of the image, and how it matches the loaded image above. Yours might differ depending on release you’re using, so make sure it’s right.
$ helm install neo4j --namespace $NAMESPACE --name $APP_NAME \
--set namespace=$NAMESPACE \
--set image=$IMAGE \
--set name=$APP_NAME \
--set neo4jPassword=mySecretPassword \
--set authEnabled=true \
--set coreServers=3 \
--set readReplicaServers=1 \
--set cpuRequest=200m \
--set memoryRequest=1Gi \
--set volumeSize=2Gi \
--set volumeStorageClass=standard \
--set acceptLicenseAgreement=yesNAME: my-neo4j-deploy
LAST DEPLOYED: Tue Jul 16 11:25:19 2019
NAME TYPE DATA AGE
my-neo4j-deploy-neo4j-secrets Opaque 1 1s==> v1/Service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
my-neo4j-deploy-neo4j ClusterIP None <none> 7474/TCP,7473/TCP,7687/TCP 1s
my-neo4j-deploy-neo4j-readreplica-svc ClusterIP None <none> 7474/TCP,7473/TCP,7687/TCP 1s==> v1beta2/StatefulSet
NAME READY AGE
my-neo4j-deploy-neo4j-core 0/3 1s
my-neo4j-deploy-neo4j-replica 0/1 1s
You’ll see that helm outputs some messages related to the StatefulSets it is creating and the fact they’re not ready yet. We’ll need a few minutes for everything to come up happily. If you’re interested in a deeper breakdown of what resources are being created and how they all work together, read this article, which goes over how Neo4j works with Kubernetes.
Where’s My Data?
Neo4j on PKS uses persistent volume claims of the size and storage class you specified when installing via helm. These PVCs in turn map to the
/data directory inside of the pod. The actual container running is essentially Neo4j’s Standard Docker Container, for the purposes of understanding layout and configuration.
Once everything is up, you’ll see that the pods and StatefulSets are happy, and we’re ready to start using this cluster. Let’s run a cypher-shell against our new instance. The password we’re using is what we specified above on deploy.
The cypher-shell tool is provided in the container that ships with this, so connecting to your cluster is a matter of running that tool, and connecting to the right URL where your service is deployed.
NEO4J_PASSWORD=mySecretPasswordkubectl run -it --rm cypher-shell \
--command -- ./bin/cypher-shell -u neo4j \
-p "$NEO4J_PASSWORD" \
-a $APP_INSTANCE_NAME-neo4j.default.svc.cluster.localIf you don't see a command prompt, try pressing enter.Connected to Neo4j 3.5.7 at bolt://my-neo4j-deploy-neo4j.default.svc.cluster.local:7687 as user neo4j.Type :help for a list of available commands or :exit to exit the shell.Note that Cypher queries must end with a semicolon.neo4j> match (n) return count(n);+----------+
| count(n) |
| 0 |
+----------+1 row available after 276 ms, consumed after another 0 ms
neo4j> return apoc.version();+----------------+
| apoc.version() |
| "188.8.131.52" |
+----------------+1 row available after 2 ms, consumed after another 0 ms
When you’re done with a cluster, you can shut it down and remove all resources with a single easy command.
$ helm delete --purge my-neo4j-deploy
release "my-neo4j-deploy" deleted
Related Resources for Neo4j on Kubernetes
The following is a list of other articles and tutorials you may want to check out that will help with Neo4j on Kubernetes!
- Neo4j on PKS Documentation
- How to Backup Neo4j on Kubernetes
- How to Restore Neo4j on Kubernetes
- Neo4j Considerations in Orchestration Environments — or, all of the kubernetes-specific considerations about running Neo4j.
- Querying Neo4j Clusters, which describes how queries are routed in clustered setup.
- Neo4j Docker Container Documentation