簡體   English   中英

如何將文件上傳到kubernetes集群以供我的Apps訪問?

[英]How to upload a file to kubernetes cluster for my Apps to access it?

可以說我們有一個訪問文件的應用程序。 該應用程序是一個jar,打包成一個映像,並推送到Registry以便Kubernetes運行它。 但是,當我們創建Pod時,我們還需要在其中配置一個卷。 當我們指定一個卷時,我們給出一個路徑,我們如何將文件放置在該卷中,比如說我們的虛擬機?

請幫我解釋一下。 我們還應該創建一個存儲,以便從kubernetes集群訪問它嗎? 請同時解釋相關主題。

注意:我們使用的是Azure CLI

我認為最好的方法是使用要從應用程序中使用的數據創建ConfigMap 然后,您只需要將ConfigMap掛載為需要數據的Pod( 在此處進行說明 )中的一個卷即可。

您可以輕松地從文件創建ConfigMap ,例如

kubectl create configmap your-configmap-name --from-file=/some/path/to/file

然后將其安裝在您的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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM