Exercise 9.3: Working with CoreDNS
CP 노드에 연결된 터미널로 이동
Pod 생성
cat <<EOF | kubectl create -f - apiVersion: v1 kind: Pod metadata: name: net-tools spec: containers: - name: net-tools image: praqma/network-multitool command: [ "sleep" ] args: [ "infinity" ] EOF생성한 Pod에 Bash 실행
kubectl exec -it net-tools -- /bin/bashDNS 서버 정보 확인
dig로컬 DNS 설정 확인
cat /etc/resolv.confDNS 서버 상세 정보 확인
dig @DNS_SERVER -x DNS_SERVEROR
dig @10.96.0.10 -x 10.96.0.10CURL 명령어로 이전 실습에서 생성한 Service의 FQDN로 접근
curl nginx-one.accounting.svc.cluster.localCURL 명령어로 이전 실습에서 생성한 Service의 이름로 접근
curl nginx-oneCURL 명령어로 이전 실습에서 생성한 Service의 이름에 Namespace 이름을 추가하고 접근
curl nginx-one.accountingBash 종료
exitkube-system Namespace 안에 있는 Service 확인
kubectl -n kube-system get svckube-dns Service의 Selector 조건 확인
kubectl -n kube-system get svc kube-dns \ -o=jsonpath='{.spec.selector}' | jqk8s-app Label을 가진 Pod 확인
kubectl get pod -l k8s-app --all-namespacesk8s-app=kube-dns Label을 가진 Pod 확인
kubectl get pod -l k8s-app=kube-dns --all-namespacescoredns Pod 상세 내용 확인
kubectl -n kube-system get pod COREDNS_POD_NAME -o yamlOR
kubectl -n kube-system get pod $(kubectl get pod -l k8s-app=kube-dns -o=jsonpath='{.items[0].metadata.name}' -n kube-system) -o yamlkube-system Namespace 안에 있는 ConfigMap 확인
kubectl -n kube-system get configmapscoredns ConfigMap 상세 내용 확인
kubectl -n kube-system get configmaps coredns -o yamlcoredns ConfigMap을 수정하도록 텍스트 에디터 실행
kubectl -n kube-system edit configmaps coredns아래와 같이 수정
apiVersion: v1 data: Corefile: | .:53 { rewrite name regex (.*)\.douzone\.com {1}.default.svc.cluster.local errors health {18, 19번 단계를 수행하지 않고 아래의 명령어로 대체 가능
cat <<EOF | kubectl apply -f - apiVersion: v1 kind: ConfigMap metadata: name: coredns namespace: kube-system data: Corefile: | .:53 { rewrite name regex (.*)\.douzone\.com {1}.default.svc.cluster.local errors health { lameduck 5s } ready kubernetes cluster.local in-addr.arpa ip6.arpa { pods insecure fallthrough in-addr.arpa ip6.arpa ttl 30 } prometheus :9153 forward . /etc/resolv.conf { max_concurrent 1000 } cache 30 loop reload loadbalance } EOFcoredns Pod 재생성
{ kubectl scale deployment coredns --replicas=0 -n kube-system kubectl scale deployment coredns --replicas=2 -n kube-system }coredns Pod가 재생성 되었는지 확인
kubectl -n kube-system get pod -l k8s-app=kube-dnsNGINX Deployment 생성
kubectl create deployment nginx --image=nginxNGINX Deployment에 Service 생성
kubectl expose deployment nginx --type=ClusterIP --port=80생성된 Service 확인
kubectl get svc nginxnet-tools Pod로 Bash 연결
kubectl exec -it net-tools -- /bin/bash위에서 생성된 Service의 IP 주소로 DNS 주소 검색 (Reverse Lookup)
dig -x SERVICE_CLUSTER_IP위에서 확인한 Service의 DNS 주소로 IP 주소 검색 (Forward Lookup)
dig nginx.default.svc.cluster.localCoreDNS에 추가한 Rewrite 규칙 테스트
dig nginx.joins.comRewrite 규칙에 명시한 도메인 주소로 접근 시도
curl nginx.joins.comBash 프로세스 종료
exitcoredns ConfigMap을 수정하도록 텍스트 에디터 실행
kubectl -n kube-system edit configmaps coredns아래와 같이 수정
apiVersion: v1 data: Corefile: | .:53 { rewrite stop { name regex (.*)\.douzone\.com {1}.default.svc.cluster.local answer name (.*)\.default\.svc\.cluster\.local {1}.douzone.com } errors health {32, 33번 단계를 수행하지 않고 아래의 명령어로 대체 가능
cat <<EOF | kubectl apply -f - apiVersion: v1 kind: ConfigMap metadata: name: coredns namespace: kube-system data: Corefile: | .:53 { rewrite stop { name regex (.*)\.douzone\.com {1}.default.svc.cluster.local answer name (.*)\.default\.svc\.cluster\.local {1}.douzone.com } errors health { lameduck 5s } ready kubernetes cluster.local in-addr.arpa ip6.arpa { pods insecure fallthrough in-addr.arpa ip6.arpa ttl 30 } prometheus :9153 forward . /etc/resolv.conf { max_concurrent 1000 } cache 30 loop reload loadbalance } EOFcoredns Pod 재생성
{ kubectl scale deployment coredns --replicas=0 -n kube-system kubectl scale deployment coredns --replicas=2 -n kube-system }coredns Pod가 재생성 되었는지 확인
kubectl -n kube-system get pod -l k8s-app=kube-dnsnet-tools Pod로 Bash 연결
kubectl exec -it net-tools -- /bin/bashCoreDNS에 추가한 Rewrite 규칙 확인
dig nginx.joins.comCoreDNS에 추가한 Rewrite 규칙 테스트
curl nginx.joins.comBash 프로세스 종료
exitnet-tools Pod 삭제
kubectl delete pod net-tools
Last updated