avoidik / homework_k8s_sonarqube

Sample SonarQube deployment with MySQL backend on Minikube

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

K8s

SonarQube + MySQL

In this exercise we will install SonarQube with MySQL on a local Kubernetes cluster atop Minikube

Please keep in mind, SonarQube 7.9 and above does not support MySQL backend! Therefore, the latest version of SonarQube supported MySQL backend is 7.8. Check feature/postgresql branch if you wanted to use latest version of SonarQube.

Tiller is obsolete in Helm 3, hence not presented in this exercise.

The deployment process is as follows

  1. Run Minikube cluster
  2. Configure Helm
  3. Deploy MySQL chart into a separate namespace with data persistance
  4. Deploy SonarQube chart into a separate namespace with data persistance
  5. Configure Ingress for both MySQL and SonarQube

On a first try the deployment process may take up to 5 minutes (e.g. images downloading).

Prerequisites

Minikube

Start Minikube cluster

./minikube.sh

Terminate Minikube cluster

./minikube.sh --destroy

Optionally you may change Minikube's profile inside .env file

Terraform

Initiate deployment

./terraform.sh --auto

Terminate deployment

./terraform.sh --auto --destroy

The --auto flag is optional

Shell scripts

Initiate deployment

./helm.mysql.sh
./helm.sonarqube.sh

Terminate deployment

./helm.sonarqube.sh --destroy
./helm.mysql.sh --destroy

Accessing services

Additional changes might be required to expose service ports through Minikube, and access SonarQube or MySQL from your local machine.

At your convenience there are three options available:

  1. With Shell automation - applied automatically
  2. With Terraform automation - use terraform.svc.mysql.sh
  3. Manually, check steps below

Ingress as Minikube addon

# enable addon
minikube addons enable ingress

# patch up ports
kubectl patch configmap tcp-services \
  -n kube-system \
  -p '{"data":{"3306":"mysql/mysql:3306"}}'

kubectl patch deployment nginx-ingress-controller \
  -n kube-system \
  -p '{"spec":{"template":{"spec":{"containers":[{"name":"nginx-ingress-controller","ports":[{"containerPort":3306,"protocol":"TCP","hostPort":3306}]}]}}}}'

# OR

kubectl patch deployment nginx-ingress-controller \
  -n kube-system \
  --type='json' \
  -p='[{"op": "add", "path": "/spec/template/spec/containers/0/ports/-", "value": {"containerPort": 3306, "protocol": "TCP", "hostPort": 3306}}]'

Ingress as not an Minikube addon

# disable addon
minikube addons disable ingress

# install ingress-nginx
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/mandatory.yaml
kubectl get deploy nginx-ingress-controller -n ingress-nginx

# patch up ports
kubectl patch deployment nginx-ingress-controller \
  -n ingress-nginx \
  -p '{"spec":{"template":{"spec":{"hostNetwork":true}}}}'

kubectl patch configmap tcp-services \
  -n ingress-nginx \
  -p '{"data":{"3306":"mysql/mysql:3306"}}'

kubectl get configmap tcp-services \
  -n ingress-nginx -o yaml

URL

After successfull deployment you will be able to access SonarQube at:

echo "http://$(minikube ip):9000"

You may use standard admin/admin credentials to login.

HeidiSQL

You may use free HeidiSQL to connect to PostgreSQL database. Just import preconfigured profile from heidisql/minikube-mysql.txt

Please support HeidiSQL author with the donation

Copyright

You may use my work or its parts as you wish, but only with the proper credits to me like this:

Viacheslav - avoidik@gmail.com

About

Sample SonarQube deployment with MySQL backend on Minikube


Languages

Language:Shell 86.8%Language:HCL 13.2%