Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: autoscaling.kubedb.com/v1alpha1
kind: Neo4jAutoscaler
metadata:
name: neo4j-compute-autoscaler
namespace: demo
spec:
databaseRef:
name: neo4j-autoscale
opsRequestOptions:
apply: IfReady
timeout: 10m
maxRetries: 3
compute:
neo4j:
trigger: "On"
podLifeTimeThreshold: 5m
resourceDiffPercentage: 20
minAllowed:
cpu: 600m
memory: 1200Mi
maxAllowed:
cpu: "2"
memory: 2Gi
controlledResources:
- cpu
- memory
containerControlledValues: RequestsAndLimits
28 changes: 28 additions & 0 deletions docs/examples/neo4j/autoscaler/neo4j.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
apiVersion: kubedb.com/v1alpha2
kind: Neo4j
metadata:
name: neo4j-autoscale
namespace: demo
spec:
version: "2025.12.1"
replicas: 3
storageType: Durable
storage:
storageClassName: longhorn
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
podTemplate:
spec:
containers:
- name: neo4j
resources:
requests:
cpu: 500m
memory: 1Gi
limits:
cpu: 500m
memory: 1Gi
deletionPolicy: WipeOut
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: autoscaling.kubedb.com/v1alpha1
kind: Neo4jAutoscaler
metadata:
name: neo4j-storage-autoscaler
namespace: demo
spec:
databaseRef:
name: neo4j-autoscale
opsRequestOptions:
apply: IfReady
timeout: 10m
maxRetries: 3
storage:
neo4j:
trigger: "On"
usageThreshold: 20
scalingThreshold: 50
expansionMode: Online
10 changes: 10 additions & 0 deletions docs/guides/neo4j/autoscaler/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
title: Autoscaling
menu:
docs_{{ .version }}:
identifier: neo4j-autoscaling
name: Autoscaling
parent: neo4j-guides
weight: 90
menu_name: docs_{{ .version }}
---
10 changes: 10 additions & 0 deletions docs/guides/neo4j/autoscaler/compute/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
title: Compute Autoscaling
menu:
docs_{{ .version }}:
identifier: neo4j-compute-autoscaling
name: Compute Autoscaling
parent: neo4j-autoscaling
weight: 10
menu_name: docs_{{ .version }}
---
205 changes: 205 additions & 0 deletions docs/guides/neo4j/autoscaler/compute/autoscale.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
---
title: Autoscale Neo4j Compute Resources
menu:
docs_{{ .version }}:
identifier: neo4j-compute-autoscaling-guide
name: Autoscale Compute Resources
parent: neo4j-compute-autoscaling
weight: 20
menu_name: docs_{{ .version }}
section_menu_id: guides
---

> New to KubeDB? Please start [here](/docs/README.md).

# Autoscale Neo4j Compute Resources

This guide deploys a Neo4j cluster, loads a small social graph, and configures KubeDB to adjust CPU and memory automatically. After scaling, we query the graph again to verify that the data remains available.

## Before You Begin

| Requirement | Details |
|---|---|
| KubeDB | Provisioner, Ops Manager, and Autoscaler operators must be installed. |
| Metrics Server | The Kubernetes Metrics Server must be running so the recommender can observe pod usage. |
| Storage | This example uses a `longhorn` StorageClass; substitute another available class if necessary. |
| Tools | `kubectl`, `jq`, and `base64` must be available locally. |

See [Neo4jAutoscaler](/docs/guides/neo4j/concepts/autoscaler.md) and the [compute autoscaling overview](/docs/guides/neo4j/autoscaler/compute/overview.md) for background.

## Deploy Neo4j

Create an isolated namespace and apply the example Neo4j resource:

```bash
$ kubectl create namespace demo
namespace/demo created

$ kubectl apply -f https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/examples/neo4j/autoscaler/neo4j.yaml
neo4j.kubedb.com/neo4j-autoscale created
```

Wait for the cluster to become ready:

```bash
$ kubectl get neo4j -n demo neo4j-autoscale -w
NAME VERSION STATUS AGE
neo4j-autoscale 2025.12.1 Ready 3m
```

