apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
  name: bcp-mysql
  labels:
    app: bcp-mysql
spec:
  selector:
    matchLabels:
      app: bcp-mysql
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: bcp-mysql
    spec:
      containers:
      - image: karthickas/mysql:5.7
        name: mysql
        env:
          - name: MYSQL_ROOT_PASSWORD
            value: password
          - name: MYSQL_DATABASE
            value: bcp
          - name: MYSQL_USER
            value: root
          - name: MYSQL_PASSWORD
            value: password
        ports:
        - containerPort: 3306
          name: mysql
        imagePullPolicy: Always
        volumeMounts:
        - name: mysql-persistent-storage
          mountPath: /var/lib/mysql
      volumes:
      - name: mysql-persistent-storage
        persistentVolumeClaim:
          claimName: mysql-pv-claim
      imagePullSecrets:
        - name: regcred
---
apiVersion: v1
kind: Service
metadata:
  name: bcp-mysql
spec:
  selector:
    app: bcp-mysql
  ports:
    - port: 3306
      targetPort: 3306
  type: ClusterIP
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysql-pv-claim
  labels:
    app: bcp-mysql
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi