简体   繁体   English

如何将流量从主机名重定向到 Kubernetes (AKS) 中的自定义 IP 地址?

[英]How to redirect traffic from hostname to a custom IP address in Kubernetes (AKS)?

I'm following this tutorial: https://kubernetes.io/docs/concepts/services-networking/add-entries-to-pod-etc-hosts-with-host-aliases/我正在关注本教程: https://kubernetes.io/docs/concepts/services-networking/add-entries-to-pod-etc-hosts-with-host-aliases/

But it seems not to be working even though when I run cat /etc/hosts inside the pod I can see my hostname there.但它似乎不起作用,即使当我在 pod 内运行 cat /etc/hosts 时,我可以在那里看到我的主机名。 Is there any other way of achieving this?有没有其他方法可以实现这一目标? I also tried with kube-dns, but that will just redirect the traffic to custom DNS server IP rather than normal server IP?我也尝试使用 kube-dns,但这只会将流量重定向到自定义 DNS 服务器 IP 而不是普通服务器 IP?

I have a service with a single pod where I would like to rewire one hostname to go to a custom IP address for testing purposes.我有一个带有单个 pod 的服务,我想将一个主机名重新连接到 go 到自定义 IP 地址以进行测试。

nslookup gives: nslookup 给出:

root@manager-admin-5944869775-x59n5:/app# nslookup xxxxx.azure-devices.net
Server:         10.0.0.10
Address:        10.0.0.10#53

Non-authoritative answer:
xxxxx.azure-devices.net        canonical name = ihsu-prod-bl-004.cloudapp.net.
Name:   ihsu-prod-bl-004.cloudapp.net
Address: 137.117.83.38

While hosts are:虽然主机是:

root@manager-admin-5944869775-x59n5:/app# 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.244.2.104    manager-admin-5944869775-x59n5
40.84.159.16 xxxxx.azure-devices.net

Any ideas or help?有什么想法或帮助吗?

That should work...Anyway its not a best practice as you probably know...那应该可行...无论如何,您可能知道这不是最佳实践...

Anyway, try first if you have connectivity to the IP "telnet 40.84.159.16 80" (You will have to install telnet if you don't have it, and if 80 is the port you want call).无论如何,如果您连接到 IP “telnet 40.84.159.16 80”,请先尝试(如果没有,则必须安装 telnet,如果 80 是您要调用的端口)。 It could be for example a firewall issue on the outbound connectivity of the cluster or the incoming connections from your service you are trying to connect.例如,可能是集群的出站连接或您尝试连接的服务的传入连接的防火墙问题。

However if you can't...Try to use core-dns as you mentioned with the Host Plugin.但是,如果您不能...尝试使用您在主机插件中提到的core-dns

And as a last resort you can specify on a Pod a DNS nameserver which modifies the /etc/resolv.conf file of the pod (You ccould do that with CoreDNS too).作为最后的手段,您可以在 Pod 上指定一个 DNS 名称服务器,该名称服务器会修改 pod 的 /etc/resolv.conf 文件(您也可以使用 CoreDNS 执行此操作)。

Of course this last approach relies you can modify your DNS entries, and that you will not have any DNS conflict, which most sure will appear...当然,最后一种方法依赖于您可以修改您的 DNS 条目,并且您不会有任何 DNS 冲突,这肯定会出现......

apiVersion: v1
kind: Pod
metadata:
  namespace: default
  name: dns-example
spec:
  containers:
    - name: test
      image: nginx
  dnsPolicy: "None"
  dnsConfig:
    nameservers:
      - 1.2.3.4
    searches:
      - ns1.svc.cluster-domain.example
      - my.dns.search.suffix
    options:
      - name: ndots
        value: "2"
      - name: edns0

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

相关问题 如何为 AKS 中的出口流量保留 pod IP 地址? - How to preserve pod IP address for egress traffic in AKS? 如何减少 Azure AKS IP 地址占用? - How to reduce Azure AKS IP address hogging? 如何将Azure终结点(DNS /静态IP)上托管的流量重定向到其他外部IP地址 - How to redirect traffic hosted on an azure endpoint (DNS/static IP) to different external IP address 用自定义名称替换 kubernetes 中的 ip 地址 - Replacing ip address in kubernetes with custom name Azure AKS静态IP地址 - Azure AKS static IP Address Kubernetes - 服务类型 LoadBalancer 每次在 AKS 中部署时使用特定的 ip 地址 - Kubernetes - service type LoadBalancer to use specific ip address every time deployed in AKS 如何将自定义域名应用到 azure kubernetes 服务(AKS)集群? - How to apply custom domain name to azure kubernetes services (AKS) cluster? 如何将流量从我的Azure应用服务路由到特定的外部IP地址 - How to route traffic from my Azure App Service to specific external IP address 如何获取Azure IoT中心的IP地址而不是主机名 - How to get IP address of azure IoT hub instead of hostname Azure AKS IP 地址到白名单图像注册表 - Azure AKS IP address to whitelist Image Registry
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM