侧边栏壁纸
博主头像
★街角晚灯★博主等级

博观而约取 厚积而薄发

  • 累计撰写 450 篇文章
  • 累计创建 183 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

K8S 安装部署SonarQube

WinJay
2024-01-13 / 0 评论 / 0 点赞 / 9 阅读 / 4329 字 / 正在检测是否收录...
温馨提示:
文章发布较早,内容可能过时,阅读注意甄别。。。。

K8S 安装部署Sonar

img

创建数据存储

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: sonarqube-data
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi

---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: postgres-data
spec:
  storageClassName: alicloud-nas
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 10Gi

部署数据库

apiVersion: apps/v1
kind: Deployment
metadata:
  name: postgres-sonar
spec:
  replicas: 1
  selector:
    matchLabels:
      app: postgres-sonar
  template:
    metadata:
      labels:
        app: postgres-sonar
    spec:
      containers:
      - name: postgres-sonar
        image: postgres:latest
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 5432
        env:
        - name: POSTGRES_DB
          value: "sonar"
        - name: POSTGRES_USER
          value: "YourUserName"
        - name: POSTGRES_PASSWORD
          value: "YourPassword"
        volumeMounts:
          - name: data
            mountPath: /var/lib/postgresql/data
      volumes:
        - name: data
          persistentVolumeClaim:
            claimName: postgres-data

---
apiVersion: v1
kind: Service
metadata:
  name: postgres-sonar
  labels:
    app: "postgres-sonar"
spec:
  selector:
    app: postgres-sonar
  type: NodePort
#  clusterIP: None
  ports:
  - name: postgre-sql
    port: 5432
    targetPort: 5432
    protocol: TCP
    nodePort: 30432

创建Secret

apiVersion: v1
kind: Secret
metadata:
  name: postgre-secret
type: Opaque
data:
  username: cm9vdA==		# base64加密用户名后的字符串
  password: bGl0U09mdDIwMjM=		# base64加密密码后的字符串
  
  #

image-20230228111956946

image-20230228105825645

image-20230228105859098

部署Sonar

helm install sonarqube stevehipwell/sonarqube \
  --version 4.9.0 \
  --namespace sonar \
  --set psql.host=postgres-sonar \
  --set psql.port=5432 \
  --set psql.database=sonar \
  --set psql.username=root \
  --set psql.password.secret=postgre-secret \
  --set psql.password.key=password \
  --set sonarqube.persistence.enabled=true \
  --set sonarqube.persistence.storageClass=alicloud-nas \
  --set sonarqube.persistence.existingClaim=sonarqube-data
  • 执行完反馈信息如下:
apiVersion: networking.k8s.io/v1
LAST DEPLOYED: Mon Feb 27 13:16:26 2023
NAMESPACE: monitoring
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
1. Get the application URL by running these commands:
  export POD_NAME=$(kubectl get pods --namespace monitoring -l "app.kubernetes.io/name=sonarqube,app.kubernetes.io/instance=sonarqube" -o jsonpath="{.items[0].metadata.name}")
  export CONTAINER_PORT=$(kubectl get pod --namespace monitoring $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
  echo "Visit http://127.0.0.1:9000 to use your application"
  kubectl --namespace monitoring port-forward $POD_NAME 9000:$CONTAINER_PORT
  
[root@master 008.Sonarqube]# ls
001.pvc.yaml

image-20230227141412693

image-20230228112233048

部署完成。


使用

创建Token

<properties>
  <sonar.qualitygate.wait>true</sonar.qualitygate.wait>
</properties>
sqa_2e3596f5a6d245bb427ac46ee006b501329eaa87

image-20230228130839897

0
  1. 支付宝打赏

    qrcode alipay
  2. 微信打赏

    qrcode weixin

评论区