I tried to run all images regarding Spring Boot Microservices on Kubernetes.
When I run kubectl apply -f k8s
,
I get this issue for order service, payment service, auth service and lastly product service.
Here is the issue shown below.
Caused by: java.sql.SQLException: Access denied for user 'springmicroserviceuser'@'172.17.0.6' (using password: YES)
How can I define a command to create user and password in MySQL deployment yaml file.
Here is the file shown below.
# Persistent Volume
apiVersion: v1
kind: PersistentVolume
metadata:
name: mysql-pv
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
storageClassName: manual
hostPath:
# path: "/mnt/data" # - for Unix/Linux
path: "/run/desktop/mnt/host/c/temp/testfiles"
type: DirectoryOrCreate
---
# Persistent Volume Claim
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mysql-pvc
spec:
resources:
requests:
storage: 1Gi
storageClassName: manual
accessModes:
- ReadWriteOnce
# StatefulSet - MySql
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: mysql
spec:
selector:
matchLabels:
app: mysql
serviceName: mysql
replicas: 1
template:
metadata:
labels:
app: mysql
spec:
containers:
- name: mysql
image: mysql:8.0
env:
- name: MYSQL_ROOT_PASSWORD
value: ippavlova_1990
ports:
- containerPort: 3306
name: mysql
volumeMounts:
- name: mysql-initdb
mountPath: /docker-entrypoint-initdb.d
- name: mysql-persistent-storage
mountPath: /var/lib/mysql
volumes:
- name: mysql-initdb
configMap:
name: mysql-initdb-cm
- name: mysql-persistent-storage
persistentVolumeClaim:
claimName: mysql-pvc
# Headless Service
---
apiVersion: v1
kind: Service
metadata:
name: mysql
spec:
clusterIP: None
selector:
app: mysql
ports:
- port: 3306
# Config
---
apiVersion: v1
kind: ConfigMap
metadata:
name: mysql-initdb-cm
data:
init.sql: |
CREATE USER 'springmicroserviceuser'@'localhost' IDENTIFIED BY '111111';
CREATE DATABASE IF NOT EXISTS orderdb;
CREATE DATABASE IF NOT EXISTS paymentdb;
CREATE DATABASE IF NOT EXISTS productdb;
Here is the screenshot of one pod.
Here is the repo : Link
How can I fix it?