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

Support using existing PVC #55

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ helm install valheim-server valheim-k8s/valheim-k8s \
| `storage.hostvol.path` | The folder to be mounted into /config in the game-server pod | `/data/valheim` |
| `storage.pvc.storageClassName` | The storageClass used to create the persistentVolumeClaim | `default` |
| `storage.pvc.size` | The size of the persistent volume to be created | `1Gi` |
| `storage.pvc.existingClaim` | The existing persistentVolumeClaim to use if set | None |
| `serverStorage.kind` | Storage strategy/soln used to save the server installation files | `hostvol` |
| `serverStorage.hostvol.path` | The folder to be mounted into /opt/valheim in the game-server pod | `/data/valheim-server` |
| `serverStorage.pvc.storageClassName` | The storageClass used to create the persistentVolumeClaim | `default` |
| `serverStorage.pvc.size` | The size of the persistent volume to be created | `5Gi` |
| `serverStorage.pvc.existingClaim` | The existing persistentVolumeClaim to use if set | None |
| `useHostNetworking` | If true, set pod.spec.hostNetwork = true and don't create a service | `false` |
| `networking.serviceType` | The type of service e.g `NodePort`, `LoadBalancer` or `ClusterIP` | `LoadBalancer` |
| `networking.loadBalancerIP` | A user supplied IP for service type LoadBalancer | None |
Expand Down Expand Up @@ -70,6 +72,8 @@ To use a `persistentVolumeClaim` for storage, you will need to first set up your

Once you have your StorageClass set up, set `storage.kind` to `persistentVolumeClaim`, optionally set `storage.pvc.storageClassName` to the name of your previously configured StorageClass (or it will use the default StorageClass), and set `storage.pvc.size` to the size of the volume to create (default 1Gi).

If you already have a `persistentVolumeClaim` and `persistentVolume`, perhaps set up manually or restored from a backup, you can set `storage.pvc.existingClaim` to the name of your `persistentVolumeClaim`.

### Using an existing world

To use an existing world simply set the `worldName` parameter to the name of your world then save the `.db` and `.fwl` files to the directory mounted into the pod. For example, if your world is named `myworld` then set `worldName: myworld` in your values file (or `--set worldName=myworld`) and assuming you are mounting at `/data/valheim` then your directory should look like:
Expand Down
2 changes: 1 addition & 1 deletion chart/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: valheim-k8s
description: Basic chart for deploying valheim to a k8s homelab
icon: https://www.google.com/url?sa=i&url=https%3A%2F%2Fstore.steampowered.com%2Fapp%2F892970%2FValheim%2F&psig=AOvVaw1MMOQJzse-eyruGtGG0DEs&ust=1641045420126000&source=images&cd=vfe&ved=0CAsQjRxqFwoTCIDmhd2YjvUCFQAAAAAdAAAAABAJ
type: application
version: 2.0.1
version: 2.0.2

# upstream repo https://github.com/lloesche/valheim-server-docker
# doesn't have semantic versions so this field mean anything:
Expand Down
4 changes: 2 additions & 2 deletions chart/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ spec:
{{ if eq .Values.storage.kind "persistentVolumeClaim" }}
- name: gamefiles
persistentVolumeClaim:
claimName: {{ .Release.Name }}-world-data
claimName: {{ if .Values.storage.pvc.existingClaim }}{{ .Values.storage.pvc.existingClaim }}{{ else }}{{ .Release.Name }}-world-data{{ end }}
{{ end }}
{{ if eq .Values.serverStorage.kind "persistentVolumeClaim" }}
- name: serverfiles
persistentVolumeClaim:
claimName: {{ .Release.Name }}-server-base-data
claimName: {{ if .Values.serverStorage.pvc.existingClaim }}{{ .Values.serverStorage.pvc.existingClaim }}{{ else }}{{ .Release.Name }}-server-base-data{{ end }}
{{ end }}
{{ range .Values.extraVolumes }}
- name: {{ .name }}
Expand Down
6 changes: 3 additions & 3 deletions chart/templates/persistentvolumeclaim.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{ if eq .Values.storage.kind "persistentVolumeClaim" }}
{{ if and (eq .Values.storage.kind "persistentVolumeClaim") (not .Values.storage.pvc.existingClaim) }}
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
Expand All @@ -15,7 +15,7 @@ spec:
storage: {{ .Values.storage.pvc.size }}
{{ end }}
---
{{ if eq .Values.serverStorage.kind "persistentVolumeClaim" }}
{{ if and (eq .Values.serverStorage.kind "persistentVolumeClaim") (not .Values.serverStorage.pvc.existingClaim) }}
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
Expand All @@ -30,4 +30,4 @@ spec:
resources:
requests:
storage: {{ .Values.serverStorage.pvc.size }}
{{ end }}
{{ end }}
24 changes: 23 additions & 1 deletion chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,28 @@ serverStorage:
pvc:
size: 5Gi

#storage:
# kind: persistentVolumeClaim
# pvc:
# existingClaim: example-pvc-name

#storage:
# kind: persistentVolumeClaim
# pvc:
# storageClass: example-storage-class
# size: 1Gi

#serverStorage:
# kind: persistentVolumeClaim
# pvc:
# existingClaim: example-pvc-name

#serverStorage:
# kind: persistentVolumeClaim
# pvc:
# storageClass: example-storage-class
# size: 5Gi

# if useHostNetworking is set to true then no service is created
# and the gamePort
useHostNetworking: false
Expand Down Expand Up @@ -57,4 +79,4 @@ tolerations: {}
# extraVolumes:
# - type: secret
# name: backup-ssh-key
# defaultMode: 0600
# defaultMode: 0600
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0.1
2.0.2