我有一个有两个副本的 statefulSet。它的无头服务名称是“gov-svc” 它是->
- .metadata.name:sts
- .metadata.namespace:默认
- .spec.serviceName: gov-svc
- .spec.template.spec.subdomain: gov-svc
- .spec.replicas: 2
在运行 statefulSet 之前
kubectl get pods --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system coredns-99b9bb8bd-qdnsb 1/1 Running 0 4h
kube-system etcd-minikube 1/1 Running 0 4h
kube-system kube-addon-manager-minikube 1/1 Running 0 4h
kube-system kube-apiserver-minikube 1/1 Running 0 4h
kube-system kube-controller-manager-minikube 1/1 Running 1 4h
kube-system kube-proxy-b9np6 1/1 Running 0 4h
kube-system kube-scheduler-minikube 1/1 Running 0 4h
kube-system kubernetes-dashboard-7db4dc666b-bsk8k 1/1 Running 0 4h
kube-system storage-provisioner
在从 pod 运行这个 statefulSet 的两个 podsts-0
之后,ping
结果:
$ ping sts-0.gov-svc.default.svc.cluster.local
PING sts-0.gov-svc.default.svc.cluster.local (172.17.0.11): 56 data bytes
64 bytes from 172.17.0.11: seq=0 ttl=64 time=0.051 ms
64 bytes from 172.17.0.11: seq=1 ttl=64 time=0.444 ms
^C
--- redis-cluster-exp-0-0.redis-cluster-exp.default.svc.cluster.local ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 0.051/0.247/0.444 ms
但是当我尝试ping sts-1
from时sts-0
,它说:
$ ping sts-1.gov-svc.default.svc.cluster.local
ping: bad address 'sts-1.gov-svc.default.svc.cluster.local'
我需要通过主机名成功 ping 其他 pod。我该怎么做?