apiVersion: v1
kind: PersistentVolume
metadata:
  name: sonar-pv
spec:
  storageClassName: ""
  capacity:
    storage: 2Gi
  accessModes:
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Retain
  mountOptions:
    - hard
    - nfsvers=4.1
  nfs:
    server: 192.168.2.110
    path: /mnt/nfs_share/sonar
    readOnly: false
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: sonar-pvc
  namespace: sonarqube
spec:
  storageClassName: ""
  volumeName: sonar-pv
  accessModes:
    - ReadWriteMany
  volumeMode: Filesystem
  resources:
    requests:
      storage: 2Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: sonarqube
  namespace: sonarqube
  labels:
    app: sonarqube
spec:
  replicas: 1
  selector:
    matchLabels:
      app: sonarqube
  template:
    metadata:
      labels:
        app: sonarqube
    spec:
      containers:
      - name: sonarqube
        image: sonarqube
        ports:
        - name: sonarqube
          containerPort: 9000
        env:
        - name: SONAR_JDBC_URL
          value: jdbc:postgresql://postgres14.postgres:5432/sonar
        - name: SONAR_JDBC_USERNAME
          value: sonar
        - name: SONAR_JDBC_PASSWORD
          value: sonar
        volumeMounts:
         - name: sonarqube
           mountPath: /opt/sonarqube/extensions
           subPath: sonarqube-extensions
         - name: sonarqube
           mountPath: /opt/sonarqube/data
           subPath: sonarqube-data
      volumes:
      - name: sonarqube
        persistentVolumeClaim:
          claimName: sonar-pvc
      - name: sonarqube-data
        persistentVolumeClaim:
          claimName: sonar-pvc
---
apiVersion: v1
kind: Service
metadata:
  name: sonarqube
  namespace: sonarqube
  labels:
    name: sonarqube
spec:
  type: ClusterIP
  selector:
    app: sonarqube
  ports:
  - port: 9000
    name: sonarqube
---
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
  name: sonarqube-http
  namespace: sonarqube
spec:
  entryPoints:
    - web
  routes:
  - match: Host(`sonarqube-dev.allarddcs.nl`)
    kind: Rule
    services:
    - name: sonarqube
      port: 9000
---
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
  name: sonarqube-tls
  namespace: sonarqube
spec:
  entryPoints:
    - websecure
  routes:
  - match: Host(`sonarqube-dev.allarddcs.nl`)
    kind: Rule
    services:
    - name: sonarqube
      port: 9000
  tls:
    certResolver: letsencrypt
