我已经仔细阅读过Kubernetes文档,但是仍然无法通过在K8作业启动的pod中运行的应用程序与主机文件系统上的文件进行交互。即使使用最简单的实用程序也会发生这种情况,因此我提供了一个简化的yaml配置示例。此处引用的本地文件'hello.txt'确实存在于主机上的/ tmp中(即,在Kubernetes环境之外),我什至chmod 777也已将其保存。我还在主机文件系统中尝试过/ tmp以外的其他位置。
Kubernetes作业启动的Pod以Status = Error终止并生成日志 ls: /testing/hello.txt: No such file or directory
因为我最终希望以编程方式将其用作更复杂的工作流程的一部分,所以实际上确实需要将其作为工作而不是部署。我希望那是可能的。我正在使用kubectl启动的仅用于测试的当前配置文件是:
apiVersion: batch/v1
kind: Job
metadata:
name: kio
namespace: kmlflow
spec:
# ttlSecondsAfterFinished: 5
template:
spec:
containers:
- name: kio-ingester
image: busybox
volumeMounts:
- name: test-volume
mountPath: /testing
imagePullPolicy: IfNotPresent
command: ["ls"]
args: ["-l", "/testing/hello.txt"]
volumes:
- name: test-volume
hostPath:
# directory location on host
path: /tmp
# this field is optional
# type: Directory
restartPolicy: Never
backoffLimit: 4
Run Code Online (Sandbox Code Playgroud)
在此先感谢您的协助。
看起来当卷被安装时,现有数据无法访问。
您将需要使用 init 容器来预先填充卷中的数据。
apiVersion: v1
kind: Pod
metadata:
name: my-app
spec:
containers:
- name: my-app
image: my-app:latest
volumeMounts:
- name: config-data
mountPath: /data
initContainers:
- name: config-data
image: busybox
command: ["echo","-n","{'address':'10.0.1.192:2379/db'}", ">","/data/config"]
volumeMounts:
- name: config-data
mountPath: /data
volumes:
- name: config-data
hostPath: {}
Run Code Online (Sandbox Code Playgroud)
参考:
归档时间: |
|
查看次数: |
578 次 |
最近记录: |