This repo contains all things necessary to automate setting up a Valheim server in GKE.
- Helm > v3.0
- Terraform > v14.0
You can skip this if you already have a GKE cluster. Autopilot is not supported but may work. You can't add capabilities and this container modifies CAP_SYS_NICE so it may impact performance.
cp terraform.tfvars.example terraform.tfvars
- edit
terraform.tfvars
(see below for inputs) make init
,make apply
make start
or ./start_server.sh
This script will invoke the Cloud Function to scale up the node pool, print logs if there is an error, otherwise wait for the pod to be marked as ready
make init
make plan
make apply
make docs
- Generate TF docs
Name | Description | Type | Default | Required |
---|---|---|---|---|
apis_required | a list of APIs to enable | list(string) |
n/a | yes |
artifactrepo | Name of AR to create | string |
"blank" |
no |
backup_cf_memory | MB to give the backup function. Must exceed the size of your backup file | number |
n/a | yes |
backup_function_schedule | cron schedule for backup in UTC | string |
"0 9 * * *" |
no |
bucket_name | Bucket name to create. Used to store world backups | string |
n/a | yes |
cloudscheduler_location | Location for cloud scheduler | string |
n/a | yes |
cluster_name | Name of GKE cluster | string |
n/a | yes |
container_name | Name of the container in the pod | string |
n/a | yes |
create_artifact_registry | n/a | bool |
n/a | yes |
dr_region | The DR region to host the DR bucket in | string |
n/a | yes |
ip_range_pods | The NAME of the secondary range to use for pods. Note this MUST exist already. | string |
"pods" |
no |
ip_range_services | The NAME of the secondary range to use for services. Note this MUST exist already. | string |
"services" |
no |
machine_type | Type to use for node pool | string |
"e2-standard-2" |
no |
master_authorized_networks | A list of cidrs to allow to talk to the control plane | list(object({ cidr_block = string, display_name = string })) |
n/a | yes |
metrics_baseline | Threshold CPU value to scaledown. Defines cluster idle state. Uses container/cpu/core_usage_time metric | string |
n/a | yes |
namespace | Kubernetes namespace to use | string |
"default" |
no |
network | The VPC network to host the cluster in | string |
"default" |
no |
project | GCP Project to create resources in | string |
n/a | yes |
region | The region to host the cluster in | string |
n/a | yes |
scaledown_function_schedule | cron schedule for backup in UTC | string |
"0 * * * *" |
no |
scaleup_users | A list of principals which are allowed to invoke the scale up function | list(string) |
n/a | yes |
subnetwork | The subnetwork to host the cluster in | string |
"default" |
no |
zones | Which zones to make the cluster in. Set to a single zone for free tier | list(string) |
n/a | yes |
- Get kubectl config
gcloud container clusters get-credentials (cluster name) --region (region)
- Deploy helm chart It will prompt for a password so it is not stored in your history.
scripts/create_helm_server.sh (install|upgrade)
Server config data (world, config) is stored on a PVC and server backups are copied to GCS. This means it doesn't really matter if you lose your cluster you just need your backup zip.
GKE Cluster and node pool - these run the workloads Backup Cloud Function + Cloud Scheduler job - grabs a daily backup and optionally copies it to a secondary bucket Scaledown Cloud Function + Cloud Scheduler job - checks the pod CPU metrics and determines when to scale node pool to 0 Scaleup Cloud Function - scales node pool to 1 upon invocation
This uses a modified helm chart from https://addyvan.github.io/valheim-k8s/ This uses the container from https://github.com/lloesche/valheim-server-docker