Openshift GitLab安裝及使用Nodeport支持ssh訪問

openshift-gitlab

部署Gitlab

  1. 創(chuàng)建gitlab項目
oc new-project gitlab
  1. 創(chuàng)建cicd serviceaccount
$ oc create serviceaccount cicd -n gitlab
  1. 導入Gitlab模板
wget https://gitee.com/xhua/OpenshiftOneClick/raw/3.11/openshift-templates/gitlab-template.yaml
oc create -f openshift-template.json -n openshift
  1. 創(chuàng)建持久化存儲(如果沒有pv的情況下)
$ cat gitlab-pv.yaml
apiVersion: v1
items:
- apiVersion: v1
  kind: PersistentVolume
  metadata:
    creationTimestamp: null
    name: gitlabdata-volume
  spec:
    accessModes:
    - ReadWriteMany
    capacity:
      storage: 50Gi
    claimRef:
      apiVersion: v1
      kind: PersistentVolumeClaim
      name: gitlab-data
      namespace: gitlab
    nfs:
      path: /mnt/gitlabdata
      server: 192.168.0.13
    persistentVolumeReclaimPolicy: Retain
  status: {}
- apiVersion: v1
  kind: PersistentVolume
  metadata:
    creationTimestamp: null
    name: gitlabpostgresql-volume
  spec:
    accessModes:
    - ReadWriteMany
    capacity:
      storage: 10Gi
    claimRef:
      apiVersion: v1
      kind: PersistentVolumeClaim
      name: gitlab-postgresql
      namespace: gitlab
    nfs:
      path: /mnt/gitlabpostgresql
      server: 192.168.0.13
    persistentVolumeReclaimPolicy: Retain
  status: {}
- apiVersion: v1
  kind: PersistentVolume
  metadata:
    creationTimestamp: null
    name: gitlabredisdata-volume
  spec:
    accessModes:
    - ReadWriteMany
    capacity:
      storage: 50Gi
    claimRef:
      apiVersion: v1
      kind: PersistentVolumeClaim
      name: gitlab-redis-data
      namespace: gitlab
    nfs:
      path: /mnt/gitlabredisdata
      server: 192.168.0.13
    persistentVolumeReclaimPolicy: Retain
  status: {}
- apiVersion: v1
  kind: PersistentVolume
  metadata:
    creationTimestamp: null
    name: gitlabetc-volume
  spec:
    accessModes:
    - ReadWriteMany
    capacity:
      storage: 50Gi
    claimRef:
      apiVersion: v1
      kind: PersistentVolumeClaim
      name: gitlab-etc
      namespace: gitlab
    nfs:
      path: /mnt/gitlabetc
      server: 192.168.0.13
    persistentVolumeReclaimPolicy: Retain
  status: {}
$ oc create gitlab-pv.yaml
  1. 給gitlab 容器使用root用戶的權(quán)限
$  oc adm  policy add-scc-to-user anyuid -z cicd -n gitlab
  1. 在Openshift上創(chuàng)建gitlab應用
部署應用

設(shè)置gitlab安裝配置(自定義)

自定義配置1
自定義配置2
  1. 通過訪問Route訪問gitlab
    在訪問的機器上hosts文件中配置Router Host與Ip的對應
    用戶名(root) 密碼(根據(jù)自定義配置中設(shè)定)
GitLab訪問

使用Nodeport讓gitlab服務支持ssh訪問

  • Openshift上的服務最常使用的是Route來對外提供服務。但是Route只支持Http協(xié)議,而對于Gitlab通過ssh訪問的方式,得通過TCP協(xié)議。所以可以使用NodePort向外提供服務。
  1. 創(chuàng)建NodePort (30022->gitlab 22)
$ cat gitlab-nodeport.yaml
apiVersion: v1
kind: Service
metadata:
  name: gitlab-nodeport
  namespace: gitlab
  labels:
    name: gitlab-nodeport
spec:
  type: NodePort
  ports:
    - port: 22
      nodePort: 30022
      name: ssh
  selector:
    app: gitlab-ce
    deploymentconfig: gitlab-ce
$ oc create -f gitlab-nodeport.yaml
  1. 將本機的公鑰拷貝到gitlab網(wǎng)站的ssh key管理
導入客戶端的公鑰

3.客戶端clone代碼

git clone ssh://git@gitlab.apps.it.example.com:30022/root/test.git
# 或者
git clone ssh://git@192.168.1.x:30022/root/test.git ##192.168.1.x為集群中任意Node的ip

注意:因為Nodeport使用的不是ssh默認的22端口,在clone時必須在前綴使用ssh://,同時在git服務后添加:NodePort端口號

  1. 結(jié)果展示
[root@gitlab ~]# git clone ssh://git@gitlab.apps.it.example.com:30022/root/test.git
Cloning into 'test'...
Warning: Permanently added '[gitlab.apps.it.example.com]:30022,[192.168.1.3]:30022' (ECDSA) to the list of known hosts.
remote: Counting objects: 12, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 12 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (12/12), done.

參考資源

https://docs.gitlab.com/ee/install/openshift_and_gitlab/index.html

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容