sonarqube

sonarqube 架构简介

image-20221019105210386

  1. SonarQube Scanner 扫描仪在本地执行代码扫描任务

  2. 执行完后,将分析报告被发送到SonarQube服务器进行处理

  3. SonarQube服务器处理和存储分析报告导致SonarQube数据库,并显示结果在UI中。

部署 on k8s

sonar/secret.yaml

apiVersion: v1
kind: Secret
metadata:
name: sonar
  namespace: jenkins
type: Opaque
data:
  POSTGRES_USER: cm9vdA==
  POSTGRES_PASSWORD: MTIzNDU2   # 123456

sonar/postgres.yaml

apiVersion: v1
kind: Service
metadata:
  name: sonar-postgres
  labels:
    app: sonar-postgres
  namespace: jenkins
spec: ports:
  - name: server
    port: 5432
    targetPort: 5432
    protocol: TCP
  selector:
    app: sonar-postgres
---
apiVersion: apps/v1
kind: Deployment
metadata:
  namespace: jenkins
  name: sonar-postgres
  labels:
    app: sonar-postgres
spec:
  replicas: 1
  selector:
    matchLabels:
      app: sonar-postgres
  template:
    metadata:
      labels:
        app: sonar-postgres
    spec:
      nodeSelector:
        sonar: "true"
      tolerations:
      - operator: "Exists"
      containers:
      - name: postgres
        image:  172.21.32.13:5000/postgres:11.4
        imagePullPolicy: "IfNotPresent"
        ports:
        - containerPort: 5432
        env:
        - name: POSTGRES_DB		#PostgreSQL 数据库名称
          value: "sonar"
        - name: POSTGRES_USER		#PostgreSQL 用户名
          valueFrom:
            secretKeyRef:
              name: sonar
              key: POSTGRES_USER		#PostgreSQL 密码
        - name: POSTGRES_PASSWORD
          valueFrom:
            secretKeyRef:
        			name: sonar
              key: POSTGRES_PASSWORD
        resources:
          limits:
            cpu: 1000m
            memory: 2048Mi
          requests:
            cpu: 500m
            memory: 1024Mi
        volumeMounts:
        - mountPath: /var/lib/postgresql/data
          name: postgredb
      volumes:
      - name: postgredb
        hostPath:
          path: /var/lib/postgres/
          type: Directory

未完。。。