Skip to content

Instantly share code, notes, and snippets.

@kordless
Last active June 19, 2023 15:50
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save kordless/424102dfd6f348f3b8d64b33c52e17ba to your computer and use it in GitHub Desktop.
Save kordless/424102dfd6f348f3b8d64b33c52e17ba to your computer and use it in GitHub Desktop.
Rust Server Deployment for Google Container Engine

Howdy Y'all! I'm @kordless on YouTube and I occasionally play and stream Rust, the game.

This repo is for deploying a Rust Server running on Google Container Engine. Google has a deal going where you can get $300 of free credits for a year on Google Cloud, so it's a good excuse to signup and run your own server. And no, I don't work for Google!

This deployment uses an image built by @dids, which is hosted on Docker Hub: https://hub.docker.com/r/didstopia/rust-server/

This deployment method can be used to start a small server to play with friends or practice building things. In a few days, I'll update the scripts to include a way to save the content you've created, in-game, with others who can then run their own servers and load your content in to explore it for themselves.

For now, start by navigating to Google Cloud and signup for an account. You'll need to enter some credit card details to get this going, but Google is giving you $300 in credits for the next year. Should be enough to make this FREE if you don't run the server all the time and have people connecting to it!

If you ever need to navigate back to Google Cloud, you'll use the following URL:

https://console.cloud.google.com/apis/dashboard?

Once you have finished signing up, you'll need to go and enable Google Container Engine APIs for your account.

Watch the video for more information on setting up your account. The basics below start once you get into the console.

Once you are connected to the Google console do the following to start the server (don't copy and paste the dollar signs):

$ git clone https://gist.github.com/424102dfd6f348f3b8d64b33c52e17ba.git rust-server
$ cd rust-server
$ ./create-cluster.sh
$ # wait a few minutes
$ ./start-server.sh
$ # wait about 10 minutes, then run this to get the IP:
$ kubectrl get services
NAME            CLUSTER-IP    EXTERNAL-IP      PORT(S)           AGE
kubernetes      10.3.240.1    <none>           443/TCP           2h
rust-frontend   10.3.252.69   104.198.23.205   28015:32632/UDP   2h

Use the EXTERNAL-IP of the frontend to build a string to connect to the server in the Rust client. Use F1 to bring up the console in Rust and type:

client.connect 104.198.23.205:28015

Obviously, this is the IP address of my server in this example. Use your own in your own example!

To completely wipe the server from Google, including shutting down the container cluster controllers, the container running the game server AND deleting your server data, do the following:

$ ./wipe-server.sh

To shut the server down, but keep the data intact and the cluster controllers running, do the following:

$ ./stop-server.sh

That's about it. Stay tuned for sharing of worlds.

gcloud config set compute/zone us-west1-b
gcloud container clusters create rust-cluster
gcloud compute disks create --size 200GB rust-server-disk
gcloud config list
apiVersion: v1
kind: Pod
metadata:
name: rust-server
labels:
name: rust-server
spec:
containers:
- resources:
limits:
cpu: 0.5
image: gcr.io/rusty-162617/rust-server
name: rust-server
env:
- name: PASSWORD
value: yourpassword
ports:
- containerPort: 28015
hostPort: 28015
protocol: UDP
volumeMounts:
- name: rust-server-storage
mountPath: /steamcmd/rust
volumes:
- name: rust-server-storage
gcePersistentDisk:
pdName: rust-server-disk
fsType: ext4
apiVersion: v1
kind: Service
metadata:
labels:
name: rust-frontend
name: rust-frontend
spec:
type: LoadBalancer
ports:
- port: 28015
targetPort: 28015
protocol: UDP
selector:
name: rust-server
kubectl exec -it rust-server -- /bin/bash
kubectl create -f rust-server.yaml
kubectl create -f rust-service.yaml
kubectl delete -f rust-server.yaml
kubectl delete -f rust-service.yaml
kubectl delete -f rust-server.yaml
kubectl delete -f rust-service.yaml
gcloud config set compute/zone us-west1-b
gcloud container clusters delete rust-cluster
gcloud compute disks delete rust-server-disk
@dvgui
Copy link

dvgui commented Dec 28, 2020

hi, I tried running it but seems like the image is down. I tried replacing it with the one from didstopia but no luck.. in case you have any ideas here is my yaml

apiVersion: v1
kind: Pod
metadata:
  name: rust-server
  labels:
    name: rust-server
spec:
  containers:
    - resources:
        limits:
          cpu: 0.5
      image: didstopia/rust-server
      name: rust-server
      env:
        - name: PASSWORD
          value: "MYPASS"
        - name: RUST_SERVER_NAME
          value: "Downies CachuServer"
        - name: RUST_SERVER_MAXPLAYERS
          value: "100"
        - name: RUST_SERVER_DESCRIPTION
          value: "Recien Wipeado MAX4P Vanilla"
        - name: RUST_RCON_PASSWORD
          value: "MYPASS"
      ports:
        - containerPort: 28015
          hostPort: 28015
          protocol: UDP
      volumeMounts:
        - name: rust-server-storage
          mountPath: /steamcmd/rust
  volumes:
    - name: rust-server-storage
      gcePersistentDisk:
        pdName: rust-server-disk
        fsType: ext4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment