Placing Files In A Kubernetes Persistent Volume Store On GKE

Noah Huppert picture Noah Huppert · Jun 5, 2018 · Viewed 16.4k times · Source

I am trying to run a Factorio game server on Kubernetes (hosted on GKE).

I have setup a Stateful Set with a Persistent Volume Claim and mounted it in the game server's save directory.

I would like to upload a save file from my local computer to this Persistent Volume Claim so I can access the save on the game server.

What would be the best way to upload a file to this Persistent Volume Claim?

I have thought of 2 ways but I'm not sure which is best or if either are a good idea:

  • Restore a disk snapshot with the files I want to the GCP disk which backs this Persistent Volume Claim
  • Mount the Persistent Volume Claim on an FTP container, FTP the files up, and then mount it on the game container

Answer

Noah Huppert picture Noah Huppert · Jun 7, 2018

It turns out there is a much simpler way: The kubectl cp command.

This command lets you copy data from your computer to a container running on your cluster.

In my case I ran:

kubectl cp ~/.factorio/saves/k8s-test.zip factorio/factorio-0:/factorio/saves/

This copied the k8s-test.zip file on my computer to /factorio/saves/k8s-test.zip in a container running on my cluster.

See kubectl cp -h for more more detail usage information and examples.