Kubernetes - CoreDNS
Kubernetes 기초
Kubernetes - CoreDNS
DNS 도메인 네임 서비스
- 서비스를 생성하면 대응되는 DNS 엔트리가 생성됨
- 엔트리는 <서비스 이름="">.<네임스페이스 이름="">.svc.cluster.local 의 형식을 가짐 네임스페이스>서비스>
CoreDNS
- 내부에서 DNS서버 역할을 하는 POD가 조냊
- DNS 에는 configmap저장소를 사용해 설정 파일을 컨트롤함
- CoreFile을 통해 현재 클러스터의 NS를 지정
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
kubectl get configmap coredns -n kube-system -o yaml ------------------------------------------------------------ apiVersion: v1 data: Corefile: | .:53 { 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 }
POD에서도 Subdomain을 사용하면 DNS서비스를 사용가능하다.
https://kubernetes.io/ko/docs/concepts/services-networking/dns-pod-service/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# sub도메인 생성 및 POD 도메인 생성 YAML파일
apiVersion: v1
kind: Service
metadata:
name: default-subdomain
spec:
selector:
name: busybox
clusterIP: None
ports:
- name: foo # 사실 포트는 필요하지 않다.
port: 1234
targetPort: 1234
---
apiVersion: v1
kind: Pod
metadata:
name: busybox1
labels:
name: busybox
spec:
hostname: busybox-1
subdomain: default-subdomain
containers:
- image: busybox:1.28
command:
- sleep
- "3600"
name: busybox
---
apiVersion: v1
kind: Pod
metadata:
name: busybox2
labels:
name: busybox
spec:
hostname: busybox-2
subdomain: default-subdomain
containers:
- image: busybox:1.28
command:
- sleep
- "3600"
name: busybox
연습문제
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
apiVersion: v1
kind: Namespace
metadata:
creationTimestamp: null
name: blue
---
apiVersion: v1
kind: Service
metadata:
name: srv-jenkins
namespace: blue
spec:
ports:
- protocol: TCP
port: 8080
targetPort: 8080
selector:
run: pod-jenkins
---
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
run: pod-jenkins
name: pod-jenkins
namespace: blue
spec:
replicas: 1
selector:
matchLabels:
run: pod-jenkins
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
run: pod-jenkins
spec:
containers:
- image: jenkins/jenkins
name: jenkins
ports:
- containerPort: 8080
resources: {}
status: {}
1
2
k exec http-go -- curl srv-jenkins.blue.svc.cluster.local:8080
k exec http-go -- curl srv-jenkins.blue:8080
This post is licensed under CC BY 4.0 by the author.

