当前位置: 首页 > article >正文

k8s部署sonarqube

SonarQube需要依赖数据库存储数据,且SonarQube7.9及其以后版本将不再支持Mysql,官网有推荐的几种数据库,我这块选择使用PostgreSQL作为SonarQube的数据库。

1、部署PGSql

由于我们有现成的pg库,是在阿里云上,这里就直接使用了。
首先在原有的pg实例上创建一个sonarqube的库"sonarDB",然后设置账号和密码。

2、部署SonarQube

deplyment.yaml
镜像仓库使用官方的最新版镜像

apiVersion: apps/v1
kind: Deployment
metadata:
  name: sonarqube
  labels:
    app: sonarqube
spec:
  replicas: 1
  selector:
    matchLabels:
      app: sonarqube
  template:
    metadata:
      labels:
        app: sonarqube
    spec:
      containers:
      - name: sonarqube
        image: sonarqube:9.9.0-community
        imagePullPolicy: IfNotPresent
        resources:
          limits:
            cpu: 2000m
            memory: 2048Mi
          requests:
            cpu: 500m
            memory: 500Mi
        ports:
        - containerPort: 9000
        env:
        - name: SONARQUBE_JDBC_USERNAME
          value: "sonarqube"
        - name: SONARQUBE_JDBC_PASSWORD
          value: "123456"
        - name: SONARQUBE_JDBC_URL
          value: "jdbc:postgresql://xxxx-xxxxx.pg.rds.aliyuncs.com:1921/sonarDB"
        livenessProbe:
          httpGet:
            path: /sessions/new
            port: 9000
          initialDelaySeconds: 60
          periodSeconds: 30
        readinessProbe:
          httpGet:
            path: /sessions/new
            port: 9000
          initialDelaySeconds: 60
          periodSeconds: 30
          failureThreshold: 6
        volumeMounts:
        - mountPath: /opt/sonarqube/conf
          name: data
          subPath: conf
        - mountPath: /opt/sonarqube/data
          name: data
          subPath: data
        - mountPath: /opt/sonarqube/extensions
          name: data
          subPath: extensions
      volumes:
      - name: data
        persistentVolumeClaim:
          claimName: sonarqube-data  

service.yaml

apiVersion: v1
kind: Service
metadata:
  name: sonarqube
  labels:
    app: sonarqube
spec:
  type: ClusterIP
  ports:
    - name: sonarqube
      port: 9000
      targetPort: 9000
      protocol: TCP
  selector:
    app: sonarqube

这里使用的是storageclass来构建pv和pvc,基于nfs来存储数据的,所以还需要创建nfs-provisioner和nfs-provisione的serviceaccount
storageclass.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: sonarqube-data
  annotations:
    volume.beta.kubernetes.io/storage-class: "course-nfs-storage"
spec:
  accessModes:
  - ReadWriteMany
  resources:
    requests:
      storage: 500Mi
[root@wdcloud sonarqube]# ls
nfs-client-sa.yaml  nfs-client.yaml  pvc.yaml  service.yaml  sonarqube-deployment.yaml  storageclass.yaml

storageclass.yaml

[root@wdcloud sonarqube]# cat storageclass.yaml 
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: course-nfs-storage
provisioner: fuseim.pri/ifs
allowVolumeExpansion: true

nfs-client-sa.yaml

apiVersion: v1
kind: ServiceAccount
metadata:
  name: nfs-client-provisioner

---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: nfs-client-provisioner-runner
rules:
  - apiGroups: [""]
    resources: ["persistentvolumes"]
    verbs: ["get", "list", "watch", "create", "delete"]
  - apiGroups: [""]
    resources: ["persistentvolumeclaims"]
    verbs: ["get", "list", "watch", "update"]
  - apiGroups: ["storage.k8s.io"]
    resources: ["storageclasses"]
    verbs: ["get", "list", "watch"]
  - apiGroups: [""]
    resources: ["events"]
    verbs: ["list", "watch", "create", "update", "patch"]
  - apiGroups: [""]
    resources: ["endpoints"]
    verbs: ["create", "delete", "get", "list", "watch", "patch", "update"]

---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: run-nfs-client-provisioner
subjects:
  - kind: ServiceAccount
    name: nfs-client-provisioner
    namespace: devops
roleRef:
  kind: ClusterRole
  name: nfs-client-provisioner-runner
  apiGroup: rbac.authorization.k8s.io

nfs-client-provisioner.yaml

kind: Deployment
apiVersion: apps/v1
metadata:
  name: nfs-client-provisioner
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nfs-client-provisioner
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: nfs-client-provisioner
    spec:
      serviceAccountName: nfs-client-provisioner
      containers:
        - name: nfs-client-provisioner
          image: quay.io/external_storage/nfs-client-provisioner:latest
          volumeMounts:
            - name: nfs-client-root
              mountPath: /persistentvolumes
          env:
            - name: PROVISIONER_NAME
              value: fuseim.pri/ifs
            - name: NFS_SERVER
              value: xx.xx.xx.xx
            - name: NFS_PATH
              value: /data/storage/sonarqube
      volumes:
        - name: nfs-client-root
          nfs:
            server: xx.xx.xx.xx
            path: /data/storage/sonarqube

pvc.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: sonarqube-data
  annotations:
    volume.beta.kubernetes.io/storage-class: "course-nfs-storage"
spec:
  accessModes:
  - ReadWriteMany
  resources:
    requests:
      storage: 500Mi

部署完成后,可以通过serviceIP进行访问,账号和密码都是admin,有需要配置域名访问的,需要自己单独配置。


http://www.kler.cn/a/10194.html

相关文章:

  • Pycharm,2024最新版Pycharm下载安装配置教程!
  • C++ 并发专题 - 无锁数据结构(队列)
  • 右旋圆极化散射后的stocks矢量 与T3矩阵的关系
  • 100种算法【Python版】第56篇——Delaunay三角剖分之增量法
  • 一、文心一言问答系统为什么要分对话,是否回学习上下文?二、文心一言是知识检索还是大模型检索?三、文心一言的词向量、词语种类及多头数量
  • 兰空图床配置域名访问
  • C++11 如何区分右值引用与万能引用
  • QtSqlite加密--QtCipherSqlitePlugin的使用
  • QML控件--DialogButtonBox
  • 【精华】OCR关键信息提取之SER和RE
  • MyBatis基础增删改查
  • 类ChatGPT代码级解读:如何从零起步实现Transformer、llama/ChatGLM
  • 如何压缩照片到30kb以下?三个方法
  • MySQL之数据类型
  • 一个评测模型+10个问题,摸清盘古、通义千问、文心一言、ChatGPT的“家底”!...
  • 基于Spring Boot和Vue3打造一个属于自己的博客平台CodeInsight
  • 【AIGC】7、CLIP | OpenAI 出品使用 4 亿样本训练的图文匹配模型
  • 高可用同时数千人在线的微服务架构需要做些什么工作
  • 2023年的深度学习入门指南(3) - 动手写第一个语言模型
  • [NOIP2017 提高组] 逛公园 (题解)
  • macosBrew
  • 华纳云:php怎么判断域名跳转
  • SpringSecurity中用户表单登录验证源码分析
  • jQuery位置方法
  • 【Cesium 编程第一篇】概述、环境搭建、界面介绍
  • 总结815