1. 程式人生 > >kubernetes實戰(十四):k8s持久化部署gitlab集成openLDAP登錄

kubernetes實戰(十四):k8s持久化部署gitlab集成openLDAP登錄

don vol stat storage per 實現 dep 拉取 chang

1、基本概念

  使用k8s安裝gitlab-ce,采用GlusterFS實現持久化,並集成了openLDAP。

  註意:我公司使用的gitlab是獨立於k8s集群之外的。

2、安裝部署

  最一開始使用的是helm安裝gitlab,網上的文檔應該全部都是使用的這個chart:https://github.com/helm/charts/tree/master/stable/gitlab-ce

  但是這個chart已經被棄用,並推薦我們使用官方的chart

技術分享圖片

  官方chart:https://docs.gitlab.com/ee/install/kubernetes/gitlab_chart.html

  我在使用官方chart部署完成以後,發現啟動的容器太多,就放棄了這個方式,使用yaml文件部署。

  下載yaml文件:

git clone https://github.com/dotbalo/k8s.git
[root@k8s-master01 gitlab]# pwd
/root/k8s/gitlab
[root@k8s-master01 gitlab]# ls
gitlab-rc.yml  gitlab-svc.yml  postgresql-rc.yml  postgresql-svc.yml  redis-rc.yml  redis-svc.yml
...

  修改對應的配置:

  主要修改每個rc的namespace,使用的持久化存儲方式(當前yaml使用的GFS動態存儲)

  修改gitlab-rc.yml裏面的env,對應的LDAP信息和SMTP信息等

  修改traefik的域名

  創建gitlab

[root@k8s-master01 gitlab]# kubectl apply -f .
[root@k8s-master01 gitlab]# kubectl get po,svc,pvc -n public-service
NAME                   READY     STATUS    RESTARTS   AGE
pod/gitlab-cctr6       1/1       Running   2          37m
pod/postgresql-c6trh   1/1       Running   1
37m pod/redis-b6vfk 1/1 Running 0 3h NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/gitlab ClusterIP 10.109.163.143 <none> 80/TCP,22/TCP 24m service/gitlab-balancer NodePort 10.108.77.162 <none> 80:30049/TCP,22:30347/TCP 14m service/glusterfs-dynamic-gitlab-gitlab ClusterIP 10.102.192.68 <none> 1/TCP 59m service/glusterfs-dynamic-gitlab-pg ClusterIP 10.96.14.147 <none> 1/TCP 37m service/glusterfs-dynamic-gitlab-redis ClusterIP 10.106.253.41 <none> 1/TCP 1h service/postgresql ClusterIP 10.104.102.20 <none> 5432/TCP 3h service/redis ClusterIP 10.97.174.50 <none> 6379/TCP 3h NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE persistentvolumeclaim/gitlab-gitlab Bound pvc-b8249829-f6bf-11e8-9640-000c298bf023 5Gi RWX gluster-heketi 59m persistentvolumeclaim/gitlab-pg Bound pvc-b40b6227-f6c2-11e8-9640-000c298bf023 5Gi RWX gluster-heketi 37m persistentvolumeclaim/gitlab-redis Bound pvc-28d0276d-f6af-11e8-8d2c-000c293bfe27 3Gi RWX gluster-heketi 2h

  等待全部pods啟動成功後,訪問gitlab,報錯解決

3、訪問

  默認賬號密碼:root/gitlab

技術分享圖片

  語言更改,註意:此時翻譯是實驗性的,更改後需要重新登錄

技術分享圖片

技術分享圖片

  使用LDAP登錄,均使用郵箱登錄

技術分享圖片

技術分享圖片

  參考文檔:https://github.com/sameersbn/docker-gitlab

4、創建項目

  我公司一個項目下有很多子項目,所以首先創建一個群組:

技術分享圖片

技術分享圖片

  創建項目

技術分享圖片

技術分享圖片

  添加README

技術分享圖片

  添加用戶權限

技術分享圖片

技術分享圖片

  登錄至該用戶可查看到此項目

技術分享圖片

  添加SSH Key

技術分享圖片

技術分享圖片

技術分享圖片

  如果沒有Key需要使用ssh-keygen -t rsa -C "[email protected]"生成對應的Key。

5、拉取項目

技術分享圖片

  創建分支

技術分享圖片

技術分享圖片

  克隆代碼,註意此時需要更改git的地址,因為ssh端口並非22,可以通過service查看nodeport的端口

λ git clone ssh://[email protected]:32455/platform/app1.git
Cloning into app1...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.
Checking connectivity... done.

D:\code
λ cd app1
D:\code\app1 (master)
λ git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/app1-develop
  remotes/origin/master

D:\code\app1 (master)
λ git checkout app1-develop
Branch app1-develop set up to track remote branch app1-develop from origin.
Switched to a new branch app1-develop

D:\code\app1 (app1-develop)
λ touch.exe testfile

D:\code\app1 (app1-develop)
λ git add .

D:\code\app1 (app1-develop)
λ git commit -am "create a test file"
[app1-develop 9050e35] create a test file
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 testfile

D:\code\app1 (app1-develop)
λ git push origin app1-develop
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 278 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote:
remote: To create a merge request for app1-develop, visit:
remote:   http://gitlab.xxx.net/platform/app1/merge_requests/new?merge_request%5Bsource_branch%5D=app1-develop remote:
To ssh://[email protected]:32455/platform/app1.git
   0a63d86..9050e35  app1-develop -> app1-develop

  查看文件

技術分享圖片

  協同開發,同樣方式將其他用戶加入此項目

  克隆代碼,並修改文件

[root@k8s-node02 ~]# git clone ssh://[email protected]:32455/platform/app1.git
Cloning into app1...
The authenticity of host [gitlab.xxx.net]:32455 ([192.168.20.10]:32455) cant be established.
ECDSA key fingerprint is SHA256:l6BYlMWpAWyXx/f5oTG8lK4JQvG9C2ZZ9opqdQZfIuc.
ECDSA key fingerprint is MD5:5b:b4:04:68:26:53:2e:ba:fe:f8:99:6c:8f:d3:fa:51.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added [gitlab.xxx.net]:32455,[192.168.20.10]:32455 (ECDSA) to the list of known hosts.
remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 6 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (6/6), done.
[root@k8s-node02 ~]# cd app1/
[root@k8s-node02 app1]# ls
README.md
[root@k8s-node02 app1]# git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/app1-develop
  remotes/origin/master
[root@k8s-node02 app1]# git checkout app1-develop
Branch app1-develop set up to track remote branch app1-develop from origin.
Switched to a new branch app1-develop
[root@k8s-node02 app1]# ls
README.md  testfile
[root@k8s-node02 app1]# echo "add something" >> testfile 
[root@k8s-node02 app1]# git add .
[root@k8s-node02 app1]# git commit -am "add someting to testfile"
[app1-develop 69d693c] add someting to testfile
 1 file changed, 1 insertion(+)
[root@k8s-node02 app1]# git push origin app1-develop
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 305 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: 
remote: To create a merge request for app1-develop, visit:
remote:   http://gitlab.xxx.net/platform/app1/merge_requests/new?merge_request%5Bsource_branch%5D=app1-develop
remote: 
To ssh://[email protected]:32455/platform/app1.git
   9050e35..69d693c  app1-develop -> app1-develop

kubernetes實戰(十四):k8s持久化部署gitlab集成openLDAP登錄