K8S 之 使用GIT仓库作为存储卷

一、gitRepo卷的作用

gitRepo卷基本上也是一个emptyDir卷,它通过克隆Git仓库关在pod启 动时检出特定版本来填充数据。

备注:在创建gitRepo卷后,它并不能和对应repo保持同步,当向Git仓库推送新增的提交时,卷中的文件将不会被更新。然而,如果所有的pod是由ReplicationController管理的,删除这个pod将触发新建一个新的pod,而这个新pod的卷中将含新的提交。

二、在gitlab上创建一个gitRepo项目

K8S 之 使用GIT仓库作为存储卷

K8S 之 使用GIT仓库作为存储卷

三、创建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/

四、查看结果

[root@test-nodes1 k8s-yaml-file]# kubectl create -f gitrepo.yaml 
pod/gitrepo-volume-pod created
[root@test-nodes1 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>
[root@test-nodes1 k8s-yaml-file]# curl 172.7.21.6
<html>
<body>
Hello MingKang.Zhou!!!!!
</body>
</html>

猜你喜欢

转载自blog.51cto.com/12965094/2488995