Deploying a Neo4J cluster on managed Kubernetes
I’ve created some videos on how to deploy both a Neo4J cluster and standalone instance to a manged Kubernetes cluster. When running a database or any service with persistence concern, we need to take more considerations into account, most importantly how to implement persistent storage as well as automated processes such as backups.
In the following video I’ll explain how to deploy a Neo4J cluster with 3 nodes via the official Helm Chart.
I’ve forked and modified the Helm chart to only use ClusterIP
Kubernetes services and pushed the result under this GitHub repository.
When you run the example on a managed Kubernetes environment, such as the IBM Cloud Kubernetes Service, the storage class provider will create the persistent volumes for you, as shown in the video.
Try it yourself
To try it out yourself run the following steps. If you need access to a managed Kubernetes environment first, you can follow this guide to get access to an IKS cluster. You will need Helm in version v3.x
.
01 02 03 04 05 06 07 08 09 10 | cd /tmp/ git clone https: //github.com/sdaschner/neo4j-helm cd neo4j-helm/ helm template graphdb \ --set acceptLicenseAgreement=yes \ --set neo4jPassword=mySecretPassword . \ > /tmp/neo4j.yaml kubectl apply -f /tmp/neo4j.yaml |
Now Kubernetes will provision the resources including the volume claims and your cloud provider will create the persistent volumes.
1 2 3 4 5 6 | kubectl get pvc NAME STATUS [...] STORAGECLASS AGE datadir-graphdb-neo4j-core- 0 Pending ibmc-file-gold 13s datadir-graphdb-neo4j-core- 1 Pending ibmc-file-gold 13s datadir-graphdb-neo4j-core- 2 Pending ibmc-file-gold 13s |
After a while your persistent volumes will be provisioned:
1 2 3 4 5 6 | kubectl get pvc NAME STATUS VOLUME STORAGECLASS AGE datadir-graphdb-neo4j-core- 0 Bound pvc-8c0ae307-[...] ibmc-file-gold 2m24s datadir-graphdb-neo4j-core- 1 Bound pvc-9a1a6f3c-[...] ibmc-file-gold 2m24s datadir-graphdb-neo4j-core- 2 Bound pvc-2f742c13-[...] ibmc-file-gold 2m24s |
Once that is the case, the Neo4J pods provided by the stateful set should be up-and-running:
1 2 3 4 5 6 | kubectl get pods NAME READY STATUS RESTARTS AGE graphdb-neo4j-core- 0 1 / 1 Running 0 4m13s graphdb-neo4j-core- 1 1 / 1 Running 0 4m13s graphdb-neo4j-core- 2 1 / 1 Running 0 4m13s |
Test connection
In order to test the access you can directly connect to Neo4J using the cypher-shell
command line, either locally, by port-forwarding the ports 7474
, 7687
, and 7473
to localhost
, or by executing the command directly in the running pod:
1 2 | kubectl exec -t -i graphdb-neo4j-core- 0 /bin/bash cypher-shell -u neo4j -p mySecretPassword |
OR:
1 | kubectl port-forward graphdb-neo4j-core- 0 7474 : 7474 7687 : 7687 7473 : 7473 |
In a new terminal:
1 | cypher-shell -a localhost: 7687 -u neo4j -p mySecretPassword |
Example coffee beans application
In order to test the Quarkus application which I showed in the previous video, run the following:
1 2 3 | cd /tmp/ git clone https: //github.com/sdaschner/quarkus-playground --branch neo4j cd quarkus-playground/ |
Then you can create the example data set using the provided Cypher script:
1 2 3 4 5 | cat src/test/resources/test-data.cypher | cypher-shell \ -a localhost: 7687 \ -u neo4j \ -p mySecretPassword \ --format verbose |
Then we can deploy our coffee example:
1 | kubectl apply -f deployment/ |
Once the application is up-and-running you can access the endpoint under /beans/
or /beans/special
.
In order to access the application you would need to use a Kubernetes ingress, Istio gateway, load balancer, or similar means. For testing purposes, we can also forward the port 8080
of our coffee-shop-XX
pod:
1 2 | kubectl port-forward coffee-shop-XX 8080 : 8080 curl localhost: 8080 /beans/ | jq . |
Published on Java Code Geeks with permission by Sebastian Daschner, partner at our JCG program. See the original article here: Deploying a Neo4J cluster on managed Kubernetes (Video) Opinions expressed by Java Code Geeks contributors are their own. |