kubernetes - 解析 headless 服务的 IP 地址

标签 kubernetes google-cloud-platform

我创建了一个服务,它分配了 3 个 Pod。

enter image description here

我想通过同一项目中的其他服务通过其主机名访问该服务。我怎样才能做到这一点?

尝试过:

alxtbk@dns-test:~$ ping elassandra-0.elassandra
ping: elassandra-0.elassandra: Name or service not known

alxtbk@dns-test:~$ ping elassandra-0.default.svc.cluster.local
ping: elassandra-0.default.svc.cluster.local: Name or service not known

alxtbk@dns-test:~$ ping elassandra.default.svc.cluster.local
ping: elassandra.default.svc.cluster.local: Name or service not known

解析 headless 服务的IP地址的正确方法是什么?

最佳答案

For such Services, a cluster IP is not allocated, kube-proxy does not handle these services, and there is no load balancing or proxying done by the platform for them. How DNS is automatically configured depends on whether the service has selectors defined.

With selectors

For headless services that define selectors, the endpoints controller creates Endpoints records in the API, and modifies the DNS configuration to return A records (addresses) that point directly to the Pods backing the Service.

Without selectors

For headless services that do not define selectors, the endpoints controller does not create Endpoints records. However, the DNS system looks for and configures either:

CNAME records for ExternalName-type services.

A records for any Endpoints that share a name with the service, for all other types.

所以你也许可以这样做:

kubectl get ep

获取端点,然后在另一个 kubernetes 服务中使用它们。

关于kubernetes - 解析 headless 服务的 IP 地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53122784/

相关文章:

kubernetes - 核心操作系统项目kube-prometheus和prometheus运算符有什么区别?

kubernetes - Minikube服务接入本地VPN

google-cloud-platform - Google Cloud Composer 变量不会传播到 Airflow

firebase - 如何在 Firestore 中存储有关集合的元数据?

node.js - 如何在 Google App Engine 标准环境中使用 Google Cloud Build 或其他方法设置环境变量?

https - 如何在 GCP 中使用 https 访问虚拟机实例

kubernetes 中的 Spring boot (Tomcat) 服务需要使用 FQDN

Kubernetes - 在预安装作业中使用 secret

kubernetes - 如何在 Alpine linux 上使用 azure-cli 创建 dind docker 镜像?

python - 新版python wheel发行后,gcloud应用部署超时