我正在尝试在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
我正在尝试在pod初始化期间将文件添加到pod的磁盘但没有运气。
在这种情况下,您可能希望使用InitContainers
。
从您的清单判断,您的主命令被执行(复制文件然后退出)终止容器(和随附的pod)。然后部署重新启动已退出的窗格并循环重复。如果您使用InitContainers
(使用与您现在为主容器相同的定义和PV),则应使用运行完成的InitContaienrs
预填充数据,然后继续在正常容器中使用它(应该不会退出主进程作为其命令/入口点)。
注意:如果您不想使用InitContainers
或仅作为快速测试,您可以在复制语句后附加常规的非退出命令,并检查是否需要使用tty启动容器,具体取决于您的用例以及保持容器正常运行的方法。