Skip to content

Commit

Permalink
[Feature #884] Helm chart for Kubernetes deployments PR#902 (#971)
Browse files Browse the repository at this point in the history
* Include the Helm Chart and Kubernetes YAMLs

- Includes the Helm chart required for the NeoDash deployment for the
  Kubernetes clusters
- Includes the example YAML files for the Kubernetes manifests
- Appropriate document changes to include the new Kubernetes
  deployments.

Signed-off-by: Lolla, Venkata <venkata.lolla@fMR.COM>

* Fix the chart notes

Signed-off-by: Lolla, Venkata <venkata.lolla@fMR.COM>

* Patch a typo in the build-and-run.adoc file

Signed-off-by: Lolla, Venkata <venkata.lolla@fMR.COM>

* Resolves SonarCloud warning

Signed-off-by: Lolla, Venkata <venkata.lolla@fMR.COM>

* Review + small fixes, LGTM

---------

Signed-off-by: Lolla, Venkata <venkata.lolla@fMR.COM>
Co-authored-by: Lolla, Venkata <venkata.lolla@fMR.COM>
  • Loading branch information
msenechal and venkatalolla authored Nov 14, 2024
1 parent 416b8f8 commit d822773
Show file tree
Hide file tree
Showing 15 changed files with 741 additions and 1 deletion.
119 changes: 118 additions & 1 deletion docs/modules/ROOT/pages/developer-guide/build-and-run.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ docker run -it –rm -p 5005:5005 neodash

== Run on Kubernetes

An example of a pod definition YAML file to create a NeoDash pod in a cluster:
=== To deploy using YAML files

YAML examples are available in the https://github.com/neo4j-labs/neodash[NeoDash repository]. Here is an example of a pod definition YAML file to create a NeoDash pod in a cluster:

....
apiVersion: v1
Expand Down Expand Up @@ -108,3 +110,118 @@ spec:
selector:
project: neodash
....

=== To deploy using a Helm Charts

A Kubernetes Helm chart is available in the https://github.com/neo4j-labs/neodash[the NeoDash repository] and here is the full example of the Helm chart values.yaml file,

....
# Name override or full name override
nameOverride: ''
fullnameOverride: neodash-test
# Number of pods
replicaCount: 1
# Image Details
image:
repository: neo4jlabs/neodash
pullPolicy: IfNotPresent
tag: 'latest'
imagePullSecrets: [] # Image pull secret if any
# Pod annotations, labels and security context
podAnnotations: {}
podLabels: {}
podSecurityContext: {}
# Mode configuration using environment variables
# Set reader mode environment variables when enable_reader_mode is true
enable_reader_mode: true
env:
- name: "ssoEnabled"
value: "false"
- name: "standalone"
value: "true"
- name: "standaloneProtocol"
value: "neo4j+s"
- name: "standaloneHost"
value: "localhost"
- name: "standalonePort"
value: "7687"
- name: "standaloneDatabase"
value: neo4j
- name: "standaloneDashboardName"
value: "test"
- name: "standaloneDashboardDatabase"
value: neo4j
- name: "standaloneAllowLoad"
value: "false"
- name: "standaloneLoadFromOtherDatabases"
value: "false"
- name: "standaloneMultiDatabase"
value: "false"
# Environment variable from secret
envFromSecrets: []
# standaloneUsername:
# secretName: "neo4j-connection-secrets"
# key: "username"
# standalonePassword:
# secretName: "neo4j-connection-secrets"
# key: "password"
# Service details
service:
type: LoadBalancer # Can also be ClusterIP or NodePort
port: 5005 # For the service to listen in for Traffic
targetPort: 5005 # Target port is the container port
annotations: {} # Service annotations for the LoadBalance
# Ingress
ingress:
enabled: false # Enable Kubernetes Ingress
className: 'alb' # Class Name
annotations: {} # Cloud LoadBalancer annotations
hosts: []
# - host: neodash.example.com
# paths:
# - path: '/'
# pathType: Prefix
tls: []
# Pod resources request, limits and health check
resources:
requests:
memory: "64Mi"
cpu: "250m"
limits:
memory: "128Mi"
cpu: "500m"
livenessProbe:
httpGet:
path: /*
port: 5005
readinessProbe:
httpGet:
path: /*
port: 5005
# Pod Autoscaler
autoscaling:
enabled: false
# minReplicas: 1
# maxReplicas: 100
# targetCPUUtilizationPercentage: 80
# Pod Volumes
volumes: []
volumeMounts: []
# Service Account
serviceAccount:
create: true
automount: true
# annotations: {}
# name: ''
....
23 changes: 23 additions & 0 deletions k8s-deploy/neodash/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
24 changes: 24 additions & 0 deletions k8s-deploy/neodash/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: neodash
description: A NeoDash Helm chart for Kubernetes

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 1.0.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "2.4.9"
78 changes: 78 additions & 0 deletions k8s-deploy/neodash/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# NeoDash

![Version: 0.1.0](https://img.shields.io/badge/Version-0.1.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 1.16.0](https://img.shields.io/badge/AppVersion-1.16.0-informational?style=flat-square)

A NeoDash Helm chart for Kubernetes

## Resources

Following are the Kubernetes resources utilized for the NeoDash.

- Deployment
- Service
- Ingress
- Service Account
- Horizontal Pod Autoscalar (HPA)

## Values Configuration

| Key | Type | Default | Description |
|-----|------|---------|-------------|
| autoscaling.enabled | bool | `false` | Enable/disable Autoscaling |
| enable_reader_mode | bool | `true` | Enable/disable Reader mode |
| envFromSecrets | list | `[]` | Environment variables from secrets |
| fullnameOverride | string | `"neodash-test"` | Name override applies to all resources |
| image.pullPolicy | string | `"IfNotPresent"` | Image pull policy |
| image.repository | string | `"neo4jlabs/neodash"` | Image repository and Image name |
| image.tag | string | `"latest"` | Image version |
| imagePullSecrets | list | `[]` | Image pull secrets if any |
| podAnnotations | object | `{}` | Pod annotations |
| podLabels | object | `{}` | Additional labels |
| podSecurityContext | object | `{}` | Security Context if any |
| ingress.annotations | object | `{}` | Ingress Annotations for load balancers |
| ingress.className | string | `"alb"` | Ingress Class |
| ingress.enabled | bool | `false` | Enable/disable Ingress |
| ingress.hosts | list | `[]` | Host Details |
| ingress.tls | list | `[]` | TLS details |
| livenessProbe.httpGet.path | string | `"/*"` | LivenessProbe path |
| livenessProbe.httpGet.port | int | `5005` | LivenessProbe port |
| readinessProbe.httpGet.path | string | `"/*"` | Readiness path |
| readinessProbe.httpGet.port | int | `5005` | Readiness port |
| replicaCount | int | `1` | Replica count |
| resources.limits.cpu | string | `"500m"` | CPU limit |
| resources.limits.memory | string | `"128Mi"` | Memory limit |
| resources.requests.cpu | string | `"250m"` | CPU request |
| resources.requests.memory | string | `"64Mi"` | Memory request |
| service.annotations | object | `{}` | Service annotations |
| service.port | int | `5005` | Service port |
| service.targetPort | int | `5005` | Service target port |
| service.type | string | `"LoadBalancer"` | Type of service, other options are `ClusterIP` or `NodePort` |
| serviceAccount.automount | bool | `true` | Enable/disable service account auto mount to pod |
| serviceAccount.create | bool | `true` | Enable/disable service account |
| volumeMounts | list | `[]` | Volume mounts on pod |
| volumes | list | `[]` | Volumes for pod |
| env | list |<br><pre lang="YAML">- name: "ssoEnabled" &#13; value: "false" &#13;- name: "standalone" &#13; value: "true" &#13;- name: "standaloneProtocol" &#13; value: "neo4j+s" &#13;- name: "standaloneHost" &#13; value: "localhost" &#13;- name: "standalonePort" &#13; value: "7687" &#13;- name: "standaloneDatabase" &#13; value: "neo4j" &#13;- name: "standaloneDashboardName" &#13; value: "test" &#13;- name: "standaloneDashboardDatabase" &#13; value: "neo4j" &#13;- name: "standaloneAllowLoad" &#13; value: "false" &#13;- name: "standaloneLoadFromOtherDatabases" &#13; value: "false" &#13;- name: "standaloneMultiDatabase" &#13; value: "false" &#13;</pre> | Env variables for reader mode |

## Usage

- To install this helm chart run the following command,

```bash
helm install <release-name> ./neodash -n <namespace-name>
```

- To upgrade the release run the following command,

```bash
helm upgrade <release-name> ./neodash -n <namespace-name>
```

- To uninstall the release run the following command,

```bash
helm uninstall <release-name> -n <namespace-name>
```

> **Note:** To use custom values files, pass `-f <path-to-values-file>.yaml` for the above command.
> **Note:** To use custom values, pass `--set param=value` for the above command.
For example, to install neodash and set the service type to NodePort, run: `helm install <release-name> ./neodash -n <namespace-name> --set service.type=NodePort`
26 changes: 26 additions & 0 deletions k8s-deploy/neodash/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
The NeoDash application has been successfully deployed, here is the application URL:
{{- if .Values.ingress.enabled }}
{{- range $host := .Values.ingress.hosts }}
{{- range .paths }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }}
{{- end }}
{{- end }}
{{- else if contains "NodePort" .Values.service.type }}
Run the following command to retrieve the IP address:
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "neodash.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" .Values.service.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of the LoadBalancer by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "neodash.fullname" . }}'

Once available, run the following command to retrieve the IP address:
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "neodash.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
echo http://$SERVICE_IP:{{ .Values.service.port }}
{{- else if contains "ClusterIP" .Values.service.type }}
Run the following command to retrieve the IP address:
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "neodash.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
{{- end }}
62 changes: 62 additions & 0 deletions k8s-deploy/neodash/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "neodash.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "neodash.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "neodash.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "neodash.labels" -}}
helm.sh/chart: {{ include "neodash.chart" . }}
{{ include "neodash.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "neodash.selectorLabels" -}}
app.kubernetes.io/name: {{ include "neodash.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "neodash.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "neodash.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
Loading

0 comments on commit d822773

Please sign in to comment.