learning-coredns

created : Wed, 28 Sep 2022 11:30:48 +0900
modified : Wed, 02 Nov 2022 00:19:28 +0900
coredns

공부 이유

공부 방법

1장 소개

2장 DNS 소개

3장 CoreDNS 구성

CoreDNS 커맨드라인 옵션

Corefile 구문

# comment
<label>, <label2> {
  <statement...>
  {$env_var}
}

<snippet_name> {
  <label_name> {
    ...
  }
}

import <snippet_name>
import <config_filename>

# Server Block
foo.example {
}

# Root Server Block
. {
}

# Specific Port
foo.example:1053 {
}

# Protocol prefix
tsl://foo.example {
}

grpc://bar.example {
}

플러그인

DNS 서버 구성 예시

캐싱 전용 DNS 서버

. {
  forward . 8.8.8.8 8.8.4.4
  cache
  errors
  log
}

주 DNS 서버

foo.example {
  root /etc/coredns/zones
  file db.foo.example
  errors
  log
}

. {
  forward 8.8.8.8 8.8.4.4
  cache
  errors
  log
}

보조 DNS 서버

(logerrors) {
  errors
  log
}

bar.exmple {
  transfer from 10.0.0.1
  import logerrors
}

foo.example {
  file db.foo.example
  root /etc/coredns/zones
  import logerrors
}

. {
  forward 8.8.8.8 8.8.4.4
  cache
  impor logerrors
}

4장 영역 데이터 관리

file 플러그인

실습

# Corefile
foo.example {
  file db.foo.example
}
# db.foo.example
@ 3600 IN SOA ns1.foo.example. root.foo.example. (
  2019041900
  3600
  600
  604800
  600 )
  3600 IN NS ns1.foo.example.
  3600 IN NS ns2.foo.example.

ns1 IN A 10.0.0.53
    IN AAAA 2001:db8:42:1::53
ns2 IN A 10.0.1.53
    IN AAAA 2001:db8:42:2::53
www IN A 10.0.0.1
    IN AAAA 2001:db8:42:1:1
coredns # 위 파일들이 있는 디렉토리에서
dig @localhost ns1.foo.example

# 출력
# ; <<>> DiG 9.10.6 <<>> @localhost ns1.foo.example
# ; (2 servers found)
# ;; global options: +cmd
# ;; Got answer:
# ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 36641
# ;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 1
# ;; WARNING: recursion requested but not available
#
# ;; OPT PSEUDOSECTION:
# ; EDNS: version: 0, flags:; udp: 4096
# ;; QUESTION SECTION:
# ;ns1.foo.example.               IN      A
#
# ;; ANSWER SECTION:
# ns1.foo.example.        3600    IN      A       10.0.0.53
#
# ;; AUTHORITY SECTION:
# foo.example.            3600    IN      NS      ns1.foo.example.
# foo.example.            3600    IN      NS      ns2.foo.example.
#
# ;; Query time: 0 msec
# ;; SERVER: ::1#53(::1)
# ;; WHEN: Thu Sep 29 18:21:14 KST 2022
# ;; MSG SIZE  rcvd: 155

auto 플러그인

auto [ZONES...] {
  directory DIR [REGEX ORIGIN_TEMPLATE]
  transfer to ADDRESS...
  reload DURATION
}

Git 과 auto 플러그인 사용

hosts 플러그인

hosts [FILE [ZONES...]] {
  [INLINE]
  ttl SECONDS
  no_reverse
  reload DURATIOn
  fallthrough [ZONES...]
}

AWS Route53 플러그인

route53 [ZONE:HOSTED_ZONE_ID...] {
  [aws_access_key AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY]
  upstream
  credentials PROFILE [FILENAME]
  fallthrough [ZONES...]
}

5장 서비스 검색

서비스 검색 문제 해결

CoreDNS 및 etcd로 서비스 검색

etcd 플러그인

{
  "host": "192.0.2.10",
  "port": 20020,
  "priority": 10,
  "weight": 20
}

6장 쿠버네티스

Plugin 구조 분석

클러스터 DNS 디플로이먼트 리소스

CoreDNS 확장

개인 생각