首页 > 解决方案 > gcsfuse 在 GKE 和/或 python3 boto 中安装存储桶以进行流式写入?

问题描述

我正在寻找一种将一些 .mp4 视频文件(因为它们是由某些 python 应用程序生成的)“写入流”到谷歌云存储桶的方法。python 应用程序已容器化并部署在 GKE 中,目前可以作为 Web 服务正常执行。但问题是所有视频文件都是在本地生成并存储在tmp/processedpod 内的路径 ( ) 中。

但是,我希望将视频文件写入谷歌存储桶中名为my_bucket.

我已阅读gcsfuse指南 ( https://github.com/maciekrb/gcs-fuse-sample ) 关于如何在 Kubernetes pod 中安装存储桶并阅读有关boto ( https://cloud.google.com/storage/docs /boto-plugin#streaming-transfers)用于将流传输到存储桶。

为了挂载my_buckettmp/processed我在我的应用程序的部署文件 (YAML) 中添加了以下几行:

        lifecycle:
          postStart:
            exec:
              command:
              - gcsfuse
              - -o
              - nonempty
              - my_bucket
              - tmp/processed
          preStop:
            exec:
              command:
              - fusermount
              - -u
              - tmp/processed/
        securityContext:
          capabilities:
            add:
            - SYS_ADMIN

我还没用过boto,我想也许只是安装就足够了!但是,我的应用程序在尝试生成视频文件时给了我输入/输出错误。

现在我的问题是我是否需要同时使用gcsfuseboto,或者只需将存储桶安装在我的 GKE pod 中就足够了?我安装对了吗?


更新:我验证我使用以下命令正确安装:

kubectl exec -it [POD_NAME] bash

标签: kubernetesbotobucketgoogle-kubernetes-enginegcsfuse

解决方案


问题解决了!我只需要将我的桶安装在吊舱内,就是这样。安装脚本(如上面我的问题中所写)已正确完成。但是,导致的问题input/output error是由于我的 GKE 集群没有足够的权限。基本上,集群没有读取/写入存储的权限,并且项目需要其他一些权限。因此,我使用以下命令创建了一个新集群:

gcloud container clusters create [MY_CLUSTER_NAME] \
  --scopes=https://www.googleapis.com/auth/userinfo.email,cloud-platform,https://www.googleapis.com/auth/devstorage.read_write,storage-rw,trace,https://www.googleapis.com/auth/trace.append,https://www.googleapis.com/auth/servicecontrol,compute-rw,https://www.googleapis.com/auth/compute,https://www.googleapis.com/auth/service.management.readonly,https://www.googleapis.com/auth/taskqueue \
  --num-nodes 4 --zone "us-central1-c"

为了能够读取/写入存储桶,集群必须具有https://www.googleapis.com/auth/devstorage.read_write权限。

此外,无需使用boto并通过gcsfuse 挂载就足以让我能够将流视频文件写入my_bucket.


推荐阅读