K8s DNS
- Service 및 pod용 DNS
- Cluster에서 실행하는 모든 pod가 사용할 수 있도록 구성
- DNS를 통해 service와 pod access
- service_name.namespace.svc.cluster.local
- Pod-IP-Address.namespace.pod.cluster.local
<이미지 출처 : https://www.youtube.com/watch?v=vhsyWMnc2f8&list=PLApuRlvrZKohLYdvfX-UEFYTE7kfnnY36&index=8>
- kube-dns service 작동 확인
kubectl get service --all-namespaces
NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
default kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 4d20h
kube-system kube-dns ClusterIP 10.96.0.10 <none> 53/UDP,53/TCP,9153/TCP 4d20h
- coreDNS pod 작동 확인
kubectl get pods --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system coredns-6d4b75cb6d-gd65q 1/1 Running 4 (3h26m ago) 4d20h
kube-system coredns-6d4b75cb6d-pr92v 1/1 Running 4 (3h26m ago) 4d20h
...
CoreDNS 사용
- pod 배포 및 service 생성, 확인
vi deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
spec:
replicas: 3
selector:
matchLabels:
app: web
template:
metadata:
name: nginx-pod
labels:
app: web
spec:
containers:
- name: nginx-container
image: nginx:1.14
vi svc.yaml
apiVersion: v1
kind: Service
metadata:
name: svc-web
spec:
clusterIP: 10.96.100.100
selector:
app: web
ports:
- protocol: TCP
port: 80
targetPort: 80
kubectl apply -f deployment.yaml
kubectl apply -f svc.yaml
kuebctl get all
- client용 pod 실행 및 nameserver 확인
- kube-dns의 ip주소와 동일
kubectl run client-pod --image=centos:7 -it -- /bin/bash
cat /etc/resolv.conf
search default.svc.cluster.local svc.cluster.local cluster.local t4loxwhes1oetkkxir4bjy3yxf.syx.internal.cloudapp.net
nameserver 10.96.0.10
options ndots:5
- Service에 대한 coreDNS 사용
curl svc-web.default.svc.cluster.local
curl svc-web
- Pod에 대한 coreDNS 사용
curl 10-47-0-1.default.pod.cluster.local
Pod내 DNS 설정
- dnsconfig pod 생성
vi custom-dns.yaml
apiVersion: v1
kind: Pod
metadata:
namespace: default
name: dns-example
spec:
containers:
- name: test
image: nginx
dnsPolicy: "None"
dnsConfig:
nameservers:
- 1.2.3.4 # 변경 가능
searches:
- ns1.svc.cluster-domain.example # 변경 가능
- my.dns.search.suffix
options:
- name: ndots
value: "2""
- name: edns0
- 생성한 pod로 접속
- dnsconfig와 일치
kubectl exec dns-example -it -- /bin/bash
cat /etc/resolv.conf
search ns1.svc.cluster-domain.example my.dns.search.suffix
nameserver 1.2.3.4
options ndots:2 edns0
참고 :
https://www.youtube.com/watch?v=vhsyWMnc2f8&list=PLApuRlvrZKohLYdvfX-UEFYTE7kfnnY36&index=8
'INFRA > DevOps' 카테고리의 다른 글
[K8S] role & rolebinding (0) | 2023.06.18 |
---|---|
[k8s] Kubernetes AutoScaling (0) | 2023.05.02 |
[k8s] kube-proxy (0) | 2023.04.10 |
[K8s] Network (0) | 2023.04.10 |
[k8s] Persistent Volume & Persistent Volume Claim (0) | 2023.04.03 |
댓글