镜像准备
postgres:11.6 sonarqube:9.0.0-community busybox:1.27.1
安装postgres
sonarqube7.9及以上使用postgres为数据库使用
PVCapiVersion: v1 kind: PersistentVolumeClaim metadata: name: sonar-mysql namespace: demo spec: accessModes: - ReadWriteMany resources: requests: storage: 1Gi storageClassName: nfs volumeMode: Filesystem
Deployment
kind: Deployment apiVersion: apps/v1 metadata: name: sonar-db namespace: demo labels: app: sonar-db name: sonar-db spec: replicas: 1 selector: matchLabels: app: sonar-db name: sonar-db template: metadata: labels: app: sonar-db name: sonar-db spec: volumes: - name: sonar-mysql persistentVolumeClaim: claimName: sonar-mysql containers: - name: postgres image: 'postgres:11.6' ports: - containerPort: 5432 protocol: TCP env: - name: POSTGRES_DB value: sonardb - name: POSTGRES_USER value: sonar - name: POSTGRES_PASSWORD value: sonar resources: limits: cpu: '1' memory: 2Gi requests: cpu: 800m memory: 2Gi volumeMounts: - name: sonar-mysql mountPath: /var/lib/postgresql/data imagePullPolicy: IfNotPresent restartPolicy: Always
Service
kind: Service apiVersion: v1 metadata: name: sonar-db namespace: demo labels: name: sonar-db spec: ports: - name: tcp-port-0 protocol: TCP port: 5432 targetPort: 5432 selector: name: sonar-db type: ClusterIP
安装sonarqube
PVC
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: sonar-data namespace: demo spec: accessModes: - ReadWriteMany resources: requests: storage: 1Gi storageClassName: nfs volumeMode: Filesystem --- apiVersion: v1 kind: PersistentVolumeClaim metadata: name: sonar-extensions namespace: demo spec: accessModes: - ReadWriteMany resources: requests: storage: 1Gi storageClassName: nfs volumeMode: Filesystem
Deployment
kind: Deployment apiVersion: apps/v1 metadata: name: sonarqube namespace: demo labels: app: sonarqube name: sonarqube spec: replicas: 1 selector: matchLabels: app: sonarqube name: sonarqube template: metadata: labels: app: sonarqube name: sonarqube spec: volumes: - name: sonar-extensions persistentVolumeClaim: claimName: sonar-extensions - name: sonar-data persistentVolumeClaim: claimName: sonar-data initContainers: - name: init-sysctl image: 'busybox:1.27.1' command: # elasticsearch用户拥有的内存权限太小,es启动会报错,此命令保证es正常启动 - sysctl - '-w' - vm.max_map_count=262144 ports: - containerPort: 80 protocol: TCP resources: limits: cpu: '1' memory: 2Gi requests: cpu: 800m memory: 2Gi terminationMessagePath: /dev/termination-log terminationMessagePolicy: File imagePullPolicy: IfNotPresent securityContext: # 配置特权 privileged: true containers: - name: sonarqube image: 'sonarqube:9.0.0-community' ports: - containerPort: 9000 protocol: TCP env: - name: SONARQUBE_JDBC_USERNAME value: sonar - name: SONARQUBE_JDBC_PASSWORD value: sonar - name: SONARQUBE_JDBC_URL value: 'jdbc:postgresql://sonar-db.demo:5432/sonardb' resources: limits: cpu: '1' memory: 4Gi requests: cpu: 800m memory: 2Gi volumeMounts: - name: sonar-extensions mountPath: /opt/sonarqube/extensions - name: sonar-data mountPath: /opt/sonarqube/data readinessProbe: httpGet: path: / port: 9000 scheme: HTTP initialDelaySeconds: 240 timeoutSeconds: 5 periodSeconds: 5 successThreshold: 1 failureThreshold: 3 imagePullPolicy: IfNotPresent securityContext: privileged: false restartPolicy: Always
Service
kind: Service apiVersion: v1 metadata: name: sonarqube namespace: demo labels: name: sonarqube spec: ports: - name: tcp-port-0 protocol: TCP port: 9000 targetPort: 9000 selector: name: sonarqube type: ClusterIP|NodePort
标签:name,部署,sonarqube,db,sonar,安装,spec,metadata From: https://www.cnblogs.com/putaoo/p/17447545.html