当前位置:   article > 正文

基于Kubernetes安装Gitlab_kubernetes gitlab-template

kubernetes gitlab-template

基于Kubernetes安装Gitlab

1、创建命名空间gitlab

kubectl create namespace gitlab
  • 1

2、然后创建gitlab用的PVC,编写yaml配置文件

vim pvc-gitlab.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  namespace: gitlab
  name: gitlab-data
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 40Gi
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

然后使用如下命令创建

kubectl apply -f pvc-gitlab.yaml
  • 1

3、创建Postgre用的PVC的配置文件 pvc-postsql.yaml

vim pvc-postsql.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
		namespace:gitlab
		name: postsql-data
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage:5Gi
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

然后执行如下命令

kubectl apply -f pvc-postsql.yaml
  • 1

4、为redis创建pvc,文件名 pvc-redis.yaml

vim pvc-redis.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  namespace: gitlab
  name: redis-data
spec:
  accessModes:
    - ReadWriteMany
  resource:
    requests:
      storage: 5Gi
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

然后执行如下命令创建供redis使用的pvc

kubectl apply -f pvc-redis.yaml
  • 1

5、编写创建postgresql的yaml配置文件

vim postsql.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: postgresql
  namespace: gitlab
  labels:
    name: postgresql
spec:
  selector:
    matchLabels:
       name: postgresql
  template:
    metadata:
      labels:
        name: postgresql
    spec:
      containers:
      - name: postgresql
        image: sameersbn/postgresql:10
        imagePullPolicy: IfNotPresent
        env:
        - name: DB_USER
          value: gitlab
        - name: DB_PASS
          value: gitlab
        - name: DB_NAME
          value: gitlab_production
        - name: DB_EXTENSION
          value: pg_trgm
        ports:
        - name: postgres
          containerPort: 5432
        volumeMounts:
        - mountPath: /var/lib/postgresql
          name: data
        livenessProbe:
          exec:
            command:
            - pg_isready
            - -h
            - localhost
            - -U
            - postgres
          initialDelaySeconds: 30
          timeoutSeconds: 5
        readinessProbe:
          exec:
            command:
            - pg_isready
            - -h
            - localhost
            - -U
            - postgres
          initialDelaySeconds: 5
          timeoutSeconds: 1
      volumes:
      - name: data
        persistentVolumeClaim:
          claimName: postsql-data
---
apiVersion: v1
kind: Service
metadata:
  name: postgresql
  namespace: gitlab
  labels:
    name: postgresql
spec:
  ports:
    - name: postgres
      port: 5432
      targetPort: postgres
  selector:
      name: postgresql
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76

然后执行如下命令创建Pod

kubectl apply -f postsql.yaml
  • 1

6、编写redis的yaml配置文件

vim redis.yaml

apiVersion: v1
kind: Deployment
metadata:
  namespace: gitlab
  name: redis
  lables: redis
spec:
  selector:
    matchLabels:
      name: redis
  template:
    metadata:
      name: redis
      labels:
        name: redis
    spec:
      containers:
      - name: redis
        image: sameersbn/redis
        imagePullPolicy: IfNotPresent
        ports:
        - name: redis
          containerPort: 6379
        volumeMounts:
        - mountPath: /var/lib/redis
          name: data
        livenessProbe:
          exec:
            command:
            - redis-cli
            - ping
          initialDelaySeconds: 30
          timeoutSeconds: 5
        readinessProbe:
          exec:
            command:
            - redis-cli
            - ping
          initialDelaySeconds: 5
          timeoutSeconds: 1
      volumes:
      - name: data
        persistentVolumeClaim:
          claimName: redis-data
---
apiVersion: v1
kind: Service
metadata:
  name: redis
  namespace: gitlab
  labels:
    name: redis
spec:
  ports:
    - name: redis
      port: 6379
      targetPort: redis
  selector:
    name: redis
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61

然后执行如下命令即可创建

kubectl apply -f redis.yaml
  • 1

7、编写创建gitlab的yaml配置文件

vim gitlab.yaml

