Kubernetes的 Spring 云-由以下原因引起:java.sql.SQLException:由于用户问题(Mysql部署yaml文件),访问被拒绝

utugiqy6  于 2023-02-07  发布在  Mysql
关注(0)|答案(1)|浏览(114)

我尝试在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

z31licg0

z31licg01#

在docker-mysql终端上使用以下命令为您收到此错误的IP地址创建用户。

CREATE USER 'springmicroserviceuser'@'172.17.0.6' IDENTIFIED BY 'root';

GRANT ALL PRIVILEGES ON *.* TO 'root'@'172.23.0.6' WITH GRANT OPTION;

docker exec -it a5572eb07b8fe8e216d9addc63c1b8f50473638393c39d79e44e2ca7ffd6781e mysql -uroot -p (to get the docker-mysql terminal)[![This picture is for docker-mysql CLI][1]][1]
flush privileges;

有关更多信息,请参阅此SO link1link2

相关问题