mysql - 如何查询mysql Kubernetes pod?用户 'root' 的访问被拒绝 @'localhost'

标签 mysql kubernetes

我部署了 wordpress 和 mysql,一切正常,我只是想知道如何从命令行访问我的 mysql

My services
wordpress           LoadBalancer   10.102.29.45     <pending>     80:31262/TCP     39m
wordpress-mysql     ClusterIP      None             <none>        3306/TCP         42m

描述 Pod

kubectl describe pod wordpress-mysql-5fc97c66f7-jx42l
Name:               wordpress-mysql-5fc97c66f7-jx42l
Namespace:          default
Priority:           0
PriorityClassName:  <none>
Node:               minikube/10.0.2.15
Start Time:         Mon, 11 Mar 2019 08:49:19 +0100
Labels:             app=wordpress
                    pod-template-hash=5fc97c66f7
                    tier=mysql
Annotations:        <none>
Status:             Running
IP:                 172.17.0.15
Controlled By:      ReplicaSet/wordpress-mysql-5fc97c66f7
Containers:
  mysql:
    Container ID:   docker://dcfe9037ab14c3615aec4000f89f28992c52c40a03581215d921564e5b3bec58
    Image:          mysql:5.6
    Image ID:       docker-pullable://mysql@sha256:36cad5daaae69fbcc15dd33b9f25f35c41bbe7e06cb7df5e14d8b966fb26c1b4
    Port:           3306/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Mon, 11 Mar 2019 08:50:33 +0100
    Ready:          True

与 docker 有什么类比吗? 如何查询mysql?

如果我尝试使用 exec

kubectl exec -it wordpress-mysql-5fc97c66f7-jx42l -- /bin/bash
root@wordpress-mysql-5fc97c66f7-jx42l:/# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

最佳答案

要解决此问题,您必须为 MySQL 用户设置密码。

据官方documentation ,您需要创建一个包含您的密码的 Secret 对象:

kubectl create secret generic mysql-pass --from-literal=password=YOUR_PASSWORD

并使用以下部分更新您的部署规范:

env:
  - name: MYSQL_ROOT_PASSWORD
    valueFrom:
      secretKeyRef:
        name: mysql-pass
        key: password

关于mysql - 如何查询mysql Kubernetes pod?用户 'root' 的访问被拒绝 @'localhost',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55098269/

相关文章:

python - 将 Django 连接到本地网络上的远程 mysql 服务器

php - 使用 PHP 访问 MySQL DB 行数据

php - 在文本框中从数据库中搜索数据以显示 - Laravel

kubernetes - kubeadm 创建的集群的 kube-controller-manager 和 kube-apiserver 问题

kubernetes - 在高内存/CPU负载下确保Kubernetes的可用性?

当我尝试创建表时出现 Mysql 1064(4200) 错误

MySQL - 按计数案例分组

nginx - 如何自定义通过 nginx 入口 Controller 的默认后端提供的错误页面?

kubernetes - 现有的Kubernetes集群可以转换为openshift集群吗?

docker - ASP.NET Core 2.0 在 Kubernetes 中启动 Kestrel 时出错