apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mysql
  template:
    metadata:
      labels:
        app: mysql
    spec:
      nodeSelector:
        kubernetes.io/hostname: server-3
      tolerations:
        - key: "node"
          operator: "Equal"
          value: "special"
          effect: "NoSchedule"
        - key: node-role.kubernetes.io/master
          operator: Equal
          value: ""
          effect: NoSchedule
        - key: node-role.kubernetes.io/control-plane
          operator: Equal
          value: ""
          effect: NoSchedule
      containers:
        - name: mysql
          image: mirror.gcr.io/mysql:8.2
          ports:
            - containerPort: 3306
          env:
            - name: TZ
              value: "Australia/Melbourne"
            - name: MYSQL_DATABASE
              value: home
            - name: MYSQL_USER
              value: junv
            - name: MYSQL_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: mysql-password-junv
                  key: password
            - name: MYSQL_ROOT_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: mysql-root-password
                  key: password
          volumeMounts:
            - name: data
              mountPath: "/var/lib/mysql"
          resources:
            limits:
              cpu: "1"
              memory: "1Gi"
            requests:
              cpu: "400m"
              memory: "256Mi"
          securityContext:
            privileged: false
            runAsGroup: 1000
            # fsGroup: 1000
            runAsUser: 1000
      volumes:
        - name: data
          persistentVolumeClaim:
            claimName: mysql-local-pvc

---
apiVersion: v1
kind: Service
metadata:
  name: mysql-adguard
  namespace: db
  annotations:
    metallb.universe.tf/loadBalancerIPs: 192.168.1.201
spec:
  selector:
    app: mysql
  ports:
    - protocol: TCP
      port: 3306
      targetPort: 3306
  type: LoadBalancer
  externalIPs:
    - 192.168.1.201

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