Factorio kubernetes game server
In a previous post I deployed a factorio game server using docker. The same image can be deployed onto kubernetes.
Installing factorio on Kubernetes
Requirements
In order to proceed, you must have a k8s platform, the kubectl
command line utility, and a persistent provider. If you are not familiar with kubernetes, check out a previous post to get started.
Deployment to k8s
In order to deploy factorio onto a kubernetes cluster, the deployment needs to be configured in YAML
format document.
factorio manifests
factorio-pvc.yaml
This file will request persistent storage for the container(s). This will utilize the longhorn
storage provider. For more information, see a previous post on the topic.
|
|
factorio-deploy.yaml
|
|
Install to your cluster
To install these on your cluster, use kubectl
. I recommend creating a dedicated namespace
in the cluster for this game server.
|
|
Verify it worked:
|
|
Create an in cluster service object
Enter the following command with the kubectl
utility to create a cluster service object that can be used to route traffic to the pods.
|
|
View the newly created object:
|
|
The output should be similar:
|
|
Take note of the NodePort
as this will be the entrypoint to connect to the game server.
Any worker node on the cluster will accept traffic to this port and route it to the factorio pod. Do not run multiple replicas of the server because the map storage is similar to a database, multiple processes modifying the map at the same time will cause corruption.
Game server configuration files can be found inside the factorio pod under /factorio
. If you make changes, you will need to scale the pods to 0 and then scale back up to effectively restart the game server.
Scaling the server pod
Enter this to get the factorio replicaset:
|
|
Take the name of the ReplicaSet and apply it to the following command to update the replica count:
|
|
Mods
In order to move mods onto the container’s persistent storage, you will need to copy the files from your game’s mods
directory onto the server using kubectl cp
|
|
Replace with the name of your factorio pod: kubectl get po -n factorio
Once the mods are copied, delete the pod to reload the server with the mods.
Next steps
To delete these resources, delete the objects created for the factorio server: Deployment
, Service
, PersistentVolumeClaim
and PersistentVolume
if your storage class does not automatically delete unclaimed volumes.
Troubleshooting
If you have trouble accessing the game server from the game itself, check that there is not a firewall blocking the port exposed as a NodePort
.
The logs of the factorio pod may also provide information as to what might be wrong:
kubectl get logs factorio-foobar
Replace with the name of your factorio pod: kubectl get po -n factorio
.