kubernetes - 主机名未在命名空间中注册
问题描述
我已经通过 Rancher 设置了 Kuberbetes 集群。一切看起来都很好,直到我决定将 Helm Chart 应用程序部署到它(bitnami/wordpress)。
命名空间中的 Pod 和服务wordpress
:
> kubectl get pods,svc -owide --namespace=wordpress
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
pod/wordpress-6647794f9b-4mmxd 0/1 Running 20 104m 10.42.0.19 dev-app <none> <none>
pod/wordpress-mariadb-0 1/1 Running 1 26h 10.42.0.14 dev-app <none> <none>
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
service/wordpress LoadBalancer 10.43.91.13 <pending> 80:30158/TCP,443:30453/TCP 26h app.kubernetes.io/instance=wordpress,app.kubernetes.io/name=wordpress,io.cattle.field/appId=wordpress
service/wordpress-mariadb ClusterIP 10.43.178.123 <none> 3306/TCP 26h app=mariadb,component=master,io.cattle.field/appId=wordpress,release=wordpress
然后我尝试验证从 Wordpress CMS 到 MariaDB 的连接:
在 MariaDB pod 上:
I have no name!@wordpress-mariadb-0:/$ cat /etc/hosts
# Kubernetes-managed hosts file.
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
fe00::0 ip6-mcastprefix
fe00::1 ip6-allnodes
fe00::2 ip6-allrouters
10.42.0.14 wordpress-mariadb-0.wordpress-mariadb.wordpress.svc.cluster.local wordpress-mariadb-0
不知道为什么-0
要添加到主机名中,但是
I have no name!@wordpress-mariadb-0:/$ mysql -h wordpress-mariadb-0.wordpress-mariadb.wordpress.svc.cluster.local -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 48253
Server version: 10.3.22-MariaDB Source distribution
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
从 MariaDB pod 可以正常工作。
比在 Wordpress pod 上:
I have no name!@wordpress-6647794f9b-4mmxd:/$ mysql -h wordpress-mariadb-0.wordpress-mariadb.wordpress.svc.cluster.local -u root -p
Enter password:
ERROR 2005 (HY000): Unknown MySQL server host 'wordpress-mariadb-0.wordpress-mariadb.wordpress.svc.cluster.local' (-3)
由于某种原因,主机名没有为该命名空间注册。
有什么线索吗?
附言
从 wordpress 吊舱:
I have no name!@wordpress-6647794f9b-4mmxd:/$ cat /etc/hosts
# Kubernetes-managed hosts file.
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
fe00::0 ip6-mcastprefix
fe00::1 ip6-allnodes
fe00::2 ip6-allrouters
10.42.0.19 wordpress-6647794f9b-4mmxd
# Entries added by HostAliases.
127.0.0.1 status.localhost
和
I have no name!@wordpress-6647794f9b-4mmxd:/$ cat /etc/resolv.conf
nameserver 10.43.0.10
search wordpress.svc.cluster.local svc.cluster.local cluster.local
options ndots:5
PS2
> kubectl get pod -n kube-system
NAME READY STATUS RESTARTS AGE
canal-8bf2l 2/2 Running 0 16d
canal-g782s 2/2 Running 2 16d
canal-vq474 2/2 Running 0 16d
coredns-849545576b-gcf7p 1/1 Running 0 16d
coredns-849545576b-vtqpw 1/1 Running 0 3d20h
coredns-autoscaler-84bf756579-v594n 1/1 Running 0 3d20h
metrics-server-697746ff48-rtw2h 1/1 Running 1 16d
rke-coredns-addon-deploy-job-2sjlv 0/1 Completed 0 3d20h
rke-ingress-controller-deploy-job-9q4c2 0/1 Completed 0 3d20h
rke-metrics-addon-deploy-job-cv42h 0/1 Completed 0 3d20h
rke-network-plugin-deploy-job-4pddn 0/1 Completed 0 3d20h
解决方案
出于某种原因,带有 CoreDNS pod 的节点之一(我有两个)在为服务提供数据时出现问题kube-dns
。
重建该节点解决了我的问题。
推荐阅读
- linux - 使用 ssh 命令行将存储库中的所有文件从一个目录移动到另一个目录
- java - 使用 Apache Jena 和 Blazegraph 作为 TripleStore 加载文件
- python - 如何更改 base.ir.ir_ui_view 字段定义
- selenium - 如何使用 selenium-webdriver 等待新打开的窗口的就绪状态
- class - XSD 无法生成类但适用于类似文件
- performance-testing - 强制复制
- python - 如何直接从 RobotFramework 运行 python 脚本
- scala - Spark:在 s3 上保存和加载机器学习模型
- ios - iTunes 错误:-“文件夹名称 - 无法复制,因为发生错误,指定了重复的文件名”
- c# - 如何将带有参数的 MVC 应用程序基地址路由到控制器