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/bash
DNS 서버 정보 확인
dig
로컬 DNS 설정 확인
cat /etc/resolv.conf
DNS 서버 상세 정보 확인
dig @DNS_SERVER -x DNS_SERVER
OR
dig @10.96.0.10 -x 10.96.0.10
CURL 명령어로 이전 실습에서 생성한 Service의 FQDN로 접근
curl nginx-one.accounting.svc.cluster.local
CURL 명령어로 이전 실습에서 생성한 Service의 이름로 접근
curl nginx-one
CURL 명령어로 이전 실습에서 생성한 Service의 이름에 Namespace 이름을 추가하고 접근
curl nginx-one.accounting
Bash 종료
exit
kube-system Namespace 안에 있는 Service 확인
kubectl -n kube-system get svc
kube-dns Service의 Selector 조건 확인
kubectl -n kube-system get svc kube-dns \ -o=jsonpath='{.spec.selector}' | jq
k8s-app Label을 가진 Pod 확인
kubectl get pod -l k8s-app --all-namespaces
k8s-app=kube-dns Label을 가진 Pod 확인
kubectl get pod -l k8s-app=kube-dns --all-namespaces
coredns Pod 상세 내용 확인
kubectl -n kube-system get pod COREDNS_POD_NAME -o yaml
OR
kubectl -n kube-system get pod $(kubectl get pod -l k8s-app=kube-dns -o=jsonpath='{.items[0].metadata.name}' -n kube-system) -o yaml
kube-system Namespace 안에 있는 ConfigMap 확인
kubectl -n kube-system get configmaps
coredns ConfigMap 상세 내용 확인
kubectl -n kube-system get configmaps coredns -o yaml
coredns 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 } EOF
coredns 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-dns
NGINX Deployment 생성
kubectl create deployment nginx --image=nginx
NGINX Deployment에 Service 생성
kubectl expose deployment nginx --type=ClusterIP --port=80
생성된 Service 확인
kubectl get svc nginx
net-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.local
CoreDNS에 추가한 Rewrite 규칙 테스트
dig nginx.joins.com
Rewrite 규칙에 명시한 도메인 주소로 접근 시도
curl nginx.joins.com
Bash 프로세스 종료
exit
coredns 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 } EOF
coredns 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-dns
net-tools Pod로 Bash 연결
kubectl exec -it net-tools -- /bin/bash
CoreDNS에 추가한 Rewrite 규칙 확인
dig nginx.joins.com
CoreDNS에 추가한 Rewrite 규칙 테스트
curl nginx.joins.com
Bash 프로세스 종료
exit
net-tools Pod 삭제
kubectl delete pod net-tools
Last updated