将文件放在GKE上的Kubernetes持久卷存储中

Noa*_*ert 8 docker google-cloud-platform kubernetes google-kubernetes-engine

我试图在Kubernetes(托管在GKE上)上运行Factorio游戏服务器。

我已经设置了具有永久数量声明的状态集,并将其安装在游戏服务器的保存目录中。

我想从本地计算机上将保存文件上传到此“永久批量声明”,以便可以访问游戏服务器上的保存文件。

将文件上传到此“永久批量声明”的最佳方法是什么?

我已经想到了两种方法,但是我不确定哪种方法最好,或者哪种方法都不错:

  • 将包含我想要的文件的磁盘快照还原到支持此持久卷声明的GCP磁盘
  • 将永久卷声明挂载到FTP容器上,将文件上传FTP,然后将其挂载到游戏容器上

And*_*rey 10

您可以在 GoogleCloud 上创建数据文件夹:

gcloud compute ssh <your cloud> <your zone>
mdkir data
Run Code Online (Sandbox Code Playgroud)

然后创建 PersistentVolume:

kubectl create -f hostpth-pv.yml

kind: PersistentVolume
apiVersion: v1
metadata:
  name: pv-local
  labels:
    type: local
spec:
  storageClassName: local
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/home/<user-name>/data"
Run Code Online (Sandbox Code Playgroud)

创建 PersistentVolumeClaim:

kubectl create -f hostpath-pvc.yml

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: hostpath-pvc
spec:
  storageClassName: local
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 5Gi
  selector:
    matchLabels:
      type: local
Run Code Online (Sandbox Code Playgroud)

然后将文件复制到 GCloud:

gcloud compute scp <your file> <your cloud> <your zone> 
Run Code Online (Sandbox Code Playgroud)

最后将这个 PersistentVolumeClaim 挂载到你的 pod:

...
      volumeMounts:
       - name: hostpath-pvc
         mountPath: <your-path>
         subPath: hostpath-pvc  
  volumes:
    - name: hostpath-pvc
      persistentVolumeClaim:
        claimName: hostpath-pvc
Run Code Online (Sandbox Code Playgroud)

并将文件复制到 GGloud 中的数据文件夹:

  gcloud compute scp <your file> <your cloud>:/home/<user-name>/data/hostpath-pvc <your zone>
Run Code Online (Sandbox Code Playgroud)


Noa*_*ert 9

事实证明,有一种简单得多的方法: kubectl cp命令。

此命令使您可以将数据从计算机复制到群集上运行的容器。

就我而言,我跑了:

kubectl cp ~/.factorio/saves/k8s-test.zip factorio/factorio-0:/factorio/saves/
Run Code Online (Sandbox Code Playgroud)

这会将k8s-test.zip我计算机上的文件复制到/factorio/saves/k8s-test.zip群集上运行的容器中。

有关kubectl cp -h更多详细信息,请参阅用法信息和示例。

  • 我一直在寻找这样的东西!为什么这没有列在备忘单上?https://kubernetes.io/docs/reference/kubectl/cheatsheet/ (3认同)