Preface:

With reference to article before https://www.yuque.com/duiniwukenaihe/ehb02i in https://www.yuque.com/duiniwukenaihe/ehb02i/qz49ev. To complete the Kubernetes DevOps workflow. Jenkins has already been set up. The GITLAB code repository is also essential. Now let’s go to Gitlab, which we did a little bit more detail about Helm, but I’m going to skip over. Before another gitlab version don’t have Chinese version to reference https://hub.docker.com/r/twang2218/gitlab-ce-zh/ twang2218 localization version. Now that GitLab supports multiple languages, you can skip it. Let’s start installing GitLab. Take a look at Helm’s installation… Fewer articles. Or decided to install it in the YAML way

1. Create PVC required in the construction of GITLAB

Preliminary planning: StorageClass is stored using the open source CBS-CSI plug-in of Tencent Cloud. Since the minimum value can only be 10G, Redis PostgreSQL is set to 10G. I want to emphasize that PVC specifies namespace. Yesterday my hand is out of control install Kubesphere play, the result found that he brought the Prometheus to my PV, PVC preempted…. I don’t know if this is a CBS holdup or if there is something wrong with the way they build it. Finally, the user name and password kept being wrong. Uninstall, don’t play……

cat gitlab-pvc.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: gitlab-pvc
  namespace: kube-ops
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 100Gi
  storageClassName: cbs-csi

cat gitlab-redis-pvc.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: gitlab-redis-pvc
  namespace: kube-ops  
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
  storageClassName: cbs-csi

cat gitlab-pg-pvc.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: gitlab-pg-pvc
  namespace: kube-ops 
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
  storageClassName: cbs-csi
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  namespace: kube-ops
  name: gitlab-http
spec:
  entryPoints:
    - web
  routes:
    - match: Host(`gitlab.saynaihe.com`)
      kind: Rule
      services:
        - name: gitlab
          port: 80

Execute in the current directory

kubectl apply -f .

2. Gitlab – redis structures

Note: namespace is specified specifically, otherwise when executing the kubectl apply-f YAML file you will often forget to specify namespace, claimName is modified to the PVC you created. cat redis.yaml

## Service
kind: Service
apiVersion: v1
metadata:
  name: gitlab-redis
  namespace: kube-ops
  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
  namespace: kube-ops
  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: 'sameersbn/redis:4.0.9-3'
        ports:
        - name: redis
          containerPort: 6379
          protocol: TCP
        resources:
          limits:
            cpu: 1000m
            memory: 2Gi
          requests:
            cpu: 1000m
            memory: 2Gi
        volumeMounts:
          - name: data
            mountPath: /var/lib/redis
        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
        persistentVolumeClaim:
          claimName: gitlab-redis-pvc
kubectl  apply -f redis.yaml



Wait until the creation completes running.

3. Gitlab – postgresql structures

Modify the pg configuration cat pg.yaml as with the redis configuration

## Service
kind: Service
apiVersion: v1
metadata:
  name: gitlab-postgresql
  namespace: kube-ops
  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
  namespace: kube-ops
  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@mydlq
        - 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
        persistentVolumeClaim:
          claimName: gitlab-pg-pvc

kubectl apply -f pg.yaml

4. GITLAB Deployment setup

cat gitlab.yaml

## Service
kind: Service
apiVersion: v1
metadata:
  name: gitlab
  namespace: kube-ops
  labels:
    name: gitlab
spec:
  ports:
    - name: http
      protocol: TCP
      port: 80
    - name: ssh
      protocol: TCP
      port: 22
  selector:
    name: gitlab
  type: ClusterIP
---
## Deployment
kind: Deployment
apiVersion: apps/v1
metadata:
  name: gitlab
  namespace: kube-ops
  labels:
    name: gitlab
spec:
  replicas: 1
  selector:
    matchLabels:
      name: gitlab
  template:
    metadata:
      name: gitlab
      labels:
        name: gitlab
    spec:
      containers:
      - name: gitlab
        image: 'sameersbn/gitlab:13.6.2'
        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@mydlq
        - name: GITLAB_ROOT_EMAIL 
          value: [email protected]     
        - name: GITLAB_HOST           
          value: 'gitlab.saynaihe.com'
        - 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@mydlq
        - name: DB_NAME          
          value: gitlabhq_production
        - name: REDIS_HOST
          value: gitlab-redis              
        - name: REDIS_PORT      
          value: '6379'
        resources: 
          requests:
            cpu: 2
            memory: 4Gi
          limits:
            cpu: 2
            memory: 4Gi
        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
        persistentVolumeClaim:
          claimName: gitlab-pvc
      - name: localtime
        hostPath:
          path: /etc/localtime

The basic copy of the dudin big man’s document. But I got rid of the NodePort method. I prefer to use Ingress’s proxy mode. The password username configuration that can be installed on its own needs has changed.



Waiting for running…

5. Ingress configuration

cat ingress.yaml

apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  namespace: kube-ops
  name: gitlab-http
spec:
  entryPoints:
    - web
  routes:
    - match: Host(`gitlab.saynaine.com`)
      kind: Rule
      services:
        - name: gitlab
          port: 80

kubectl apply -f ingress.yaml

Visit gitlab.saynaihe.com(The domain name is still fictitious.) . We’ve done a forced jump. Therefore, the default user name of Wei HTTP page to visit is root, and the password is set in the gitlab.yaml file. (As for the display of Chinese, because my Google browser installed a Chinese translation plug-in)



OK, logged in successfully

6. Close user registration and change the default language to Chinese.









Basic installation complete. The other uses will be studied later……. Now it’s time to put the toolchain together. Remember to change the user name and password…. after logging in GITLAB It is necessary to increase personal safety awareness.