The Neo4j container initially requests and limits `500m` CPU and `1Gi` memory:

```bash
$ kubectl get pod -n demo neo4j-autoscale-0 \
-o jsonpath='{.spec.containers[?(@.name=="neo4j")].resources}' | jq .
{
"limits": {"cpu": "500m", "memory": "1Gi"},
"requests": {"cpu": "500m", "memory": "1Gi"}
}
```

## Create a Sample Graph

Read the generated admin password, create an application database, and insert users connected by `FOLLOWS` relationships:

```bash
$ PASS=$(kubectl get secret -n demo neo4j-autoscale-auth \
-o jsonpath='{.data.password}' | base64 -d)

$ kubectl exec -n demo neo4j-autoscale-0 -- \
cypher-shell -u neo4j -p "$PASS" \
"CREATE DATABASE appdb IF NOT EXISTS WAIT"

$ kubectl exec -n demo neo4j-autoscale-0 -- \
cypher-shell -d appdb -u neo4j -p "$PASS" \
"CREATE CONSTRAINT user_id IF NOT EXISTS
FOR (u:User) REQUIRE u.id IS UNIQUE"

$ kubectl exec -n demo neo4j-autoscale-0 -- \
cypher-shell -d appdb -u neo4j -p "$PASS" \
"UNWIND range(1,10000) AS i
CREATE (:User {id: i, name: 'user-' + toString(i)})"

$ kubectl exec -n demo neo4j-autoscale-0 -- \
cypher-shell -d appdb -u neo4j -p "$PASS" \
"UNWIND range(1,9999) AS i
MATCH (a:User {id: i}), (b:User {id: i + 1})
CREATE (a)-[:FOLLOWS]->(b)"
```

Verify the initial graph:

```bash
$ kubectl exec -n demo neo4j-autoscale-0 -- \
cypher-shell -d appdb -u neo4j -p "$PASS" \
"MATCH (u:User) RETURN count(u) AS users"
users
10000
```

## Create the Neo4jAutoscaler

The example policy permits recommendations from `600m` to `2` CPU and from `1200Mi` to `2Gi` memory:

```yaml
apiVersion: autoscaling.kubedb.com/v1alpha1
kind: Neo4jAutoscaler
metadata:
name: neo4j-compute-autoscaler
namespace: demo
spec:
databaseRef:
name: neo4j-autoscale
opsRequestOptions:
apply: IfReady
timeout: 10m
maxRetries: 3
compute:
neo4j:
trigger: "On"
podLifeTimeThreshold: 5m
resourceDiffPercentage: 20
minAllowed:
cpu: 600m
memory: 1200Mi
maxAllowed:
cpu: "2"
memory: 2Gi
controlledResources:
- cpu
- memory
containerControlledValues: RequestsAndLimits
```

Apply it:

```bash
$ kubectl apply -f https://github.com/kubedb/docs/raw/{{< param "info.version" >}}/docs/examples/neo4j/autoscaler/compute/neo4j-compute-autoscaler.yaml
neo4jautoscaler.autoscaling.kubedb.com/neo4j-compute-autoscaler created
```

The minimum values are deliberately higher than the initial allocation, making this tutorial reproducible. In production, choose bounds based on workload requirements and capacity.

## Observe the Recommendation and Scaling

Run a read workload while the recommender gathers samples:

```bash
$ for i in $(seq 1 100); do
kubectl exec -n demo neo4j-autoscale-0 -- \
cypher-shell -d appdb -u neo4j -p "$PASS" \
"MATCH (u:User)-[:FOLLOWS*1..3]->(v:User)
RETURN count(v)" >/dev/null
done
```

After the `podLifeTimeThreshold` has passed, inspect the recommendation:

```bash
$ kubectl get neo4jautoscaler -n demo neo4j-compute-autoscaler \
-o jsonpath='{.status.vpas[*].recommendation.containerRecommendations}' | jq .
```

KubeDB creates a `Neo4jOpsRequest` when the recommendation differs sufficiently from the current resources:

