容器部署gitlab

介绍

GitLab 是一个用于仓库管理系统的开源项目。使用Git作为代码管理工具,并在此基础上搭建起来的web服务

可通过 Web 界面进行访问公开的或者私人项目。它拥有与Github类似的功能,能够浏览源代码,管理缺陷和注释。可以管理团队对仓库的访问,它非常易于浏览提交过的版本并提供一个文件历史库。团队成员可以利用内置的简单聊天程序(Wall)进行交流。它还提供一个代码片段收集功能可以轻松实现代码复用。

可以简单的理解,gitlab 就是支持搭建在本地(公司)服务器上的一个 github。 支持相关的个性化设置和配置,同时gitlab 支持相关的 CI (持续化集成), 为相关的项目自动化集成构建、测试、部署、交付提供了可能。

特征

  • GitLab免费托管您的(私人)软件项目。
  • GitLab是管理Git存储库的平台。
  • GitLab提供免费的公共和私人存储库,问题跟踪和维基。
  • GitLab是Git之上的一个用户友好的Web界面层,它提高了使用Git的速度。
  • GitLab提供了自己的持续集成(CI)系统来管理项目,并提供用户界面以及GitLab的其他功能。

优点

  • GitLab提供了GitLab Community Edition版本,供用户在他们的代码所在的服务器上进行定位。
  • GitLab免费提供无限数量的私人和公共存储库。
  • 代码片段可以共享项目中的少量代码,而不是共享整个项目。

部署

下面部署所涉及到文件皆可在gitee仓库上获取

docker 运行 gitlab

version: '3.6'
services:
  web:
    image: 'gitlab/gitlab-ce:latest'
    restart: always
    hostname: 'gitlab'
    container_name: 'gitlab'
    environment:
      TZ: Asia/Shanghai
      GITLAB_OMNIBUS_CONFIG: |
        # 在此处添加任何其他 gitlab.rb 配置,每个都在自己的行中
        external_url 'http://192.168.50.134'
        gitlab_rails['lfs_enabled'] = true
    ports:
      - '80:80'
      - '443:443'
      - '22:22'
    volumes:
      - './service/gitlab/config:/etc/gitlab'
      - './service/gitlab/logs:/var/log/gitlab'
      - './service/gitlab/data:/var/opt/gitlab'
    shm_size: '256m'
# 创建本地持久化目录
mkdir -p ./service/gitlab/{data,logs,config}
# 授权,或者执行提示 Permission denied
sudo chmod -R 777 ./service
# 启动服务
docker-compose up -d
# 获取密码
sudo docker exec -it gitlab grep 'Password:' /etc/gitlab/initial_root_password

kubernetes 运行 gitlab

gitlab-deploy.yaml

## Service
kind: Service
apiVersion: v1
metadata:
  name: gitlab
  labels:
    name: gitlab
spec:
  ports:
    - name: http
      protocol: TCP
      port: 80
      targetPort: http
      nodePort: 31001
    - name: ssh
      protocol: TCP
      port: 22
      targetPort: ssh
      nodePort: 31002
  selector:
    name: gitlab
  type: NodePort
---
## Deployment
kind: Deployment
apiVersion: apps/v1
metadata:
  name: gitlab
  labels:
    name: gitlab
spec:
  replicas: 1
  selector:
    matchLabels:
      name: gitlab
  template:
    metadata:
      name: gitlab
      labels:
        name: gitlab
    spec:
      containers:
        - name: gitlab
          image: 'sameersbn/gitlab:14.7.1'
          ports:
            - name: ssh
              containerPort: 22
            - name: http
              containerPort: 80
            - name: https
              containerPort: 443
          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: admin.gitlab123!
            - name: GITLAB_ROOT_EMAIL
              value: admin@163.com
            - name: GITLAB_HOST
              value: '192.168.50.134'
            - name: GITLAB_PORT
              value: '80'
            - name: GITLAB_SSH_PORT
              value: '22'
            - name: GITLAB_NOTIFY_ON_BROKEN_BUILDS
              value: 'true'
            - name: GITLAB_NOTIFY_PUSHER
              value: 'false'
            - name: DB_TYPE
              value: postgres
            - name: DB_HOST
              value: gitlab-postgresql
            - name: DB_PORT
              value: '5432'
            - name: DB_USER
              value: gitlab
            - name: DB_PASS
              value: admin.gitlab123!
            - name: DB_NAME
              value: gitlabhq_production
            # 使用外置redis
            - name: REDIS_HOST
              value: gitlab-redis
            - name: REDIS_PORT
              value: '6379'
