Skip to content

Commit c1cfa66

Browse files
authored
Merge pull request #22 from daviddob/persistent_volume_support
Implement PVC storage support
2 parents cde73b7 + cbd4702 commit c1cfa66

File tree

4 files changed

+83
-13
lines changed

4 files changed

+83
-13
lines changed

README.md

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,21 @@ helm install valheim-server valheim-k8s/valheim-k8s \
1919

2020
## Configuration
2121

22-
| Parameter | Description | Default |
23-
|:-------------------------------------------|:-----------------------------------------------------------|:----------------------------------|
24-
| `worldName` | Prefix of the world files to use (will make new if missing)| `example-world-name` |
25-
| `serverName` | Server name displayed in the server browser(s) | `example-server-name` |
26-
| `password` | Server password | `password` |
27-
| `storage.kind` | Storage strategy/soln used to provide the game-server with persistence | `hostvol` |
28-
| `storage.hostvol.path` | The folder to be mounted into /config in the game-server pod | `/data/valheim` |
29-
| `networking.serviceType` | The type of service e.g `NodePort`, `LoadBalancer` or `ClusterIP` | `LoadBalancer` |
30-
| `nodeSelector` | | `{}` |
22+
| Parameter | Description | Default |
23+
|:-------------------------------------------|:-----------------------------------------------------------------------|:------------------------|
24+
| `worldName` | Prefix of the world files to use (will make new if missing) | `example-world-name` |
25+
| `serverName` | Server name displayed in the server browser(s) | `example-server-name` |
26+
| `password` | Server password | `password` |
27+
| `storage.kind` | Storage strategy/soln used to provide the game-server with persistence | `hostvol` |
28+
| `storage.hostvol.path` | The folder to be mounted into /config in the game-server pod | `/data/valheim` |
29+
| `storage.pvc.storageClassName` | The storageClass used to create the persistentVolumeClaim | `default` |
30+
| `storage.pvc.size` | The size of the persistent volume to be created | `1Gi` |
31+
| `networking.serviceType` | The type of service e.g `NodePort`, `LoadBalancer` or `ClusterIP` | `LoadBalancer` |
32+
| `nodeSelector` | | `{}` |
3133

3234
## Persistence
3335

34-
The only form of persistence currently available is through mounting a `hostvol`. Please create an issue if you would like support for specific cloud storage solutions via PVCs / storageclasses. They vary by provider so PRs / testers welcome for this.
36+
Currently persistence is supported through mounting a `hostvol` or via a `persistentVolumeClaim`. Please create an issue if you would like support for specific cloud storage solutions via PVCs / storageclasses. They vary by provider so PRs / testers welcome for this.
3537

3638
### Using a Host Volume
3739

@@ -41,6 +43,12 @@ $ ls /data/valheim
4143
adminlist.txt backups bannedlist.txt permittedlist.txt prefs worlds
4244
```
4345

46+
### Using a persistentVolumeClaim
47+
48+
To use a `persistentVolumeClaim` for storage, you will need to first set up your CSI and StorageClass for your K8s cluster. Information regarding that differs by cloud provider and there are several guides available for configuring each of them.
49+
50+
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).
51+
4452
### Using an existing world
4553

4654
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:

chart/templates/deployment.yaml

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ spec:
66
selector:
77
matchLabels:
88
app: valheim-server
9+
strategy:
10+
type: Recreate
911
template:
1012
metadata:
1113
labels:
@@ -25,24 +27,51 @@ spec:
2527
value: {{ .Values.worldName }}
2628
- name: SERVER_PASS
2729
value: {{ .Values.password }}
30+
{{ if .Values.extraEnvironmentVars -}}
31+
{{ range $key, $value := .Values.extraEnvironmentVars }}
32+
- name: {{ $key }}
33+
value: {{ $value | quote }}
34+
{{ end -}}
35+
{{ end -}}
2836
ports:
2937
- containerPort: 2456
3038
name: game1
3139
- containerPort: 2457
3240
name: game2
3341
- containerPort: 2458
3442
name: game3
35-
{{ if eq .Values.storage.kind "hostvol" }}
3643
volumeMounts:
44+
{{ if .Values.storage.kind }}
3745
- mountPath: /config
3846
name: gamefiles
3947
{{ end }}
48+
{{ range .Values.extraVolumes }}
49+
- name: {{ .name }}
50+
readOnly: true
51+
mountPath: /extraVolumes/{{ .name }}
52+
{{ end }}
4053
resources: {{- toYaml .Values.resources | nindent 10 }}
41-
{{ if eq .Values.storage.kind "hostvol" }}
4254
volumes:
55+
{{ if eq .Values.storage.kind "hostvol" }}
4356
- name: gamefiles
4457
hostPath:
4558
path: {{ .Values.storage.hostvol.path }}
4659
type: Directory
4760
{{ end }}
48-
61+
{{ if eq .Values.storage.kind "persistentVolumeClaim" }}
62+
- name: gamefiles
63+
persistentVolumeClaim:
64+
claimName: valheim-server-world-data
65+
{{ end }}
66+
{{ range .Values.extraVolumes }}
67+
- name: {{ .name }}
68+
{{ .type }}:
69+
{{ if (eq .type "configMap") }}
70+
name: {{ .name }}
71+
{{ else if (eq .type "secret") }}
72+
secretName: {{ .name }}
73+
{{ if .defaultMode }}
74+
defaultMode: {{ .defaultMode }}
75+
{{ end }}
76+
{{ end }}
77+
{{ end }}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{{ if eq .Values.storage.kind "persistentVolumeClaim" }}
2+
apiVersion: v1
3+
kind: PersistentVolumeClaim
4+
metadata:
5+
name: valheim-server-world-data
6+
spec:
7+
{{ if .Values.storage.pvc.storageClassName }}
8+
storageClassName: {{ .Values.storage.pvc.storageClassName }}
9+
{{ end }}
10+
accessModes:
11+
- ReadWriteOnce
12+
resources:
13+
requests:
14+
storage: {{ .Values.storage.pvc.size }}
15+
{{ end }}

chart/values.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,26 @@ storage:
88
kind: hostvol
99
hostvol:
1010
path: /data/valheim
11+
pvc:
12+
size: 1Gi
1113

1214
networking:
1315
serviceType: LoadBalancer
1416

1517
nodeSelector: {}
18+
19+
# resources:
20+
# requests:
21+
# memory: "4Gi"
22+
# cpu: "2000m"
23+
24+
# extraEnvironmentVars:
25+
# BACKUPS: true
26+
# BACKUPS_CRON: "0 * * * *"
27+
# BACKUPS_MAX_AGE: 3
28+
# POST_BACKUP_HOOK: "timeout 300 scp -i /extraVolumes/backup-ssh-key/ssh-privatekey -o StrictHostKeyChecking=no @BACKUP_FILE@ [email protected]:~/valheim_backups/$(basename @BACKUP_FILE@)"
29+
30+
# extraVolumes:
31+
# - type: secret
32+
# name: backup-ssh-key
33+
# defaultMode: 0600

0 commit comments

Comments
 (0)