# fake-dns — "폐쇄망 밖 외부 DNS"의 모사(50-dns-resolution/10-lab-dns.yaml 패턴 정본 재사용). # # 설계 핵심(dns-lab에서 실측 검증된 3가지 그대로): # 1) *.lab.external 3개 hostname만 authoritative(hosts 플러그인, ttl 5s)로 응답하고, # 나머지(istiod.istio-system.svc 등)는 cluster DNS로 forward 한다. # → 그래야 이 DNS를 바라보는 pod의 sidecar가 xDS 대상(istiod)을 계속 resolve할 수 있다. # 2) 레코드 변경 = shared emptyDir(/hosts/addn) 재작성. reload 2s가 자동 재적재. # ⚠ 반드시 "전체 줄을 한 번에" 재작성할 것 — 한 호스트만 쓰면 나머지 줄이 소실된다. # 3) CoreDNS 이미지는 distroless(shell 없음) → busybox writer 사이드카가 파일 기록 통로. # Corefile 자체(이 ConfigMap)를 바꾸면 rollout restart 필요(hosts 파일과 달리 자동 재적재 안 됨). # # 호스트 3개의 역할: # api.lab.external — egress 대상(ServiceEntry 등록됨) → ext-a pod IP # blocked.lab.external — REGISTRY_ONLY 차단 검증용(DNS는 되지만 SE 없음) → ext-b pod IP # (뒤에 살아있는 서버를 둬서, 실패 원인이 "sidecar 정책" 하나로 고립되게) # www.lab.external — ingress 진입 호스트(외부 사용자가 보는 이름) → ingressgateway Service IP # # __CLUSTER_DNS__ 는 apply 전에 sed로 클러스터 DNS ClusterIP로 치환한다(README ③단계): # kubectl -n kube-system get svc coredns -o jsonpath='{.spec.clusterIP}' # 없으면 kube-dns --- apiVersion: v1 kind: ConfigMap metadata: name: fake-dns-corefile namespace: lab-ext data: Corefile: | .:53 { errors log hosts /hosts/addn api.lab.external blocked.lab.external www.lab.external { ttl 5 reload 2s fallthrough } forward . __CLUSTER_DNS__ cache 5 } --- apiVersion: apps/v1 kind: Deployment metadata: name: fake-dns namespace: lab-ext labels: { app: fake-dns } spec: replicas: 1 selector: matchLabels: { app: fake-dns } template: metadata: labels: { app: fake-dns } spec: containers: - name: coredns # 이미지 참조는 전부 fully-qualified — 폐쇄망 미러(Harbor proxy-cache 등)로 옮길 때 # apply 전 sed로 image: 앞에 사내 레지스트리를 일괄 prepend 할 수 있게 하기 위함(README 참조). image: registry.k8s.io/coredns/coredns:v1.11.3 args: ["-conf", "/etc/coredns/Corefile"] ports: - { containerPort: 53, protocol: UDP } - { containerPort: 53, protocol: TCP } volumeMounts: - { name: corefile, mountPath: /etc/coredns } - { name: hosts, mountPath: /hosts } readinessProbe: tcpSocket: { port: 53 } initialDelaySeconds: 2 - name: writer image: docker.io/library/busybox:1.36 command: ["sh", "-c", "touch /hosts/addn; while true; do sleep 3600; done"] volumeMounts: - { name: hosts, mountPath: /hosts } volumes: - name: corefile configMap: { name: fake-dns-corefile } - name: hosts emptyDir: {} --- apiVersion: v1 kind: Service metadata: name: fake-dns namespace: lab-ext spec: selector: { app: fake-dns } ports: - { name: dns-udp, port: 53, protocol: UDP, targetPort: 53 } - { name: dns-tcp, port: 53, protocol: TCP, targetPort: 53 }