gpt4 book ai didi

kubernetes - 在部署期间将文件保存到 Kubernetes pod

转载 作者:行者123 更新时间:2023-12-02 00:58:34 24 4
gpt4 key购买 nike

我试图在 pod 初始化期间将文件添加到 pod 的磁盘,但没有成功。下面是我用来部署 pod 的部署文件。该文件被下载到持久卷,但 pod 没有进入就绪状态。几秒钟后,Pod 失败并重建。这又开始了整个过程。

如有任何帮助,我们将不胜感激。

apiVersion: apps/v1beta2
kind: Deployment
metadata:
name: mapserver
spec:
selector:
matchLabels:
app: mapserver
template:
metadata:
labels:
app: mapserver
spec:
volumes:
- name: storage
persistentVolumeClaim:
claimName: mapserver-pv-claim
containers:
- name: maptiles
image: klokantech/tileserver-gl
command: ["/bin/sh"]
args:
- -c
- |
echo "[INFO] Startingcontainer"; if [ $(DOWNLOAD_MBTILES) = "true" ]; then
echo "[INFO] Download MBTILES_PLANET_URL";
rm /data/*
cd /data/
curl -k -sSL -X GET -u user:ww $(MBTILES_PLANET_URL) -O
echo "[INFO] Download finished";
fi;
env:
- name: MBTILES_PLANET_URL
value: 'https://abc-dev/nexus/repository/xyz-raw/2017-07-03_europe_netherlands.mbtiles'
- name: DOWNLOAD_MBTILES
value: 'true'
livenessProbe:
failureThreshold: 120
httpGet:
path: /health
port: 80
scheme: HTTP
initialDelaySeconds: 10
periodSeconds: 30
successThreshold: 1
timeoutSeconds: 5
ports:
- containerPort: 80
name: http
protocol: TCP
readinessProbe:
failureThreshold: 120
httpGet:
path: /health
port: 80
scheme: HTTP
initialDelaySeconds: 10
periodSeconds: 30
successThreshold: 1
timeoutSeconds: 5
resources:
limits:
cpu: 300m
memory: 3Gi
requests:
cpu: 100m
memory: 1Gi
volumeMounts:
- mountPath: "/data"
name: storage

最佳答案

am trying to add a file to a pod's disk during initialization of the pod but without luck.

在这种情况下,您可能需要使用 InitContainers相反。

从你的 list 来看,你的主要命令被执行(复制文件然后退出)终止进程中的容器(和伴随的 pod)。部署然后重新启动退出的 pod 并重复循环。如果您改用 InitContainers(具有与您现在对主容器相同的定义和相同的 PV),您应该使用运行到完成的 InitContaienrs 预填充数据,然后继续在你的普通容器中使用它(应该有非退出的主进程作为它的命令/入口点)。

注意:如果您不想使用 InitContainers 或只是作为快速测试,您可以在复制语句后附加一个常规的非退出命令,同时检查是否需要使用 tty 启动容器,具体取决于您的用例以及保持容器正常运行的方法。

关于kubernetes - 在部署期间将文件保存到 Kubernetes pod,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52373688/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com