Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add persistentVolume for static volumes #354

Merged
merged 10 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
465 changes: 235 additions & 230 deletions charts/nautobot/README.md

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions charts/nautobot/templates/job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,12 @@ spec:
{{- end }}
volumes:
- name: "nautobot-static"
{{- if $.Values.nautobot.persistenceStaticFiles.enabled }}
persistentVolumeClaim:
claimName: {{ include "common.names.fullname" $ }}-static
{{- else }}
emptyDir: {}
{{- end }}
- name: "git-repos"
emptyDir: {}
- name: "nautobot-config"
Expand Down
5 changes: 5 additions & 0 deletions charts/nautobot/templates/nautobot-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,12 @@ spec:
terminationGracePeriodSeconds: {{ $nautobot.terminationGracePeriodSeconds }}
volumes:
- name: "nautobot-static"
{{- if $nautobot.persistenceStaticFiles.enabled }}
persistentVolumeClaim:
claimName: {{ include "common.names.fullname" $ }}-static
{{- else }}
emptyDir: {}
{{- end }}
- name: "git-repos"
emptyDir: {}
- name: "nautobot-config"
Expand Down
35 changes: 35 additions & 0 deletions charts/nautobot/templates/pvc-static.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{{- if .Values.nautobot.enabled -}}
{{- if .Values.nautobot.persistenceStaticFiles.enabled -}}
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: {{ include "common.names.fullname" $ }}-static
namespace: {{ .Release.Namespace | quote }}
labels: {{- include "common.labels.standard" $ | nindent 4 }}
app.kubernetes.io/component: nautobot-static-pvc
{{- if .Values.commonLabels }}
{{- include "common.tplvalues.render" ( dict "value" $.Values.commonLabels "context" $ ) | nindent 4 }}
{{- end }}
{{- if .Values.commonAnnotations }}
annotations: {{- include "common.tplvalues.render" ( dict "value" $.Values.commonAnnotations "context" $ ) | nindent 4 }}
{{- end }}
spec:
{{- if .Values.nautobot.persistenceStaticFiles.storageClassName }}
{{- if (eq "-" .Values.nautobot.persistenceStaticFiles.storageClassName) }}
storageClassName: ""
{{- else }}
storageClassName: {{ .Values.nautobot.persistenceStaticFiles.storageClassName | quote }}
{{- end }}
{{- end }}
accessModes:
- {{ .Values.nautobot.persistenceStaticFiles.accessMode | quote }}
resources:
requests:
storage: {{ .Values.nautobot.persistenceStaticFiles.size | quote }}
{{- with .Values.nautobot.persistenceStaticFiles.selector }}
selector:
{{- toYaml . | nindent 4 }}
{{- end }}
{{ end -}}
{{ end -}}
29 changes: 29 additions & 0 deletions charts/nautobot/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,35 @@
}
}
},
"persistenceStaticFiles": {
"type": "object",
"additionalProperties": false,
"properties": {
"enabled": {
"type": "boolean"
},
"storageClassName": {
"type": "string"
},
"accessMode": {
"type": "string"
},
"size": {
"type": "string"
},
"selector": {
"type": "object"
}
},
"required": [
"accessMode",
"enabled",
"selector",
"size",
"storageClassName"
],
"title": "Persistence"
},
"command": {
"type": "array",
"items": {
Expand Down
18 changes: 17 additions & 1 deletion charts/nautobot/values.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
# -- (map[string]string) Annotations to be applied to ALL resources created by this chart
commonAnnotations: {}

# Nautobot UI front end service
service:
# -- (`ExternalName`, `ClusterIP`, `NodePort`, or `LoadBalancer`) [[ref](https://kubernetes.io/docs/concepts/services-networking/service/)] Kubernetes service type, valid values: `ExternalName`, `ClusterIP`, `NodePort`, or `LoadBalancer`
Expand Down Expand Up @@ -236,6 +235,23 @@ nautobot:
value: 2
periodSeconds: 15

# Add a Persistent Volume Claim for Nautobot static files
persistenceStaticFiles:
# --- Enable PVC and the relevant volumes
enabled: false
# --- [Kubernetes StorageClass Name](https://kubernetes.io/docs/concepts/storage/storage-classes/), for the creation of Persistent Volume Claim
storageClassName: ""
# --- [Kubernetes Volumes AccessMode](https://kubernetes.io/docs/concepts/storage/storage-classes/)
accessMode: "ReadWriteOnce"
# --- Persistent storage size request
size: "1Gi"
# --- [Kubernetes PVC Selectors](https://kubernetes.io/docs/concepts/storage/persistent-volumes/#selector) to specify volume for Persistent Volume Claim
selector: {}
# e.g.
# selector:
# matchLabel:
# nautobot-storage: static

# Nautobot NGINX configuration
nginx:
# -- Enable an nginx sidecar to proxy Nautobot traffic (can be useful for large deployments)
Expand Down
1 change: 1 addition & 0 deletions contrib/minikube.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ nautobot:
resources:
requests: null
limits: null

nginx:
enabled: false
resources:
Expand Down
1 change: 1 addition & 0 deletions docs/advanced-features/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ With [Kubernetes](https://kubernetes.io/), public clouds, and the [dependency su
* [Ingress](ingress/)
* [MySQL Support](mysql/)
* [Nautobot as a Subchart](nautobot-as-subchart/)
* [Persistent Volume for Static Files](persistence/)
* [PostgreSQL High Availability](postgresql-ha/)
* [PostgreSQL TLS](postgresql-tls/)
* [Prometheus Operator Metrics](prometheus-metrics/)
Expand Down
29 changes: 29 additions & 0 deletions docs/advanced-features/persistence.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Persistence for Static files
ubajze marked this conversation as resolved.
Show resolved Hide resolved

The recommended way to store static files is to use an external shared storage such as [using S3 for Django storage](https://docs.nautobot.com/projects/core/en/stable/user-guide/administration/guides/s3-django-storage/). That said, it is also possible to leverage Kubernetes Persistent Volumes, following the below setting a Persistent Volume Claim is created and mounted it at the `/opt/nautobot/static` path of the Pods.

```yaml
nautobot:
persistence:
enabled: true
storageClass: "your-storage-class"
accessMode: "ReadWriteMany"
size: "1Gi"
```

Unfortunately, if the underlying storage solution does not support the `ReadWriteMany` option, you have to use node affinity in order for the Pods of the deployment to be scheduled on the same node as the Persistent Volume. Below there is an example using Node labels as selector to create the PVC and schedule the Pods in the same node.

```yaml
nautobot:
persistence:
enabled: true
storageClass: "your-storage-class"
size: "1Gi"
selector:
matchLabel:
nautobot-storage: static

# Selector for the Pods of the deployment.
nodeSelector:
nautobot-storage: static
```
Loading
Loading