gpt4 book ai didi

node.js - 如何将具有数据(我需要此数据)的Pod容器路径安装到kubernetes中的本地主机路径

转载 作者:行者123 更新时间:2023-12-02 12:01:16 25 4
gpt4 key购买 nike

我有一个pod(kind:job),它在“/ usr / src / app”下有一些代码构建文件,这些文件在本地k8s主机中需要。

但是,当我尝试按照以下yamls进行操作时,无法在已挂载的主机路径中看到任何数据,该数据实际上位于pod容器(“/ usr / src / app”)中。我认为安装正在覆盖/隐藏该数据。请帮助我进入本地k8s主机。

我的文件是:-

apiVersion: batch/v1
kind: Job
metadata:
name: wf
spec:
template:
spec:
containers:
- name: wf
image: 12345678.dkr.ecr.ap-south-1.amazonaws.com/eks:ws
volumeMounts:
- name: wf-persistent-storage
mountPath: /usr/src/app # my data is in (/usr/src/app)
volumes:
- name: wf-persistent-storage
# pointer to the configuration of HOW we want the mount to be implemented
persistentVolumeClaim:
claimName: wf-test-pvc
restartPolicy: Never
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: wf-test-pvc
spec:
storageClassName: mylocalstorage
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: local
spec:
storageClassName: mylocalstorage
capacity:
storage: 2Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/root/mnt/"
type: DirectoryOrCreate

最佳答案

不要挂载/ usr / src / app。因为它将被PVC的内容覆盖。在您的情况下,pvc最初为空,因此将删除所有文件。

尝试以下代码,将/ tmp安装在pvc上,并使用命令将文件复制到pvc。

apiVersion: batch/v1
kind: Job
metadata:
name: wf
spec:
template:
spec:
containers:
- name: wf
image: 12345678.dkr.ecr.ap-south-1.amazonaws.com/eks:ws
command:
- bash
- -c
- cp -R /usr/src/app/* /tmp/
volumeMounts:
- name: wf-persistent-storage
mountPath: /opt # my data is in (/usr/src/app)
volumes:
- name: wf-persistent-storage
# pointer to the configuration of HOW we want the mount to be implemented
persistentVolumeClaim:
claimName: wf-test-pvc
restartPolicy: Never

关于node.js - 如何将具有数据(我需要此数据)的Pod容器路径安装到kubernetes中的本地主机路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61650930/

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