#          resources:
#            requests:
#              cpu: 4
#              memory: 8Gi
#            limits:
#              cpu: 4
#              memory: 8Gi
          livenessProbe:
            httpGet:
              path: /
              port: 80
              scheme: HTTP
            initialDelaySeconds: 300
            timeoutSeconds: 5
            periodSeconds: 10
            successThreshold: 1
            failureThreshold: 3
          readinessProbe:
            httpGet:
              path: /
              port: 80
              scheme: HTTP
            initialDelaySeconds: 5
            timeoutSeconds: 30
            periodSeconds: 10
            successThreshold: 1
            failureThreshold: 3
          volumeMounts:
            - name: data
              mountPath: /home/git/data
            - name: localtime
              mountPath: /etc/localtime
      volumes:
        - name: data
          hostPath:
            path: /data/gitlab
            type: DirectoryOrCreate
        - name: localtime
          hostPath:
            path: /etc/localtime

postgresql-deploy.yaml

## Service
kind: Service
apiVersion: v1
metadata:
  name: gitlab-postgresql
  labels:
    name: gitlab-postgresql
spec:
  ports:
    - name: postgres
      protocol: TCP
      port: 5432
      targetPort: postgres
  selector:
    name: postgresql
  type: ClusterIP
---
## Deployment
kind: Deployment
apiVersion: apps/v1
metadata:
  name: postgresql
  labels:
    name: postgresql
spec:
  replicas: 1
  selector:
    matchLabels:
      name: postgresql
  template:
    metadata:
      name: postgresql
      labels:
        name: postgresql
    spec:
      containers:
        - name: postgresql
          image: sameersbn/postgresql:12-20200524
          ports:
            - name: postgres
              containerPort: 5432
          env:
            - name: DB_USER
              value: gitlab
            - name: DB_PASS
              value: admin.gitlab123!
            - name: DB_NAME
              value: gitlabhq_production
            - name: DB_EXTENSION
              value: 'pg_trgm,btree_gist'
          resources:
            requests:
              cpu: 2
              memory: 2Gi
            limits:
              cpu: 2
              memory: 2Gi
          livenessProbe:
            exec:
              command: [ "pg_isready","-h","localhost","-U","postgres" ]
            initialDelaySeconds: 30
            timeoutSeconds: 5
            periodSeconds: 10
            successThreshold: 1
            failureThreshold: 3
          readinessProbe:
            exec:
              command: [ "pg_isready","-h","localhost","-U","postgres" ]
            initialDelaySeconds: 5
            timeoutSeconds: 1
            periodSeconds: 10
            successThreshold: 1
            failureThreshold: 3
          volumeMounts:
            - name: data
              mountPath: /var/lib/postgresql
      volumes:
        - name: data
          hostPath:
            path: /data/postgresql
            type: DirectoryOrCreate

redis-deploy.yaml

## Service
kind: Service
apiVersion: v1
metadata:
  name: gitlab-redis
  labels:
    name: gitlab-redis
spec:
  type: ClusterIP
  ports:
    - name: redis
      protocol: TCP
      port: 6379
      targetPort: redis
  selector:
    name: gitlab-redis
---
## Deployment
kind: Deployment
apiVersion: apps/v1
metadata:
  name: gitlab-redis
  labels:
    name: gitlab-redis
spec:
  replicas: 1
  selector:
    matchLabels:
      name: gitlab-redis
  template:
    metadata:
      name: gitlab-redis
      labels:
        name: gitlab-redis
    spec:
      containers:
        - name: gitlab-redis
          image: 'redis:6.2.6'
          ports:
            - name: redis
              containerPort: 6379
              protocol: TCP
          resources:
            limits:
              cpu: 1000m
              memory: 2Gi
            requests:
              cpu: 1000m
              memory: 2Gi
          volumeMounts:
            - name: data
              mountPath: /data
          livenessProbe:
            exec:
              command:
                - redis-cli
                - ping
            initialDelaySeconds: 5
            timeoutSeconds: 5
            periodSeconds: 10
            successThreshold: 1
            failureThreshold: 3
          readinessProbe:
            exec:
              command:
                - redis-cli
                - ping
            initialDelaySeconds: 5
            timeoutSeconds: 5
            periodSeconds: 10
            successThreshold: 1
            failureThreshold: 3
      volumes:
        - name: data
          hostPath:
            path: /data/redis
            type: DirectoryOrCreate

按顺序启动

kubectl apply -f redis-deploy.yaml
kubectl apply -f postgresql-deploy.yaml
kubectl apply -f gitlab-deploy.yaml

登录设置(不强求设置)

  1. 登陆后看喜好设置语言
    在这里插入图片描述

  2. 重置管理员密码
    在这里插入图片描述

  3. 设置禁止注册
    在这里插入图片描述

参考文档

docs.gitlab.com

kubernetes部署gitlab

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值