ScaleSec / valheim-gke-server

Valheim server

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Valheim GKE Server

This repo contains all things necessary to automate setting up a Valheim server in GKE.

Architecture

image

Requirements

  • Helm > v3.0
  • Terraform > v14.0

Getting started

Cluster setup

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.

  1. cp terraform.tfvars.example terraform.tfvars
  2. edit terraform.tfvars (see below for inputs)
  3. make init, make apply

Starting server

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

Terraform Commands

  • make init
  • make plan
  • make apply
  • make docs - Generate TF docs

Inputs

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

Server deployment

  1. Get kubectl config
gcloud container clusters get-credentials (cluster name) --region (region) 
  1. 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.

Components

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

Credits

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

About

Valheim server

License:Other


Languages

Language:HCL 52.9%Language:Go 41.5%Language:Shell 4.4%Language:Makefile 1.2%