[英]How to upload a file to kubernetes cluster for my Apps to access it?
Lets say we have an application which accesses a file. 可以说我们有一个访问文件的应用程序。 This App is a jar which is packaged into an image and pushed to Registry for the Kubernetes to run it.
该应用程序是一个jar,打包成一个映像,并推送到Registry以便Kubernetes运行它。 But when we create the Pod, we need to configure a volume also in it.
但是,当我们创建Pod时,我们还需要在其中配置一个卷。 When we specify a volume we give a path, how do we place the file in that volume from lets say our virtual machine?
当我们指定一个卷时,我们给出一个路径,我们如何将文件放置在该卷中,比如说我们的虚拟机?
Please help me in understanding this with an explanation. 请帮我解释一下。 Also should we create a storage so that its accessible from kubernetes cluster?
我们还应该创建一个存储,以便从kubernetes集群访问它吗? please explain relevent topic as well to understand this.
请同时解释相关主题。
Note: we are using azure cli 注意:我们使用的是Azure CLI
I think the best approach would be to create a ConfigMap
with the data you want to use from your application. 我认为最好的方法是使用要从应用程序中使用的数据创建
ConfigMap
。 Then you just need to mount the ConfigMap
as a volume in the Pod's ( explained here ) that need the data. 然后,您只需要将
ConfigMap
挂载为需要数据的Pod( 在此处进行说明 )中的一个卷即可。
You can easily create a ConfigMap
from a file like 您可以轻松地从文件创建
ConfigMap
,例如
kubectl create configmap your-configmap-name --from-file=/some/path/to/file
And then mount it in your Pod 然后将其安装在您的Pod中
apiVersion: v1
kind: Pod
metadata:
name: dapi-test-pod
spec:
containers:
- name: test-container
image: k8s.gcr.io/busybox
command: [ "/bin/sh", "-c", "ls /etc/config/" ]
volumeMounts:
- name: config-volume
mountPath: /etc/config
volumes:
- name: config-volume
configMap:
# Provide the name of the ConfigMap containing the files you want
# to add to the container
name: special-config
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.