Skip to content

Commit 0dbead2

Browse files
docs(core-dns): update tutorial (#5926)
* docs(core-dns): update tutorial Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com> * docs(core-dns): update tutorial Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com> * docs(core-dns): update tutorial Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com> * docs(core-dns): update tutorial Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com> * docs(core-dns): update tutorial Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com> * docs(core-dns): update tutorial Co-authored-by: Michel Loiseleur <97035654+mloiseleur@users.noreply.github.com> --------- Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com> Co-authored-by: Michel Loiseleur <97035654+mloiseleur@users.noreply.github.com>
1 parent 1a5ab81 commit 0dbead2

File tree

8 files changed

+579
-321
lines changed

8 files changed

+579
-321
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
apiVersion: v1
3+
kind: Service
4+
metadata:
5+
name: a
6+
annotations:
7+
external-dns.alpha.kubernetes.io/hostname: a.domain.local
8+
external-dns.alpha.kubernetes.io/coredns-group: "g1"
9+
spec:
10+
type: LoadBalancer
11+
status:
12+
loadBalancer:
13+
ingress:
14+
- ip: 127.0.0.1
15+
---
16+
apiVersion: v1
17+
kind: Service
18+
metadata:
19+
name: b
20+
annotations:
21+
external-dns.alpha.kubernetes.io/hostname: b.domain.local
22+
external-dns.alpha.kubernetes.io/coredns-group: "g1"
23+
spec:
24+
type: LoadBalancer
25+
status:
26+
loadBalancer:
27+
ingress:
28+
- ip: 127.0.0.2
29+
---
30+
apiVersion: v1
31+
kind: Service
32+
metadata:
33+
name: c
34+
annotations:
35+
external-dns.alpha.kubernetes.io/hostname: c.subdom.domain.local
36+
external-dns.alpha.kubernetes.io/coredns-group: "g2"
37+
spec:
38+
type: LoadBalancer
39+
status:
40+
loadBalancer:
41+
ingress:
42+
- ip: 127.0.0.3
43+
---
44+
apiVersion: v1
45+
kind: Service
46+
metadata:
47+
name: d
48+
annotations:
49+
external-dns.alpha.kubernetes.io/hostname: d.subdom.domain.local
50+
external-dns.alpha.kubernetes.io/coredns-group: "g2"
51+
spec:
52+
type: LoadBalancer
53+
status:
54+
loadBalancer:
55+
ingress:
56+
- ip: 127.0.0.4
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# kubectl apply -f docs/snippets/tutorials/coredns/etcd.yaml
2+
# kubectl delete -f docs/snippets/tutorials/coredns/etcd.yaml
3+
---
4+
apiVersion: v1
5+
kind: Service
6+
metadata:
7+
name: etcd
8+
namespace: default
9+
spec:
10+
type: ClusterIP
11+
clusterIP: None
12+
ports:
13+
- name: etcd-client
14+
port: 2379
15+
- name: etcd-server
16+
port: 2380
17+
- name: etcd-metrics
18+
port: 8080
19+
selector:
20+
app: etcd
21+
---
22+
apiVersion: v1
23+
kind: Service
24+
metadata:
25+
name: etcd-nodeport-external
26+
namespace: default
27+
spec:
28+
type: NodePort
29+
ports:
30+
- port: 2379
31+
targetPort: 2379
32+
nodePort: 32379 # must match kind config port mapping
33+
selector:
34+
app: etcd
35+
---
36+
apiVersion: apps/v1
37+
kind: StatefulSet
38+
metadata:
39+
name: etcd
40+
namespace: default
41+
spec:
42+
serviceName: etcd
43+
replicas: 1
44+
selector:
45+
matchLabels:
46+
app: etcd
47+
template:
48+
metadata:
49+
labels:
50+
app: etcd
51+
annotations:
52+
serviceName: etcd
53+
spec:
54+
containers:
55+
- name: etcd
56+
image: quay.io/coreos/etcd:v3.5.15
57+
command:
58+
- /usr/local/bin/etcd
59+
- --name=$(HOSTNAME)
60+
- --listen-peer-urls=$(URI_SCHEME)://0.0.0.0:2380
61+
- --listen-client-urls=$(URI_SCHEME)://0.0.0.0:2379
62+
- --advertise-client-urls=$(URI_SCHEME)://$(HOSTNAME).$(SERVICE_NAME):2379
63+
- --data-dir=/var/lib/etcd
64+
ports:
65+
- containerPort: 2379
66+
volumeMounts:
67+
- name: data
68+
mountPath: /var/lib/etcd
69+
env:
70+
- name: K8S_NAMESPACE
71+
valueFrom:
72+
fieldRef:
73+
fieldPath: metadata.namespace
74+
- name: HOSTNAME
75+
valueFrom:
76+
fieldRef:
77+
fieldPath: metadata.name
78+
- name: SERVICE_NAME
79+
valueFrom:
80+
fieldRef:
81+
fieldPath: metadata.annotations['serviceName']
82+
- name: ETCDCTL_ENDPOINTS
83+
value: $(HOSTNAME).$(SERVICE_NAME):2379
84+
- name: URI_SCHEME
85+
value: "http"
86+
volumeClaimTemplates:
87+
- metadata:
88+
name: data
89+
spec:
90+
accessModes: ["ReadWriteOnce"]
91+
resources:
92+
requests:
93+
storage: 50Mi
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# kubectl apply -f docs/snippets/tutorials/coredns/fixtures.yaml
2+
# kubectl delete -f docs/snippets/tutorials/coredns/fixtures.yaml
3+
# kubectl get svc -l svc=test-svc
4+
---
5+
apiVersion: v1
6+
kind: Service
7+
metadata:
8+
name: a-g1-record
9+
labels:
10+
svc: test-svc
11+
annotations:
12+
external-dns.alpha.kubernetes.io/hostname: a.example.org
13+
external-dns.alpha.kubernetes.io/coredns-group: "g1"
14+
cluster-name: "cluster1"
15+
namespace: default
16+
spec:
17+
type: LoadBalancer
18+
ports:
19+
- port: 80
20+
name: http
21+
targetPort: 80
22+
selector:
23+
app: test-app
24+
---
25+
apiVersion: v1
26+
kind: Service
27+
metadata:
28+
name: aa-g1-record
29+
labels:
30+
svc: test-svc
31+
annotations:
32+
external-dns.alpha.kubernetes.io/hostname: aa.example.org
33+
external-dns.alpha.kubernetes.io/coredns-group: "g1"
34+
cluster-name: "cluster1"
35+
namespace: default
36+
spec:
37+
type: LoadBalancer
38+
ports:
39+
- port: 80
40+
name: http
41+
targetPort: 80
42+
selector:
43+
app: test-app
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# ref: https://kind.sigs.k8s.io/docs/user/quick-start/
2+
# https://kind.sigs.k8s.io/docs/user/configuration/#extra-port-mappings
3+
4+
# kind create cluster --config=docs/snippets/tutorials/coredns/kind.yaml
5+
# kind delete cluster --name coredns-etcd
6+
# kubectl cluster-info --context kind-coredns-etcd
7+
# kubectl get nodes -o wide
8+
---
9+
kind: Cluster
10+
apiVersion: kind.x-k8s.io/v1alpha4
11+
name: coredns-etcd
12+
networking:
13+
apiServerAddress: 127.0.0.1
14+
apiServerPort: 6443
15+
nodes:
16+
- role: control-plane
17+
image: kindest/node:v1.33.0
18+
kubeadmConfigPatches:
19+
- |
20+
kind: InitConfiguration
21+
nodeRegistration:
22+
kubeletExtraArgs:
23+
node-labels: "ingress-ready=true"
24+
extraPortMappings:
25+
- containerPort: 80
26+
hostPort: 8080
27+
listenAddress: "0.0.0.0"
28+
protocol: TCP
29+
- containerPort: 43
30+
hostPort: 4443
31+
listenAddress: "0.0.0.0"
32+
protocol: TCP
33+
- containerPort: 32379 # inside kind node
34+
hostPort: 32379 # exposed on host
35+
listenAddress: "0.0.0.0"
36+
protocol: TCP
37+
- role: worker
38+
image: kindest/node:v1.33.0
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# kubectl logs deploy/coredns -n default -c coredns
2+
# ref: https://github.com/coredns/helm/blob/master/charts/coredns/values.yaml
3+
isClusterService: false
4+
5+
service:
6+
name: coredns
7+
port: 53
8+
annotations: {}
9+
clusterIP: ""
10+
11+
# Main customization
12+
servers:
13+
- zones:
14+
- zone: .
15+
port: 53
16+
plugins:
17+
- name: errors
18+
- name: debug # <── enables debug mode
19+
- name: health
20+
configBlock: |-
21+
lameduck 5s
22+
- name: ready
23+
# to query kubernetes API for data
24+
- name: kubernetes
25+
parameters: cluster.local 10.0.0.0/24
26+
configBlock: |-
27+
pods insecure
28+
fallthrough in-addr.arpa ip6.arpa
29+
ttl 30
30+
- name: etcd
31+
parameters: "example.org"
32+
configBlock: |
33+
stubzones
34+
path /skydns
35+
endpoint http://etcd.default.svc.cluster.local:2379
36+
fallthrough
37+
- name: log # <── log each DNS query
38+
- name: forward
39+
parameters: ". /etc/resolv.conf"
40+
- name: cache
41+
parameters: 30
42+
- name: reload
43+
- name: loop
44+
- name: loadbalance
45+
46+
replicaCount: 1
47+
48+
# required to debug DNS resolution from within CoreDNS pods
49+
# kubectl logs deploy/coredns -n default -c resolv-check --tail=50
50+
initContainers:
51+
- name: resolv-check
52+
image: busybox:1.37
53+
command: ["sh", "-c", "echo '--- /etc/resolv.conf ---'; cat /etc/resolv.conf; echo '---------------------------'; nslookup kubernetes.default.svc.cluster.local || true; sleep 5"]
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
# ref: https://github.com/kubernetes-sigs/external-dns/blob/master/charts/external-dns/values.yaml
3+
provider:
4+
name: coredns
5+
6+
env:
7+
- name: ETCD_URLS
8+
value: "http://etcd.default.svc.cluster.local:2379"
9+
10+
11+
txtOwnerId: cluster1
12+
# Filter resources queried for endpoints by annotation, using label selector semantics
13+
annotationFilter: cluster-name=cluster1
14+
15+
domainFilters:
16+
- example.org
17+
18+
# Sources define what ExternalDNS will use to discover endpoints
19+
sources:
20+
- service
21+
22+
# Policy options
23+
policy: sync
24+
25+
logLevel: debug
26+
interval: 1m
27+
28+
# RBAC configuration
29+
rbac:
30+
create: true
31+
32+
# Optional: tune resource requests
33+
resources:
34+
requests:
35+
cpu: 100m
36+
memory: 64Mi
37+
limits:
38+
cpu: 200m
39+
memory: 128Mi

0 commit comments

Comments
 (0)