简体   繁体   English

在 Kube.netes 中运行 Mysql 时访问被拒绝

[英]Access denied when running Mysql in Kubernetes

i'm a newbie to Kube.netes.我是 Kube.netes 的新手。 This is my situation:这是我的情况:
I found a open-source project on Github, it is a online bookstore: https://github.com/devdcores/BookStoreApp-Distributed-Application (anyway, thankss to author of this repo).我在 Github 上找到了一个开源项目,它是一个在线书店: https://github.com/devdcores/BookStoreApp-Distributed-Application (无论如何,感谢这个 repo 的作者)。 This project is written in microservice-architecture, it had a docker-compose to build and run container instantly.这个项目是用微服务架构编写的,它有一个 docker-compose 来立即构建和运行容器。 I've try and it worked.我试过了,它奏效了。 But when i try to build and run this project in Kube.netes and Helm, problem raise:但是当我尝试在 Kube.netes 和 Helm 中构建和运行这个项目时,出现了问题:
Some service cannot connect to mysqldb: Access denied for user 'bookstoreDBA'@'172.17.0.1' (using password: YES) .某些服务无法连接到 mysqldb:用户 'bookstoreDBA'@'172.17.0.1' 的访问被拒绝(使用密码:YES) So i look into source code and found this:所以我查看了源代码并发现了这个:

datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://bookstore-mysql-db:3306/bookstore_db?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
    username: bookstoreDBA
    password: PaSSworD

My question is: Is the url set up properly?我的问题是: url是否设置正确? Is it the reason cause problem?这是导致问题的原因吗? If it is (not), then how to fix this problem?如果是(不是),那么如何解决这个问题?
P/S: These are environment variables and service.yaml for mysql container: P/S:这些是 mysql 容器的环境变量和service.yaml

env:
    MYSQL_DATABASE: bookstore_db
    MYSQL_PASSWORD: PaSSworD
    MYSQL_ROOT_PASSWORD: r00tPaSSworD
    MYSQL_USER: bookstoreDBA

# service.yaml
apiVersion: v1
kind: Service
metadata:
  annotations:
    kompose.cmd: kompose convert
    kompose.version: 1.22.0 (955b78124)
  creationTimestamp: null
  labels:
    io.kompose.service: bookstore-mysql-db
  name: bookstore-mysql-db
spec:
  ports:
    - name: "3306"
      port: 3306
      targetPort: 3306
  selector:
    io.kompose.service: bookstore-mysql-db
status:
  loadBalancer: {}

I use mysql client to create bookstoreDBA user and grant needed privileges.我使用mysql 客户端创建bookstoreDBA用户并授予所需的权限。 Then restart the cluster.然后重启集群。 Now every things work properly.现在一切正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM