LoginSignup
13
18

More than 5 years have passed since last update.

KubernetesのCoreDNSはホストの/etc/hostsを使ってくれないのでConfigMapにレコードを追加する

Last updated at Posted at 2019-03-16

経緯

kubeadmでK8s環境を作っていて気付いたのですが、最近採用されているCoreDNSはホストの/etc/hostsを使ってくれません。すると何が困るかというと、例えばmetrics-serverのようにノードのメトリクスを取得するPodはノード名に対して接続をしようとするので、ノード名がDNSにないと名前解決ができません。

対処

CoreDNSのConfigMapにhostsエントリを追加してレコードを記述します。

$ kubectl edit cm coredns -n kube-system

# Please edit the object below. Lines beginning with a '#' will be ignored,
# and an empty file will abort the edit. If an error occurs while saving this file will be
# reopened with the relevant failures.
#
apiVersion: v1
data:
  Corefile: |
    .:53 {
        errors
        health
        # 以下追加
        hosts {
           192.168.11.nn xxx
           192.168.11.nn yyy
           192.168.11.nn xxx
           fallthrough
        }
        # ここまで
        kubernetes cluster.local in-addr.arpa ip6.arpa {
           pods insecure
           upstream
           fallthrough in-addr.arpa ip6.arpa
        }
        prometheus :9153
        proxy . /etc/resolv.conf
        cache 30
        loop
        reload
        loadbalance
    }
kind: ConfigMap
metadata:
  name: coredns
  namespace: kube-system
  (略)

するとhostsに記述したレコードで名前解決できるようになります。CoreDNSのPodが設定をリロードするまで少し待つ必要があります。

以上です。

13
18
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
18