在Kubernetes上运行SonarQube

2017-01-17 阅读: Kubernetes SonarQube

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

准备

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

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

mysql的pod

mysql-rc.yaml

apiVersion: v1
kind: ReplicationController            
metadata:
  name: mysql                          
spec:
  replicas: 1                          
  selector:
    app: mysql                          
  template:
    metadata:
      labels:
        app: mysql                      
    spec:
      containers:                       
      - name: mysql                     
        image: mysql:5.7                
        ports:
        - containerPort: 3306           
        env:
        - name: MYSQL_ROOT_PASSWORD
          value: "123456"
        - name: MYSQL_DATABASE
          value: sonardb
        - name: MYSQL_USER
          value: sonar
        - name: MYSQL_PASSWORD
          value: sonar

创建RC

kubectl create -f mysql-rc.yaml

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

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

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

kubectl describe pod mysql-7wl9d

mysql的svc

mysql-svc.yaml

apiVersion: v1
kind: Service                       
metadata:
  name: mysql                       
spec:
  ports:
    - port: 3306
  selector:
    app: mysql

创建svc

kubectl create -f mysql-svc.yaml

确认svc运行状态

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

sonar的pod

sonar-rc.yml

apiVersion: v1
kind: ReplicationController
metadata:
 name: sonar
spec:
 replicas: 1
 selector:
   app: sonar
 template:
   metadata:
     labels:
       app: sonar
   spec:
     containers:
       - name: sonar
         image: sonarqube:6.2
         ports:
         - containerPort: 9000
         env:
         - name: SONARQUBE_JDBC_USERNAME
           value: sonar
         - name: SONARQUBE_JDBC_PASSWORD
           value: sonar
         - name: SONARQUBE_JDBC_URL
           value: "jdbc:mysql://mysql:3306/sonardb?useSSL=false&useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance"
kubectl create -f sonar-rc.yaml

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

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

sonar的svc

sonar-svc.yaml

apiVersion: v1
kind: Service
metadata:
  name: sonar
spec:
  type: NodePort
  ports:
    - port: 9000
      nodePort: 30001
  selector:
    app: sonar
kubectl create -f sonar-svc.yaml

查看service状态

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

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

http://192.168.61.100:30001/

user: admin
pwd: admin
标题:在Kubernetes上运行SonarQube
本文链接:https://blog.frognew.com/2017/01/sonarqube-mysql-on-kubernetes.html
转载请注明出处。

目录