简体   繁体   English

如何将kubernetes pod的主机名设置为其IP地址?

[英]How to set a kubernetes pod's hostname to its IP address?

So I have a deployment which creates N number of worker pods, and a service which internally balanced traffic to them. 因此,我有一个部署,该部署创建了N个工作人员Pod,并且提供了一种在内部平衡流量的服务。 I access the service from a VM. 我从VM访问服务。 The VM makes a request, and the pod responds with its hostname so that the VM can make a direct connection to it (this is used for pulling the results back from the pod that actually did the work). VM发出请求,然后Pod用其主机名进行响应,以便VM可以与其直接建立连接(用于将结果从实际完成工作的Pod中拉回)。

The problem that I'm having is that my pod is returning a hostname of my-pod-5ff75ddd86-2xdjq which the VM cannot resolve. 我遇到的问题是,我的Pod返回的主机名是my-pod-5ff75ddd86-2xdjq,VM无法解析该主机名。 I'm wondering if it's possible to set the hostname of the pod to its IP, as this would mean I don't have to change any code in my pod, or the tool running in my VM. 我想知道是否可以将Pod的主机名设置为其IP,因为这意味着我不必更改Pod或VM中运行的工具的任何代码。

In case you don't want to change your code you need to expose the internal kube-dns of your cluster and make it the default DNS server of your VM. 如果您不想更改代码,则需要公开群集的内部kube-dns ,并将其设置为VM的默认DNS服务器。

On that another question have some info 关于另一个问题有一些信息

How to expose kube-dns service for queries outside cluster? 如何为集群外的查询公开kube-dns服务?

On the nginx-controller documentation you have a good example of exposing the 53 port on UDP 在nginx-controller文档上,您有一个很好的示例,公开了UDP上的53端口

https://kubernetes.github.io/ingress-nginx/user-guide/exposing-tcp-udp-services/ https://kubernetes.github.io/ingress-nginx/user-guide/exposing-tcp-udp-services/

By having a nginx-controller up and running you have to create an ingress correctlly to be used by this controller and simply add this configMap : 通过启动并运行nginx-controller,您必须正确创建一个供该控制器使用的入口,并只需添加以下configMap

apiVersion: v1
kind: ConfigMap
metadata:
  name: udp-services
  namespace: ingress-nginx
data:
  53: "kube-system/kube-dns:53"

Depending on your cluster setup, your VM probably wont be able to connect to the pod either even with its IP. 根据您的群集设置,您的VM可能甚至无法使用其IP连接到Pod。 By default, pod IPs are on an overlay network that is only accessible form inside the cluster. 默认情况下,pod IP位于覆盖网络上,该网络只能通过集群内部的形式访问。

If the VM is in the cluster, are you sure you're referencing the pods hostname correctly against kube DNS? 如果VM在群集中,您确定针对kube DNS正确引用了pods主机名吗? Here are the docs on DNS for pods . 这是有关Pod的DNS的文档

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

相关问题 Kubernetes:如何将 static IP 地址或主机名分配给节点和 POD - Kubernetes : How to assign static IP address or HostName to node and POD 是否可以通过反向 dns 查询 POD IP 地址来获取其用于 Kubernetes 部署的主机名? - Is it possible to Reverse-dns query for a POD IP address to get its hostname for a Kubernetes Deployment? 如何从 IP 地址获取 Kubernetes pod 的名称? - How do you get a Kubernetes pod's name from its IP address? 如何在 statefulset 中为 kubernetes pod 设置主机名 - How to set hostname for kubernetes pod in statefulset Kubernetes:如何配置hostnetwork pod IP 地址? - Kubernetes: How to configure hostnetwork pod IP address? 如何使用服务 IP 地址在 Kubernetes 代替 POD IP 地址 - how to use service IP address at Kubernetes instead of POD IP address kubernetes中'k8s-master'的主机名和IP地址修改 - Hostname and IP address modification of 'k8s-master' in kubernetes 如何在kubernetes上获取所有Pod的IP - How to get all Pod's IP on a kubernetes 如何将流量从主机名重定向到 Kubernetes (AKS) 中的自定义 IP 地址? - How to redirect traffic from hostname to a custom IP address in Kubernetes (AKS)? 如何通过查询DNS srv记录获取kubernetes pod的IP地址? - How to obtain Ip address of a kubernetes pod by querying DNS srv records?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM