diff --git a/Chart.yaml b/Chart.yaml new file mode 100644 index 0000000..39c62d0 --- /dev/null +++ b/Chart.yaml @@ -0,0 +1,14 @@ +apiVersion: v2 +name: valheim +description: Helm chart to run a Valheim dedicated game server on Kubernetes +type: application +version: 0.1.0 +appVersion: "latest" +home: https://git.smokyzone.de/SmokyZone/valheim-gitops +sources: + - https://git.smokyzone.de/SmokyZone/valheim-gitops +keywords: + - valheim + - gameserver +maintainers: + - name: SmokyZone diff --git a/README.md b/README.md index e69de29..bd1ce63 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,43 @@ +# valheim-gitops + +Helm chart to run a [Valheim](https://www.valheimgame.com/) dedicated server on Kubernetes, +using the community [`lloesche/valheim-server`](https://github.com/lloesche/valheim-server-docker) +image. + +## What's included + +- **Namespace** (`valheim` by default, toggle with `namespace.create`) +- **StatefulSet** running the game server with a persistent volume for world data + (`/config` and `/opt/valheim`) so the world survives restarts/upgrades +- **Secret** holding the server join password (`SERVER_PASS`) +- **Service** (`NodePort` by default) exposing the game (2456/udp), query (2457/udp) + and crossplay (2458/udp) ports +- Headless **Service** for the StatefulSet + +## Configuration + +See [`values.yaml`](values.yaml) for all options. Important ones: + +| Key | Description | Default | +|---|---|---| +| `server.name` | Server name shown in the browser | `Valtersheim` | +| `server.worldName` | World save name | `Midgard` | +| `server.password` | Join password (override via `-f secret-values.yaml`, never commit real passwords) | `changeme-please-override` | +| `service.type` | `NodePort` or `LoadBalancer` | `NodePort` | +| `persistence.storageClassName` | StorageClass for world data, empty = cluster default | `""` | +| `persistence.size` | Size of the world data volume | `10Gi` | + +## Usage + +```sh +helm upgrade --install valheim . -n valheim --create-namespace \ + --set server.password= +``` + +### Deploying via ArgoCD + +This repository is intended to be deployed as an ArgoCD `Application` using this +chart as the Helm source (see `apps-in-apps` repo for the bootstrap Application). + +> Never commit real passwords in `values.yaml`. Use `--set`, a separate values file +> excluded from git, or a secrets manager (SealedSecrets/ExternalSecrets) for production. diff --git a/templates/namespace.yaml b/templates/namespace.yaml new file mode 100644 index 0000000..fbbe856 --- /dev/null +++ b/templates/namespace.yaml @@ -0,0 +1,9 @@ +{{- if .Values.namespace.create }} +apiVersion: v1 +kind: Namespace +metadata: + name: {{ .Values.namespace.name }} + labels: + app.kubernetes.io/name: valheim + app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} diff --git a/templates/secret.yaml b/templates/secret.yaml new file mode 100644 index 0000000..b04a46e --- /dev/null +++ b/templates/secret.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: Secret +metadata: + name: valheim-server + namespace: {{ .Values.namespace.name }} + labels: + app.kubernetes.io/name: valheim +type: Opaque +stringData: + SERVER_PASS: {{ .Values.server.password | quote }} diff --git a/templates/service.yaml b/templates/service.yaml new file mode 100644 index 0000000..d353c17 --- /dev/null +++ b/templates/service.yaml @@ -0,0 +1,49 @@ +apiVersion: v1 +kind: Service +metadata: + name: valheim-headless + namespace: {{ .Values.namespace.name }} + labels: + app.kubernetes.io/name: valheim +spec: + clusterIP: None + selector: + app.kubernetes.io/name: valheim + ports: + - name: game + port: {{ .Values.service.gamePort }} + protocol: UDP +--- +apiVersion: v1 +kind: Service +metadata: + name: valheim + namespace: {{ .Values.namespace.name }} + labels: + app.kubernetes.io/name: valheim +spec: + type: {{ .Values.service.type }} + selector: + app.kubernetes.io/name: valheim + ports: + - name: game + port: {{ .Values.service.gamePort }} + targetPort: {{ .Values.service.gamePort }} + protocol: UDP + {{- if and (eq .Values.service.type "NodePort") .Values.service.nodePorts.game }} + nodePort: {{ .Values.service.nodePorts.game }} + {{- end }} + - name: query + port: {{ .Values.service.queryPort }} + targetPort: {{ .Values.service.queryPort }} + protocol: UDP + {{- if and (eq .Values.service.type "NodePort") .Values.service.nodePorts.query }} + nodePort: {{ .Values.service.nodePorts.query }} + {{- end }} + - name: crossplay + port: {{ .Values.service.crossplayPort }} + targetPort: {{ .Values.service.crossplayPort }} + protocol: UDP + {{- if and (eq .Values.service.type "NodePort") .Values.service.nodePorts.crossplay }} + nodePort: {{ .Values.service.nodePorts.crossplay }} + {{- end }} diff --git a/templates/statefulset.yaml b/templates/statefulset.yaml new file mode 100644 index 0000000..125e07f --- /dev/null +++ b/templates/statefulset.yaml @@ -0,0 +1,106 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: valheim + namespace: {{ .Values.namespace.name }} + labels: + app.kubernetes.io/name: valheim +spec: + serviceName: valheim-headless + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/name: valheim + template: + metadata: + labels: + app.kubernetes.io/name: valheim + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + spec: + securityContext: + {{- toYaml .Values.securityContext | nindent 8 }} + containers: + - name: valheim-server + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - name: game + containerPort: {{ .Values.service.gamePort }} + protocol: UDP + - name: query + containerPort: {{ .Values.service.queryPort }} + protocol: UDP + - name: crossplay + containerPort: {{ .Values.service.crossplayPort }} + protocol: UDP + env: + - name: SERVER_NAME + value: {{ .Values.server.name | quote }} + - name: WORLD_NAME + value: {{ .Values.server.worldName | quote }} + - name: SERVER_PASS + valueFrom: + secretKeyRef: + name: valheim-server + key: SERVER_PASS + - name: SERVER_PUBLIC + value: {{ .Values.server.public | ternary "1" "0" | quote }} + {{- if .Values.server.admins }} + - name: ADMINLIST_IDS + value: {{ .Values.server.admins | quote }} + {{- end }} + - name: UPDATE_INTERVAL + value: {{ .Values.server.updateIntervalSeconds | quote }} + - name: BACKUPS_INTERVAL + value: {{ .Values.server.backupIntervalSeconds | quote }} + {{- if .Values.server.backupCronExpression }} + - name: BACKUPS_CRON + value: {{ .Values.server.backupCronExpression | quote }} + {{- end }} + {{- range .Values.server.extraEnv }} + - name: {{ .name }} + value: {{ .value | quote }} + {{- end }} + volumeMounts: + - name: valheim-data + mountPath: /config + subPath: config + - name: valheim-data + mountPath: /opt/valheim + subPath: server + resources: + {{- toYaml .Values.resources | nindent 12 }} + {{- if not .Values.persistence.enabled }} + volumes: + - name: valheim-data + emptyDir: {} + {{- end }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- if .Values.persistence.enabled }} + volumeClaimTemplates: + - metadata: + name: valheim-data + spec: + accessModes: + {{- toYaml .Values.persistence.accessModes | nindent 10 }} + {{- if .Values.persistence.storageClassName }} + storageClassName: {{ .Values.persistence.storageClassName }} + {{- end }} + resources: + requests: + storage: {{ .Values.persistence.size }} + {{- end }} diff --git a/values.yaml b/values.yaml new file mode 100644 index 0000000..18ddfbc --- /dev/null +++ b/values.yaml @@ -0,0 +1,66 @@ +## Default values for the valheim chart + +namespace: + # If true, the chart creates the namespace itself. + create: true + name: valheim + +image: + repository: lloesche/valheim-server + tag: latest + pullPolicy: IfNotPresent + +server: + name: "Valtersheim" + worldName: "Midgard" + # Leave empty to auto-generate a random password on first deploy via the secret below. + # It is strongly recommended to override this via --set or a separate values file that is + # NOT committed to git (or use SealedSecrets/ExternalSecrets in production). + password: "changeme-please-override" + public: true + # Comma separated SteamIDs allowed to join/admin the server (optional) + admins: "" + updateIntervalSeconds: 900 + backupIntervalSeconds: 3600 + backupCronExpression: "" + # extra env vars appended to the container, e.g. SERVER_ARGS, CROSSPLAY, etc. + extraEnv: [] + # - name: CROSSPLAY + # value: "true" + +service: + type: NodePort + # Game (2456), query (2457) and crossplay (2458) ports. + gamePort: 2456 + queryPort: 2457 + crossplayPort: 2458 + # Only used when type is NodePort. Leave 0 to let Kubernetes pick a random port. + nodePorts: + game: 30456 + query: 30457 + crossplay: 30458 + +persistence: + enabled: true + size: 10Gi + # Leave empty to use the cluster default StorageClass. + storageClassName: "" + accessModes: + - ReadWriteOnce + +resources: + requests: + cpu: 1000m + memory: 3Gi + limits: + cpu: 2000m + memory: 6Gi + +securityContext: + fsGroup: 1000 + +podAnnotations: {} + +nodeSelector: {} +tolerations: [] +affinity: {}