Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Placing Files In A Kubernetes Persistent Volume Store On GKE

Tags:

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
like image 462
Noah Huppert Avatar asked Jun 05 '18 15:06

Noah Huppert


People also ask

How do you add a persistent disk to Gke?

Now we have a disk available to be used as PV in GKE. Next step is to, Create a Persistent volume named app-storage from the gke-pv disk. To use the persistent volume with the pod, we will create a persistent volume claim with the same name we use in the PV claimRef , ie app-storage-claim.

How do I view files in persistent volume?

First, find out your pvc's mountPath. Your data sits there. Second, you can access it from the pod that uses the PersistentVolumeClaim. Fire up a terminal on the pod and use your favourite tools like ls and df to list files or see stats of the volume usage.

What is the difference between persistent volume and persistent volume claim in Kubernetes?

PVCs are requests for those resources and also act as claim checks to the resource. So a persistent volume (PV) is the "physical" volume on the host machine that stores your persistent data. A persistent volume claim (PVC) is a request for the platform to create a PV for you, and you attach PVs to your pods via a PVC.


1 Answers

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.

like image 88
Noah Huppert Avatar answered Oct 01 '22 09:10

Noah Huppert