반응형
[문제]
* Create a nginx pod called nginx-resolver using image nginx, expose it internally with a service called nginx-resolver-service.
* Test that you are able to look up the service and pod names from within the cluster. Use the image busybox:1.28 for dns lookup
- Record result in /tmp/nginx.svc and /tmp/nginx.pod
- pod: nginx-resolver created
- Service DNS Resolution recorded correctly
- Pod DNS resolution recorede correctly
[풀이]
pod 및 expose 생성
# kubectl run nginx-resolver --image=nginx
pod/nginx-resolver created
# kubectl expose pod nginx-resolver --name nginx-resolver-service --port=80 --target-port=80
service/nginx-resolver-service exposed
# kubectl get pod nginx-resolver -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
nginx-resolver 1/1 Running 0 47s 10.36.0.1 node1.example.com <none> <none>
# kubectl get svc nginx-resolver-service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
nginx-resolver-service ClusterIP 10.110.175.16 <none> 80/TCP 47s
pod 및 service에 대한 nslookup
- docs 문서에서 dns 내용 확인
https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/
dns 질의를 위한 busybox 이미지 파드를 임시로 생성
# kubectl run test --image=busybox:1.28 --rm -it --restart=Never -- /bin/sh
If you don't see a command prompt, try pressing enter.
/ # cat /etc/resolv.conf
search default.svc.cluster.local svc.cluster.local cluster.local
nameserver 10.96.0.10
options ndots:5
service nslookup 조회
/ # nslookup nginx-resolver-service.default.svc.cluster.local
Server: 10.96.0.10
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local
Name: nginx-resolver-service.default.svc.cluster.local
Address 1: 10.110.175.16 nginx-resolver-service.default.svc.cluster.local
pod nslookup 조회
/ # nslookup 10-36-0-1.default.pod.cluster.local
Server: 10.96.0.10
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local
Name: 10-36-0-1.default.pod.cluster.local
Address 1: 10.36.0.1 10-36-0-1.nginx-resolver-service.default.svc.cluster.local
/ # exit
pod "test" deleted
service, pod nslookup 조회 결과 저장
# cat > /tmp/nginx.svc
Server: 10.96.0.10
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local
Name: nginx-resolver-service.default.svc.cluster.local
Address 1: 10.110.175.16 nginx-resolver-service.default.svc.cluster.local
# cat > /tmp/nginx.pod
Server: 10.96.0.10
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local
Name: 10-36-0-1.default.pod.cluster.local
Address 1: 10.36.0.1 10-36-0-1.nginx-resolver-service.default.svc.cluster.local
[참고]
- 유투브 따배씨
반응형
'자격증 > CKA' 카테고리의 다른 글
[CKA] Network Policy (0) | 2023.05.02 |
---|---|
[CKA] ServiceAccount Role Binding (0) | 2023.05.01 |
[CKA] ServiceAccount Role Binding (0) | 2023.05.01 |
[CKA] User Cluster Role Binding (0) | 2023.05.01 |
[CKA] User Role Binding (0) | 2023.04.29 |