在Kubernetes上运行SonarQube

在Kubernetes上运行SonarQube

2017-01-17
Kubernetes, Sonarqube

文本描述如何在Kubernetes上运行一个Sonarqube和MySQL。

准备 #

kubernetes集群构成如下,这里是单机的试验环境。

1kubectl get nodes
2NAME      STATUS         AGE
3cent0     Ready,master   1h

mysql的pod #

mysql-rc.yaml

 1apiVersion: v1
 2kind: ReplicationController            
 3metadata:
 4  name: mysql                          
 5spec:
 6  replicas: 1                          
 7  selector:
 8    app: mysql                          
 9  template:
10    metadata:
11      labels:
12        app: mysql                      
13    spec:
14      containers:                       
15      - name: mysql                     
16        image: mysql:5.7                
17        ports:
18        - containerPort: 3306           
19        env:
20        - name: MYSQL_ROOT_PASSWORD
21          value: "123456"
22        - name: MYSQL_DATABASE
23          value: sonardb
24        - name: MYSQL_USER
25          value: sonar
26        - name: MYSQL_PASSWORD
27          value: sonar

创建RC

1kubectl create -f mysql-rc.yaml

查看Pod的状态,确认其处于Running状态。

1kubectl get pods -o wide | grep mysql
2mysql-7wl9d   1/1       Running   0          12m       10.244.0.9   cent0

可以使用kubectl describe pod <pod-name>查看Pod的详细信息,其中在Events中可以看到Pod启动各个步骤相关的信息。

1kubectl describe pod mysql-7wl9d

mysql的svc #

mysql-svc.yaml

1apiVersion: v1
2kind: Service                       
3metadata:
4  name: mysql                       
5spec:
6  ports:
7    - port: 3306
8  selector:
9    app: mysql

创建svc

1kubectl create -f mysql-svc.yaml

确认svc运行状态

1kubectl get svc
2NAME         CLUSTER-IP    EXTERNAL-IP   PORT(S)    AGE
3kubernetes   10.96.0.1     <none>        443/TCP    2h
4mysql        10.98.249.5   <none>        3306/TCP   1m

sonar的pod #

sonar-rc.yml

 1apiVersion: v1
 2kind: ReplicationController
 3metadata:
 4 name: sonar
 5spec:
 6 replicas: 1
 7 selector:
 8   app: sonar
 9 template:
10   metadata:
11     labels:
12       app: sonar
13   spec:
14     containers:
15       - name: sonar
16         image: sonarqube:6.2
17         ports:
18         - containerPort: 9000
19         env:
20         - name: SONARQUBE_JDBC_USERNAME
21           value: sonar
22         - name: SONARQUBE_JDBC_PASSWORD
23           value: sonar
24         - name: SONARQUBE_JDBC_URL
25           value: "jdbc:mysql://mysql:3306/sonardb?useSSL=false&useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance"
1kubectl create -f sonar-rc.yaml

查看Pod的状态,确认其处于Running状态。

1kubectl get pods -o wide | grep sonar
2sonar-5vhw8   1/1       Running   0          44s       10.244.0.10   cent0

sonar的svc #

sonar-svc.yaml

 1apiVersion: v1
 2kind: Service
 3metadata:
 4  name: sonar
 5spec:
 6  type: NodePort
 7  ports:
 8    - port: 9000
 9      nodePort: 30001
10  selector:
11    app: sonar
1kubectl create -f sonar-svc.yaml

查看service状态

1kubectl get svc | grep sonar
2sonar        10.101.73.74   <nodes>       9000:30001/TCP   1m

最后以http://nodeIp:30001在浏览器中打开sonar。

1http://192.168.61.100:30001/
2
3user: admin
4pwd: admin
© 2024 青蛙小白