apiVersion: v1
kind: Deployment
metadata:
  namespace: gitlab
  name: gitlab
  lables:
    name: gitlab
spec:
  selector:
    matchLabels:
        name: gitlab
  template:
    metadata:
      name: gitlab
      labels:
        name: gitlab
    spec:
      containers:
      - name: gitlab
        image: sameersbn/gitlab:11.8.1
        imagePullPolicy: IfNotPresent
        env:
        - name: TZ
          value: Asia/Shanghai
        - name: GITLAB_TIMEZONE
          value: Beijing
        - name: GITLAB_SECRETS_DB_KEY_BASE
          value: long-and-random-alpha-numeric-string
        - name: GITLAB_SECRETS_SECRET_KEY_BASE
          value: long-and-RANDOM-ALPHA-NUMERIc-string
        - name: GITLAB_SECRETS_OTP_KEY_BASE
          value: long-and-random-alpha-numeric-string
        - name: GITLAB_ROOT_PASSWORD
          value: admin321
        - name: GITLAB_ROOT_EMAIL
          value: hitredrose@163.com  ##这里填自己的邮箱
        - name: GITLAB_HOST
          value: 192.168.16.40   ##这里填gitlab的host地址,可以是主节点的ip
        - name: GITLAB_PORT
          value: "32765"       # 与下面Service中配置的nodePort一致
        - name: GITLAB_SSH_PORT  # 与下面Service中配置的nodePort一致
          value: "32766"
        - name: GITLAB_NOTIFY_ON_BROKEN_BUILDS
          value: "true"
        - name: GITLAB_NOTIFY_PUSHER
          value: "false"
        - name: GITLAB_BACKUP_SCHEDULE
          value: daily
        - name: GITLAB_BACKUP_TIME
          value: 01:00
        - name: DB_TYPE
          value: postgres
        - name: DB_HOST
          value: postgresql
        - name: DB_PORT
          value: "5432"
        - name: DB_USER
          value: gitlab
        - name: DB_PASS
          value: gitlab
        - name: DB_NAME
          value: gitlab_production
        - name: REDIS_HOST
          value: redis
        - name: REDIS_PORT
          value: "6379"
        ports:
        - name: http
          containerPort: 80
        - name: ssh
          containerPort: 22
        volumeMounts:
        - mountPath: /home/git/data
          name: data
        livenessProbe:
          httpGet:
            path: /
            port: 80
          initialDelaySeconds: 360  #这个值可以设置大一点,gitlab在启动时比较慢会处于一段时间的502,如果探测时间超过会进行重启,这样gitlab会一直处于重启状态
          timeoutSeconds: 50
        readinessProbe:
          httpGet:
            path: /
            port: 80
          initialDelaySeconds: 360
          timeoutSeconds: 50
      volumes:
      - name: data
        persistentVolumeClaim:
         claimName: gitlab-data
---
apiVersion: v1
kind: Service
metadata:
  name: gitlab
  namespace: gitlab
  labels:
    name: gitlab
spec:
  ports:
    - name: http
      port: 80
      targetPort: http
      nodePort: 32765
    - name: ssh
      port: 22
      nodePort: 32766
      targetPort: ssh
  selector:
    name: gitlab
  type: NodePort
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113

然后执行如下命令创建gitlab

kubectl apply -f gitlab.yaml
  • 1

8、此时执行如下命令查看gitlab命名空间中的pod的状态,如下都为running,表示正常

[root@master gitlab]# kubectl get pod -n gitlab
NAME                         READY   STATUS    RESTARTS   AGE
gitlab-855b5b7b7b-8hr97      1/1     Running   0          23m
postgresql-b75d769dd-dn2pt   1/1     Running   0          17h
redis-6c976f56dc-z7fsb       1/1     Running   0          55m
[root@master gitlab]#
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

然后通过Kubernetesmaster节点的ip地址和设置的端口比如这里32765,就可以访问gitlab了。

然后使用gitlab中设置的管理员密码,比如这里admin321,用户名root,就可以登录了,如下所示,为一个全新的gitlab。

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号