gpt4 book ai didi

kubernetes - 将子目录与 kubernetes gitRepo 卷挂载一起使用

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

以下片段来自 kubernetes 官方文档 (http://kubernetes.io/docs/user-guide/volumes/#gitrepo):

apiVersion: v1
kind: Pod
metadata:
name: server
spec:
containers:
- image: nginx
name: nginx
volumeMounts:
- mountPath: /mypath
name: git-volume
volumes:
- name: git-volume
gitRepo:
repository: "git@somewhere:me/my-git-repository.git"
revision: "22f1d8406d464b0c0874075539c1f2e96c253775"

以上将在/mypath 的容器内挂载完整的 git 仓库。有没有办法在/mypath 的容器内的 git repo 中只挂载特定的子目录?

最佳答案

是的,有一种方法可以做到。请参见以下示例。我有 git repo其中有子目录 configs .

这是我正在使用的 pod 文件:

apiVersion: v1
kind: Pod
metadata:
name: server
spec:
containers:
- image: nginx
name: nginx
volumeMounts:
- mountPath: /mypath/
name: git-volume
subPath: "hitcounter/configs"
volumes:
- name: git-volume
gitRepo:
repository: "https://github.com/surajssd/hitcounter"
revision: "9fd11822b822c94853b1c74ceb53adb8e1d2cfc8"

请注意 volumeMountscontainers 中的字段 subPath。您可以在容器内的 /mypath 中指定要挂载的卷中的哪个子目录。

文档说:

$ kubectl explain pod.spec.containers.volumeMounts.subPath
FIELD: subPath <string>

DESCRIPTION:
Path within the volume from which the container's volume should be mounted.
Defaults to "" (volume's root).

像这样创建pod配置文件

apiVersion: v1
kind: Pod
metadata:
name: server
spec:
containers:
- image: nginx
name: nginx
volumeMounts:
- mountPath: /mypath/
name: git-volume
subPath: "configs"
volumes:
- name: git-volume
gitRepo:
repository: "https://github.com/surajssd/hitcounter"
revision: "9fd11822b822c94853b1c74ceb53adb8e1d2cfc8"
directory: "."

这里的区别是我指定了 directory: "." 这确保挂载点 /mypath 将成为 git repo 以及 subPath: "configs " 已更改,因为没有额外的目录 hitcounter

$ kubectl explain pod.spec.volumes.gitRepo.directory
FIELD: directory <string>

DESCRIPTION:
Target directory name. Must not contain or start with '..'. If '.' is
supplied, the volume directory will be the git repository. Otherwise, if
specified, the volume will contain the git repository in the subdirectory
with the given name.

HTH

关于kubernetes - 将子目录与 kubernetes gitRepo 卷挂载一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37476967/

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