Build your own GitLab+jenkins and pull the image in kubernetes to run

Official website: https://about.gitlab.com/install/#centos-7 ; The official website explains that the machine installing gitlab should have at least 4G memory, because gitlab consumes more memory; This friend to build should pay attention

1, Install necessary dependencies

sudo yum install -y curl policycoreutils-python openssh-server 
sudo systemctl enable sshd
sudo systemctl start sshd
sudo firewall-cmd --permanent --add-service=http
sudo systemctl reload firewalld

2, If you want to send email, run the following content

sudo yum install postfix
sudo systemctl enable postfix
sudo systemctl start postfix

3, Add the warehouse address of gitlab

curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh | sudo bash
Note: the download speed of this warehouse may be very slow. At this time, you can use the domestic warehouse address
new file /etc/yum.repos.d/gitlab-ce.repo 
The content is
[gitlab-ce]
name=Gitlab CE Repository
baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/
gpgcheck=0
enabled=1

4, Set the domain name of gitlab and install gitlab

sudo EXTERNAL_URL="https://gitlab.ghy.com" yum install -y gitlab-ee 
If the domestic warehouse address is used, execute the following command. In fact, the difference is ee and ce edition
sudo EXTERNAL_URL="https://gitlab.ghy.com" yum install -y gitlab-ce
At this time, either buy a domain name or set it in the local hosts file
install gitlab Server ip address gitlab.ghy.com
If you don't want to set the domain name, you can directly install Yum install - y gitlab EE

5, Reconfigure

If not, you can run gitlab CTL reconfigure

6, Check the operation of gitlab

Gitlab CTL status can see the processes needed to run gitlab services

7, Visit

Enter gitlab ghy. COM, you need to change the password of the root account

8, Configure the installed gitlab

vim /etc/gitlab/gitlab.rb
After modification, be sure to gitlab CTL reconfigure

IX. jenkins construction and pipeline script

I have written and explained the construction of jenkins and various scripts in my jenkins space. I won't repeat them here. It seems that I don't share the construction method of pipeline in my jenkins space. I'll see later. If I don't write it, I'll share the pipeline release process in my jenkins space at that time.

10, Kubernetes pulls the image to run

Through git+jenkins+docker, you can build an image and push the image to the image warehouse. The following operations are based on the operations after the image has been pushed to the image warehouse
1) Write springboot demo Yaml file
At / root / Create springboot demo in Jenkins / workspace / scripts / yaml
# Deploy Pod with Deployment
apiVersion: apps/v1
kind: Deployment
metadata: 
  name: springboot-demo
spec: 
  selector: 
    matchLabels: 
      app: springboot-demo
  replicas: 1
  template: 
    metadata:
      labels: 
        app: springboot-demo
    spec: 
      containers: 
      - name: springboot-demo
        image: ghy/springboot-demo:v1.0
        ports: 
        - containerPort: 8080
---
# Create Service for Pod
apiVersion: v1
kind: Service
metadata: 
  name: springboot-demo
spec: 
  ports: 
  - port: 80
    protocol: TCP
    targetPort: 8080
  selector: 
    app: springboot-demo
---
# Create Ingress and define access rules
apiVersion: extensions/v1beta1
kind: Ingress
metadata: 
  name: springboot-demo
spec: 
  rules: 
  - host: springboot.ghy.com
    http: 
      paths: 
      - path: /
        backend: 
          serviceName: springboot-demo
          servicePort: 80

2) Write k8s deploy springboot demo SH file

vi /root/.jenkins/workspace/scripts/k8s-deploy-springboot-demo.sh
kubectl delete -f springboot-demo.yaml 
kubectl apply -f /root/.jenkins/workspace/scripts/springboot-demo.yaml
echo "k8s deploy success!"

3) Write pipeline; I didn't write it in detail because my friends who read this article by default have friends who read the foundation of jenkins pipeline release project; Add the following sentence to the pipeline script

stage('K8S Deploy') { 
sh "/root/.jenkins/workspace/scripts/k8s-deploy-springboot-demo.sh"
}

In this way, the whole pipeline releases the project process on k8s

 
 

Keywords: Kubernetes

Added by Gazan on Thu, 27 Jan 2022 07:11:16 +0200