Why build Gitlab + Drone

In order to realize the automatic deployment of DevOPS, the mode of GitLab + Dronoe (Jenkins can be used if the server resources allow) is adopted here. It will then be inserted into minikube

gitlab

GitLab is an open source project for warehouse management system. It uses Git as a code management tool and builds web services based on it

  • The installation
    • Docker pull gitlab/gitlab – ce: 13.7.1 – ce. 0
    • To modify gitlab external_URL, modify exit port 80
    • docker run -it -d –detach –restart unless-stopped -p 13080:13080 -p 13443:443 -p 13022:22 –name gitlab Gitlab/gitlab – ce: 13.7.1 – ce. 0
  • configuration
    • Configure the nginx reverse proxy
    upstream gitlab { server xxxx:13080; } server { listen 80; listen [::]:80; server_name git.tool.mybns.cn; #charset koi8-r; access_log /var/log/nginx/git.tool.mybns.cn.success.log main; error_log /var/log/nginx/git.tool.mybns.cn.error.log error; location / { client_max_body_size 1024m; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; # reverse proxy to gitLab built-in nginx proxy_pass http://gitlab; index index.html index.htm; }}Copy the code
    • Modify the configuration
      • vim /etc/gitlab/gitlab.rb
      External_url 'http://192.168.***.***' gitlab_rails['gitlab_shell_ssh_port'] = 13022Copy the code
      • gitlab-ctl reconfigure
      • gitlab-ctl restart
  • Install the results

drone

Compared with Jenkins, Drone is much lighter and simpler from the installation and deployment of the application itself to the construction of the assembly line. Because it is integrated with the source code management system, so Drone naturally eliminates the configuration of various accounts \ permissions, directly with Gitlab, Github, Bitbucket such source code management system operation permissions

  • The installation
    • Docker pull drone/drone: 1.10.1
    • Installation documentation: docs. Drone. IO/server/prov…
    • Gitlab creates applications
    • Remember to save the appID and key
    • Create drone key to install runner using openssl Rand-HEX 16
    • Start the installation
    docker run \
    --volume=/var/lib/drone:/data \
    --env=DRONE_GITLAB_SERVER=https://gitlab.com \
    --env=DRONE_GITLAB_CLIENT_ID={{DRONE_GITLAB_CLIENT_ID}} \
    --env=DRONE_GITLAB_CLIENT_SECRET={{DRONE_GITLAB_CLIENT_SECRET}} \
    --env=DRONE_RPC_SECRET={{DRONE_RPC_SECRET}} \
    --env=DRONE_SERVER_HOST={{DRONE_SERVER_HOST}} \
    --env=DRONE_SERVER_PROTO={{DRONE_SERVER_PROTO}} \
    --publish=2080:80 \
    --publish=2443:443 \
    --restart=always \
    --detach=true \
    --name=drone \
    drone/drone:1
    Copy the code
    • Nginx reverse proxy
    upstream drone { server xxx:2080; } server { listen 80; listen [::]:80; server_name drone.tool.mybns.cn; #charset koi8-r; access_log /var/log/nginx/drone.tool.mybns.cn.success.log main; error_log /var/log/nginx/drone.tool.mybns.cn.error.log error; location / { client_max_body_size 1024m; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://drone; index index.html index.htm; }}Copy the code
  • Install the results

Install the drone – docker – runner

  • Docker pull drone/drone – runner – docker: 1.6
  • The installation
docker run -d \ -v /var/run/docker.sock:/var/run/docker.sock \ -e DRONE_RPC_PROTO=https \ -e DRONE_RPC_HOST=xxxxxxx \ -e  DRONE_RPC_SECRET=xxxxx \ -e DRONE_RUNNER_CAPACITY=2 \ -p 23000:3000 \ --restart always \ --name runner \ Drone/drone - runner - docker: 1.6Copy the code
  • Test: Docker logs Runner

Interconnecting with the Minikube test

  • Note: The minikube apiserver port is 8443. For details, see the ~/. Kube /config file on the minikube server
  • . The drone. Yml file
kind: pipeline type: docker name: default steps: - name: build image: golang commands: - go version - name: Deploy image: Danielgormly /drone-plugin-kube:0.2.0 Settings: template:./testdrone.yaml Server: https://xxxxx:8443 token: XXXXX / / through the command kubectl -n kube - system go in secret $(kubectl -n kube - system get secret | grep default - token | awk '{print $1}') get default-token change to your accountService ca: XXXXXCopy the code
  • Testdrone yaml files
--- apiVersion: apps/v1 kind: Deployment metadata: annotations: deployment.kubernetes.io/revision: '1' k8s.kuboard.cn/displayName: nginx k8s.kuboard.cn/ingress: 'true' k8s.kuboard.cn/service: ClusterIP k8s.kuboard.cn/workload: nginx generation: 1 labels: k8s.kuboard.cn/layer: '' k8s.kuboard.cn/name: testdrone name: testdrone namespace: default spec: progressDeadlineSeconds: 600 replicas: 1 revisionHistoryLimit: 10 selector: matchLabels: k8s.kuboard.cn/layer: '' k8s.kuboard.cn/name: testdrone template: metadata: labels: k8s.kuboard.cn/layer: '' k8s.kuboard.cn/name: testdrone spec: containers: - image: 'Nginx :1.19.6-alpine' imagePullPolicy: IfNotPresent name: TestdroneCopy the code
  • perform
  • Check the pod

installed