Deploying A Steam Dedicated Server On Kubernetes - Alter Way - Medium
Deploying A Steam Dedicated Server On Kubernetes - Alter Way - Medium
Deploying A Steam Dedicated Server On Kubernetes - Alter Way - Medium
You have 2 free stories left this month. Sign up and get an extra one for free.
Using steamcmd
Prerequisites
https://medium.com/alterway/deploying-a-steam-dedicated-server-on-kubernetes-645099d063e0 1/16
29/06/2020 Deploying a Steam dedicated server on Kubernetes - alter way - Medium
A Steam account
To own the game you want to install a server for (in our case CS:GO)
Docker installed
What is steamcmd ?
To install our dedicated server, we need a tool called “steamcmd”. This tool,
released by Valve, is a simple and generic way to install dedicated servers
for steam based games.
https://medium.com/alterway/deploying-a-steam-dedicated-server-on-kubernetes-645099d063e0 2/16
29/06/2020 Deploying a Steam dedicated server on Kubernetes - alter way - Medium
After that, we can launch the server with the following command :
Create a Docker image that contains the CS:GO dedicated server (using
steamcmd).
Create a “steam” user (or whatever the name, we just need a user other
than root).
Install steamcmd.
FROM debian:buster
ARG DEBIAN_FRONTEND=noninteractive
https://medium.com/alterway/deploying-a-steam-dedicated-server-on-kubernetes-645099d063e0 4/16
29/06/2020 Deploying a Steam dedicated server on Kubernetes - alter way - Medium
USER steam
WORKDIR /home/steam
EXPOSE 27015/udp
CMD ["/home/steam/entry.sh"]
https://medium.com/alterway/deploying-a-steam-dedicated-server-on-kubernetes-645099d063e0 5/16
29/06/2020 Deploying a Steam dedicated server on Kubernetes - alter way - Medium
As you can see, our steamcmd uses a script to install the dedicated server
called csgo_install.txt :
#!/bin/bash
if [[ -z "$SRCDS_TOKEN" ]]
then
echo "You must give a SRCDS_TOKEN"
exit 1
fi
https://medium.com/alterway/deploying-a-steam-dedicated-server-on-kubernetes-645099d063e0 6/16
29/06/2020 Deploying a Steam dedicated server on Kubernetes - alter way - Medium
We can now build our Docker image with the following command :
Note: Since CS:GO is quite big (25 GB), this build might take a while.
Now that we have built our CS:GO Docker image, we can run it on any
machine running Docker as follows :
https://medium.com/alterway/deploying-a-steam-dedicated-server-on-kubernetes-645099d063e0 7/16
29/06/2020 Deploying a Steam dedicated server on Kubernetes - alter way - Medium
Our image is now stored in our registry which means that our Kubernetes
cluster can now pull it and use it.
apiVersion: v1
kind: Namespace
metadata:
name: csgo-server
https://medium.com/alterway/deploying-a-steam-dedicated-server-on-kubernetes-645099d063e0 8/16
29/06/2020 Deploying a Steam dedicated server on Kubernetes - alter way - Medium
apiVersion: v1
data:
SRCDS_TOKEN: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX (base64 encoded)
kind: Secret
metadata:
name: steam-token
namespace: csgo-server
apiVersion: v1
data:
https://medium.com/alterway/deploying-a-steam-dedicated-server-on-kubernetes-645099d063e0 9/16
29/06/2020 Deploying a Steam dedicated server on Kubernetes - alter way - Medium
autoexec.cfg: |
hostname "Counter-Strike: Global Offensive Dedicated Server"
sv_cheats 0 //This should always be set, so you know it's not on
sv_lan 0 //This should always be set, so you know it's not on
exec banned_user.cfg
exec banned_ip.cfg
server.cfg: |
mp_autoteambalance 1
mp_limitteams 1
writeid
writeip
kind: ConfigMap
metadata:
name: csgo-configuration
namespace: csgo-server
Now that we have our Secret to store our Steam token and the configuration
for our server, we can now deploy it. For that, we will create a Deployment
that creates a container using the Docker image we made previously. We
also need to use the Secret and the ConfigMap we have just created. Here is
the YAML file for that Deployment:
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: csgo-deployment
name: csgo-deployment
namespace: csgo-server
spec:
https://medium.com/alterway/deploying-a-steam-dedicated-server-on-kubernetes-645099d063e0 10/16
29/06/2020 Deploying a Steam dedicated server on Kubernetes - alter way - Medium
replicas: 1
selector:
matchLabels:
app: csgo-deployment
template:
metadata:
labels:
app: csgo-deployment
spec:
containers:
- image: srcds.azurecr.io/csgo:latest
name: csgo-server
ports:
- containerPort: 27015
protocol: UDP
env:
- name: SRCDS_TOKEN
valueFrom:
secretKeyRef:
name: steam-token
key: SRCDS_TOKEN
volumeMounts:
- name: csgo-configuration-server-cfg
mountPath: /home/steam/csgo/csgo/server.cfg
subPath: server.cfg
- name: csgo-configuration-autoexec-cfg
mountPath: /home/steam/csgo/csgo/autoexec.cfg
subPath: autoexec.cfg
volumes:
- name: csgo-configuration-server-cfg
configMap:
name: csgo-configuration
items:
- key: server.cfg
path: server.cfg
https://medium.com/alterway/deploying-a-steam-dedicated-server-on-kubernetes-645099d063e0 11/16
29/06/2020 Deploying a Steam dedicated server on Kubernetes - alter way - Medium
- name: csgo-configuration-autoexec-cfg
configMap:
name: csgo-configuration
items:
- key: autoexec.cfg
path: autoexec.cfg
Last but not least, we need to create a Service to expose our server. We will
create a LoadBalancer that targets the 27015 UDP port of our container. We
are going to create a static public IP and assign it to our LoadBalancer :
apiVersion: v1
kind: Service
metadata:
labels:
app: csgo-ns
name: csgo-ns
namespace: csgo-server
https://medium.com/alterway/deploying-a-steam-dedicated-server-on-kubernetes-645099d063e0 12/16
29/06/2020 Deploying a Steam dedicated server on Kubernetes - alter way - Medium
spec:
ports:
- name: steam
port: 27015
protocol: UDP
targetPort: 27015
selector:
app: csgo-deployment
type: LoadBalancer
loadBalancerIP: 51.103.3.30
We also need to configure the outbound IP for our pods to be the same as
the LoadBalancer IP. Why are we doing that ? Because when the SRCDS
server starts, it calls the Steam servers to register itself (Listening IP based
on the outbound IP + Listening port). To be able to connect to our server,
we need to use the exact same registered listening IP and listening port
(Otherwise, the connection to the server is rejected and we are back to the
menu). Which means that our listening IP for our Load Balancer service
must be the same as the outbound IP used by our pods. We can do so as
follows :
https://medium.com/alterway/deploying-a-steam-dedicated-server-on-kubernetes-645099d063e0 13/16
29/06/2020 Deploying a Steam dedicated server on Kubernetes - alter way - Medium
Alright, we defined all the resources we need to deploy our CS:GO server,
we can now deploy it :
Note: Since the image is quite big (25 GB), the first creation of our
deployment might take a while (the pod is in the ContainerCreating state
for a moment, because the image needs to be pulled, which can be a bit
long).
https://medium.com/alterway/deploying-a-steam-dedicated-server-on-kubernetes-645099d063e0 14/16
29/06/2020 Deploying a Steam dedicated server on Kubernetes - alter way - Medium
Connection command
https://medium.com/alterway/deploying-a-steam-dedicated-server-on-kubernetes-645099d063e0 15/16
29/06/2020 Deploying a Steam dedicated server on Kubernetes - alter way - Medium
Of course, our server is pretty basic, but we can easily customize it with our
ConfigMap.
Note: You can find all the resources in my personal gitlab repository.
https://medium.com/alterway/deploying-a-steam-dedicated-server-on-kubernetes-645099d063e0 16/16