Sonarqube setup on Kubernetes

Sonarqube setup on Kubernetes

Static code analysis

SonarQube is an open source platform to perform automatic reviews with static analysis of code to detect bugs, code smells and security vulnerabilities on 25+ programming languages including Java, C#, JavaScript, TypeScript, C/C++, COBOL and more.

Let’s setup sonarqube on Kubernetes

Git repo : https://github.com/harsh4870/sonarqube-kubernetes

apiVersion: certmanager.k8s.io/v1alpha1
	kind: ClusterIssuer
	metadata:
	  name: sonarqube
	spec:
	  acme:
	    server: https://acme-v02.api.letsencrypt.org/directory
	    email: [email protected]
	    privateKeySecretRef:
	      name: sonarqube
	    http01: {}
	---
	apiVersion: v1
	kind: Service
	metadata:
	  name: sonarqube-service
	spec:
	  selector:
	    app: sonarqube
	  ports:
	  - protocol: TCP
	    port: 9000
	    targetPort: 9000
	---
	apiVersion: extensions/v1beta1
	kind: Deployment
	metadata:
	  labels:
	    app: sonarqube
	  name: sonarqube
	spec:
	  replicas: 1
	  template:
	    metadata:
	      labels:
	        app: sonarqube
	    spec:
	      containers:
	        - name: sonarqube
	          image: sonarqube:7.1
	          resources:
	            requests:
	              memory: "1200Mi"
	              cpu: .10
	            limits:
	              memory: "2500Mi"
	              cpu: .50
	          volumeMounts:
	          - mountPath: "/opt/sonarqube/data/"
	            name: sonar-data
	          - mountPath: "/opt/sonarqube/extensions/"
	            name: sonar-extensions
	          env:
	          - name: "SONARQUBE_JDBC_USERNAME"
	            value: "root"  #Put your db username
	          - name: "SONARQUBE_JDBC_URL"
	            value: "jdbc:mysql://<My-IP>:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true" #DB URL
	          - name: "SONARQUBE_JDBC_PASSWORD"
	            valueFrom:
	              secretKeyRef:
	                name: sonarqube-mysql-secret
	                key: password
	          ports:
	          - containerPort: 9000
	            protocol: TCP
	      volumes:
	      - name: sonar-data
	        persistentVolumeClaim:
	          claimName: sonar-data
	      - name: sonar-extensions
	        persistentVolumeClaim:
	          claimName: sonar-extensions
	---
	kind: PersistentVolumeClaim
	apiVersion: v1
	metadata:
	  name: sonar-extensions
	spec:
	  accessModes:
	    - ReadWriteOnce
	  resources:
	    requests:
	      storage: 5Gi
	---
	kind: PersistentVolumeClaim
	apiVersion: v1
	metadata:
	  name: sonar-data
	spec:
	  accessModes:
	    - ReadWriteOnce
	  resources:
	    requests:
	      storage: 5Gi
	

	---
	apiVersion: extensions/v1beta1
	kind: Ingress
	metadata:
	  name: sonar-ingress
	  annotations:
	    kubernetes.io/ingress.class: "nginx"
	    certmanager.k8s.io/cluster-issuer: sonarqube
	    nginx.ingress.kubernetes.io/ssl-redirect: "true"
	    nginx.ingress.kubernetes.io/proxy-body-size: "20m"
	spec:
	  tls:
	  - hosts:
	    - sonar.example.com
	    secretName: sonarqube
	  rules:
	  - host: sonar.example.com
	    http:
	      paths:
	      - backend:
	          serviceName: sonarqube-service
	          servicePort: 9000
	---
	apiVersion: v1
	kind: Secret
	metadata:
	  name: sonarqube-mysql-secret
	type: Opaque
	data:
	  password: eHGpMdsnaEsdfNnVNLjKv==

Update YAML file deployment with database URL, Secret and ingress object with the domain.

Apply YAML file configuration to Kubernetes

Kubectl apply -f sonar-kubernetes.yaml



要查看或添加评论,请登录

Harsh Manvar的更多文章

  • API Gateway vs Service Mesh

    API Gateway vs Service Mesh

    Difference between an API gateway & Service Mesh and therefore the role of every in microservices and other…

    1 条评论
  • Cloud custodian on docker container

    Cloud custodian on docker container

    Run cloud custodian policies & c7n mailer on docker container. Why? To provide a standalone containerized runtime for…

  • Slack Post On Kubernetes POD Ready State

    Slack Post On Kubernetes POD Ready State

    Post slack notification when POD status change to READY in any namespace. In market, there are many plugins available…

    4 条评论
  • AWS Auto AMI(Instance) backup across all region

    AWS Auto AMI(Instance) backup across all region

    Simple Easy way AWS auto AMI backup(snapshot + image backup of ec2) across all region or cross region using lambda…

社区洞察

其他会员也浏览了