```bash
$ kubectl get neo4jopsrequest -n demo -w
NAME TYPE STATUS AGE
neoops-neo4j-autoscale-xxxxxx VerticalScaling Successful 2m
```

Verify that the pod allocation is now within the configured bounds:

```bash
$ kubectl get pod -n demo neo4j-autoscale-0 \
-o jsonpath='{.spec.containers[?(@.name=="neo4j")].resources}' | jq .
```

The precise recommendation depends on observed usage, but it will not be below `600m` CPU and `1200Mi` memory or above `2` CPU and `2Gi` memory.

## Verify the Graph

Confirm that the database still contains the users and relationships after the scaling rollout:

```bash
$ kubectl exec -n demo neo4j-autoscale-0 -- \
cypher-shell -d appdb -u neo4j -p "$PASS" \
"MATCH (u:User) OPTIONAL MATCH (u)-[r:FOLLOWS]->()
RETURN count(DISTINCT u) AS users, count(r) AS follows"
users, follows
10000, 9999
```

## Troubleshooting

- If no recommendation appears, verify Metrics Server with `kubectl top pod -n demo` and wait for more samples.
- If no OpsRequest is created, check `podLifeTimeThreshold`, `resourceDiffPercentage`, and the Autoscaler conditions.
- If an operation remains pending, describe it with `kubectl describe neo4jopsrequest -n demo <name>` and check Ops Manager logs.

## Cleaning Up

```bash
$ kubectl delete neo4jautoscaler -n demo neo4j-compute-autoscaler
$ kubectl delete neo4j -n demo neo4j-autoscale
$ kubectl delete namespace demo
Comment thread
fr-sarker marked this conversation as resolved.
Resolved
```
42 changes: 42 additions & 0 deletions docs/guides/neo4j/autoscaler/compute/overview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
title: Neo4j Compute Autoscaling Overview
menu:
docs_{{ .version }}:
identifier: neo4j-compute-autoscaling-overview
name: Overview
parent: neo4j-compute-autoscaling
weight: 10
menu_name: docs_{{ .version }}
section_menu_id: guides
---

> New to KubeDB? Please start [here](/docs/README.md).

# Neo4j Compute Autoscaling

KubeDB can automatically adjust the CPU and memory assigned to Neo4j pods. A `Neo4jAutoscaler` observes real resource usage, generates recommendations, and creates a `Neo4jOpsRequest` when the recommended resources differ sufficiently from the current allocation.

## Before You Begin

You should be familiar with:

- [Neo4j](/docs/guides/neo4j/concepts/neo4j.md)
- [Neo4jAutoscaler](/docs/guides/neo4j/concepts/autoscaler.md)
- [Neo4jOpsRequest](/docs/guides/neo4j/concepts/opsrequest.md)
- [Neo4j vertical scaling](/docs/guides/neo4j/scaling/vertical-scaling/overview.md)

## How Compute Autoscaling Works

<figure align="center">
<img alt="Compute autoscaling process for Neo4j" src="/docs/images/neo4j/compute-autoscaling.png">
<figcaption align="center">Fig: Neo4j compute autoscaling process</figcaption>
</figure>

1. The user creates a KubeDB `Neo4j` resource.
2. The Provisioner creates the Neo4j cluster and its supporting Kubernetes resources.
3. The user creates a `Neo4jAutoscaler` with a `spec.compute.neo4j` policy.
4. The Autoscaler creates and watches a Vertical Pod Autoscaler recommendation for the Neo4j container.
5. After the pod lifetime and resource-difference thresholds are satisfied, the Autoscaler creates a `Neo4jOpsRequest` of type `VerticalScaling`.
6. Ops Manager applies the recommendation and updates the Neo4j pods within the configured minimum and maximum bounds.

The next guide demonstrates this workflow end to end.
10 changes: 10 additions & 0 deletions docs/guides/neo4j/autoscaler/storage/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
title: Storage Autoscaling
menu:
docs_{{ .version }}:
identifier: neo4j-storage-autoscaling
name: Storage Autoscaling
parent: neo4j-autoscaling
weight: 20
menu_name: docs_{{ .version }}
---
Loading
Loading