以下片段来自 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"
Run Code Online (Sandbox Code Playgroud)
上面的代码将在 /mypath 的容器内安装完整的 git 存储库。有没有办法只将 git repo 内的特定子目录挂载在 /mypath 容器内?
是的,有一种方法可以做到。请参阅以下示例。我有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"
Run Code Online (Sandbox Code Playgroud)
请注意中subPath的字段。您可以在此处指定要在容器内安装的卷的哪个子目录。containersvolumeMounts/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).
Run Code Online (Sandbox Code Playgroud)
或者
像这样创建 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: "."
Run Code Online (Sandbox Code Playgroud)
这里的区别是我已经指定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.
Run Code Online (Sandbox Code Playgroud)
华泰
| 归档时间: |
|
| 查看次数: |
4790 次 |
| 最近记录: |