gitRepo
gitRepo卷的生命周期与Pod的生命周期一致。
gitRepo卷通过克隆Git仓库中的内容至卷中,再将卷挂载至容器中。
缺点:当仓库中有更新时,gitRepo卷中的内容并不会被自动同步,需要手动同步。
gitRepo卷在使用时的情况如下:

创建gitRepo卷
gitRepo卷的定义和挂载分为下面两步:
定义卷:在Pod的
spec.volumes
中定义卷,并且在spec.volumes.gitRepo
中定义该卷相关的配置;挂载卷:在Pod的
spec.containers.volumeMounts
中指定挂载点和挂载的卷名;
下面举一个例子,创建一个名为gitrepo-volume-pod
的Pod,其在内部的名为web-server
的容器在/usr/share/nginx/html
下挂载一个名为html
的gitRepo卷,该卷中的内容是从https://github.com/yangsijie666/kubia-website-example.git
仓库中克隆下来,分支为master
,并且克隆到该卷的根目录:
apiVersion: v1
kind: Pod
metadata:
name: gitrepo-volume-pod
spec:
containers:
- image: nginx:alpine
name: web-server
volumeMounts: # 定义挂载点
- name: html # (必须) 挂载的卷名
mountPath: /usr/share/nginx/html # (必须)容器中的挂载点
readOnly: true # 对该卷只允许读
ports:
- containerPort: 80
protocol: TCP
volumes: # 定义卷
- name: html # (必须)卷名
gitRepo: # 创建的是gitRepo卷
repository: https://github.com/yangsijie666/kubia-website-example.git # (必须)仓库地址
revision: master # 分支名
directory: . # 克隆到卷的根目录
Last updated
Was this helpful?