K8S 安装部署Sonar
创建数据存储
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加密密码后的字符串
#
部署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
部署完成。
使用
创建Token
<properties>
<sonar.qualitygate.wait>true</sonar.qualitygate.wait>
</properties>
sqa_2e3596f5a6d245bb427ac46ee006b501329eaa87
评论区