我尝试在Kubernetes上运行所有关于Spring Boot微服务的映像。
当我运行kubectl apply -f k8s
时,
我得到这个问题的订单服务,支付服务,认证服务和最后的产品服务。
这是下面显示的问题。
Caused by: java.sql.SQLException: Access denied for user 'springmicroserviceuser'@'172.17.0.6' (using password: YES)
我如何定义一个命令来创建MySQL部署yaml文件中的用户和密码?
这是下面显示的文件。
# 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;
GRANT ALL PRIVILEGES ON `orderdb`.* TO 'springmicroserviceuser'@'%' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON `paymentdb`.* TO 'springmicroserviceuser'@'%' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON `productdb`.* TO 'springmicroserviceuser'@'%' WITH GRANT OPTION;
这是一个pod的屏幕截图。
以下是回购协议:Link
1条答案
按热度按时间z31licg01#
在docker-mysql终端上使用以下命令为您收到此错误的IP地址创建用户。
有关更多信息,请参阅此SO link1、link2。