K8S 之 使用GIT仓库作为存储卷
一、gitRepo卷的作用
gitRepo卷基本上也是一个emptyDir卷,它通过克隆Git仓库关在pod启 动时检出特定版本来填充数据。
备注:在创建gitRepo卷后,它并不能和对应repo保持同步,当向Git仓库推送新增的提交时,卷中的文件将不会被更新。然而,如果所有的pod是由ReplicationController管理的,删除这个pod将触发新建一个新的pod,而这个新pod的卷中将含新的提交。
二、在gitlab上创建一个gitRepo项目


三、创建pod连接gitlab项目
apiVersion: v1
kind: Pod
metadata:
name: gitrepo-volume-pod
namespace: test
spec:
containers:
- image: nginx:alpine
name: web-server
volumeMounts:
- mountPath: /usr/share/nginx/html
name: html
readOnly: true
ports:
- containerPort: 80
protocol: TCP
volumes:
- name: html
gitRepo: #你正在创建一个gitRepo卷
repository: https://github.com/luksa/kubia-website-example.git #这个卷克隆至一个Git仓库
revision: master #使用那个主分支
directory: . #将repo克隆到卷的根目录,即/usr/share/nginx/html/四、查看结果
[ k8s-yaml-file]# kubectl create -f gitrepo.yaml pod/gitrepo-volume-pod created [ k8s-yaml-file]# kubectl get pod -o wide -n test NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES gitrepo-volume-pod 1/1 Running 0 74s 172.7.21.6 test-nodes1.cedarhd.com <none> <none> [ k8s-yaml-file]# curl 172.7.21.6 <html> <body> Hello MingKang.Zhou!!!!! </body> </html>
相关推荐
XiaoMuFireAnt 2020-09-02
akcsdno 2020-07-21
xiunai 2020-06-28
薛正华 2020-06-21
JustHaveTry 2020-06-21
xingyuzhe 2020-06-10
hyxinyu 2020-06-10
xingyuzhe 2020-06-09
wishli 2020-06-08
JayFighting 2020-06-08
guan000 2020-06-05
wishli 2020-06-03
liaochaowu 2020-06-06
88427810 2020-11-02
hubanbei00的家园 2020-10-25
shurenyun 2020-08-19