简体   繁体   English

kubernetes与Docker DNS配置

[英]kubernetes vs Docker DNS configuration

Using Docker on Mac, I am trying to port docker run parameters to kubernetes yaml configuration, today we are running a container with following DNS flags: 在Mac上使用Docker,我试图将docker run参数移植到kubernetes yaml配置中,今天我们正在运行带有以下DNS标志的容器:

--dns="8.8.8.8" --dns="8.8.4.4" --dns =“ 8.8.8.8” --dns =“ 8.8.4.4”

when I do docker inspect on this container I see: 当我在此容器上进行Docker检查时,我看到:

"Dns": [
        "8.8.8.8",
        "8.8.4.4"
       ]

After reading the Kubernetes docs, I configured the pod yaml like this: 阅读Kubernetes文档之后,我像这样配置了pod yaml:

  dnsPolicy: "None"
  dnsConfig:
    nameservers:
      - 8.8.8.8
      - 8.8.4.4

But when I do docker inspect on the container that Kubernetes launched I see 但是当我在Docker上检查Kubernetes启动的容器时,我看到了

 "Dns": null 

Is that expected? 那是预期的吗? is the configuration correct? 配置正确吗? maybe Kubernetes networking bypasses the container configurations so the container is not aware... I simply don't know. 也许Kubernetes网络绕过了容器配置,所以容器不知道...我只是不知道。

As fiunchinho clarified the behavior is correct. 正如fiunchinho所阐明的,这种行为是正确的。 Configuring Pod DNS policy will have impact on the container, but you won't be able to see that through docker commands, like in few other cases. 配置Pod DNS策略将对容器产生影响,但是您将无法像其他少数情况一样通过docker命令看到该消息。 This is because docker and Kubernetes operate on different layers of the stack. 这是因为Docker和Kubernetes在堆栈的不同层上运行。

So adding the DNS parameter to docker run will result in writing them in /etc/resolv.conf and the same thing happens with adding dnsConfig although in the last example Docker will not be aware of it. 因此,将DNS参数添加到docker run中将导致将它们写入/etc/resolv.conf并且添加dnsConfig发生相同的事情,尽管在最后一个示例中Docker不会意识到这一点。 So answering the question, yes this is expected behavior. 因此,回答问题,是的,这是预期的行为。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM