在 Kubernetes 中通过代码创建文件
Create a file throught code in Kubernetes
我需要(或者至少我认为我需要)创建一个文件(可以是一个临时文件,但现在我正在测试它时它不起作用),我可以在其中复制存储在 [=35 中的文件=]云存储。
这个文件是一个 geojson 文件,加载文件后我将使用 geopandas 读取它。
代码将 运行 它在 Google Cloud
中的 Kubernete 中
The code:
def geoalarm(self,input):
from shapely.geometry import Point
import uuid
from google.cloud import storage
import geopandas as gpd
fp = open("XXX.geojson", "w+")
storage_client = storage.Client()
bucket = storage_client.get_bucket('YYY')
blob = bucket.get_blob('ZZZ.geojson')
blob.download_to_file(fp)
fp.seek(0)
PAIS = gpd.read_file(fp.name)
(dictionaryframe,_)=input
try:
place = Point((float(dictionaryframe["lon"])/100000), (float(dictionaryframe["lat"]) / 100000))
<...>
问题是:
如何在 kubernetes 中创建文件?
或者,我如何在 geopandas 中将文件的内容用作字符串(如果我使用 download_as_string)来执行 geopanda.read_file(name)
的等效操作?
Extra
我尝试使用:
PAIS = gpd.read_file("gs://bucket/xxx.geojson")
但是我有以下错误:
DriverError: '/vsigs/bucket/xxx.geojson' does not exist in the file system, and is not recognized as a supported dataset name.
模式的非常概括的概述:
您可以先将代码放在 git 存储库中。在 Kubernetes 上,使用 ubuntu 映像创建一个 deployment/pod 并确保安装 python、python 依赖项并将代码拉入初始化脚本,最后一行调用python 到 运行 您的代码。在你的 pod 模板的 "command" 属性中,你应该使用 /bin/bash 到 运行 你的脚本。假设您拥有正确的凭据,您将能够从 Google 存储中获取文件并进行处理。要进行调试,您可以使用 "kubectl exec" 附加到 运行ning 容器。
希望对您有所帮助!
避免在kubernetes中创建文件的解决方案:
storage_client = storage.Client()
bucket = storage_client.get_bucket('buckte')
blob = bucket.get_blob('file.geojson')
string = blob.download_as_string()
PAIS = gpd.GeoDataFrame.from_features(json.loads(string))
我需要(或者至少我认为我需要)创建一个文件(可以是一个临时文件,但现在我正在测试它时它不起作用),我可以在其中复制存储在 [=35 中的文件=]云存储。
这个文件是一个 geojson 文件,加载文件后我将使用 geopandas 读取它。
代码将 运行 它在 Google Cloud
中的 Kubernete 中The code:
def geoalarm(self,input):
from shapely.geometry import Point
import uuid
from google.cloud import storage
import geopandas as gpd
fp = open("XXX.geojson", "w+")
storage_client = storage.Client()
bucket = storage_client.get_bucket('YYY')
blob = bucket.get_blob('ZZZ.geojson')
blob.download_to_file(fp)
fp.seek(0)
PAIS = gpd.read_file(fp.name)
(dictionaryframe,_)=input
try:
place = Point((float(dictionaryframe["lon"])/100000), (float(dictionaryframe["lat"]) / 100000))
<...>
问题是:
如何在 kubernetes 中创建文件?
或者,我如何在 geopandas 中将文件的内容用作字符串(如果我使用 download_as_string)来执行 geopanda.read_file(name)
的等效操作?
Extra
我尝试使用:
PAIS = gpd.read_file("gs://bucket/xxx.geojson")
但是我有以下错误:
DriverError: '/vsigs/bucket/xxx.geojson' does not exist in the file system, and is not recognized as a supported dataset name.
模式的非常概括的概述:
您可以先将代码放在 git 存储库中。在 Kubernetes 上,使用 ubuntu 映像创建一个 deployment/pod 并确保安装 python、python 依赖项并将代码拉入初始化脚本,最后一行调用python 到 运行 您的代码。在你的 pod 模板的 "command" 属性中,你应该使用 /bin/bash 到 运行 你的脚本。假设您拥有正确的凭据,您将能够从 Google 存储中获取文件并进行处理。要进行调试,您可以使用 "kubectl exec" 附加到 运行ning 容器。
希望对您有所帮助!
避免在kubernetes中创建文件的解决方案:
storage_client = storage.Client()
bucket = storage_client.get_bucket('buckte')
blob = bucket.get_blob('file.geojson')
string = blob.download_as_string()
PAIS = gpd.GeoDataFrame.from_features(json.loads(string))