Skip to content

Commit b1c9c3c

Browse files
docs(aws): tutorial with kind and localstack
Signed-off-by: ivan katliarchuk <[email protected]>
1 parent 031b6e4 commit b1c9c3c

File tree

13 files changed

+816
-4
lines changed

13 files changed

+816
-4
lines changed

docs/scripts/requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
mkdocs-git-revision-date-localized-plugin == 1.2.4
2-
mkdocs == 1.5.3
3-
mkdocs-macros-plugin==1.3.7
4-
mkdocs-material == 9.5.17
2+
mkdocs == 1.6.1
3+
mkdocs-macros-plugin == 1.3.7
4+
mkdocs-material == 9.7.1
55
mkdocs-literate-nav == 0.6.1
66
mkdocs-same-dir == 0.1.3
77
mike == 2.0.0
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# ref: docs/snippets/tutorials/aws-localstack/dnsendpoint-cname.yml
2+
---
3+
apiVersion: externaldns.k8s.io/v1alpha1
4+
kind: DNSEndpoint
5+
metadata:
6+
name: cname-example
7+
namespace: default
8+
annotations:
9+
dns.why/type: aws-localstack-tutorial
10+
spec:
11+
endpoints:
12+
- dnsName: www.example.com
13+
recordTTL: 600
14+
recordType: CNAME
15+
targets:
16+
- example.com
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# ref: docs/snippets/tutorials/aws-localstack/dnsendpoint-multi.yml
2+
---
3+
apiVersion: externaldns.k8s.io/v1alpha1
4+
kind: DNSEndpoint
5+
metadata:
6+
name: simple-example
7+
namespace: default
8+
annotations:
9+
dns.why/type: aws-localstack-tutorial
10+
spec:
11+
endpoints:
12+
- dnsName: dnsendpoint-a.example.com
13+
recordTTL: 300
14+
recordType: A
15+
targets:
16+
- 192.168.1.100
17+
- dnsName: dnsendpoint-a-lb.example.com
18+
recordTTL: 200
19+
recordType: A
20+
targets:
21+
- 10.0.1.1
22+
- 10.0.1.2
23+
- 10.0.1.3
24+
- dnsName: dnsendpoint-aaaa.example.com
25+
recordTTL: 600
26+
recordType: AAAA
27+
targets:
28+
- 2001:0db8:85a3:0000:0000:8a2e:0370:7334
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# ref: docs/snippets/tutorials/aws-localstack/dnsendpoint-txt.yml
2+
---
3+
apiVersion: externaldns.k8s.io/v1alpha1
4+
kind: DNSEndpoint
5+
metadata:
6+
name: txt-example
7+
namespace: default
8+
spec:
9+
endpoints:
10+
- dnsName: _acme-challenge.example.com
11+
recordTTL: 300
12+
recordType: TXT
13+
targets:
14+
- "validation-token-12345"
15+
- dnsName: example.com
16+
recordTTL: 3600
17+
recordType: TXT
18+
targets:
19+
- "v=spf1 include:_spf.google.com ~all"
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# run docs/snippets/tutorials/aws-localstack/check-records.sh
6+
7+
export AWS_REGION=eu-west-1
8+
export AWS_ACCESS_KEY_ID=foo
9+
export AWS_SECRET_ACCESS_KEY=bar
10+
export AWS_ENDPOINT_URL=http://127.0.0.1:32379
11+
12+
MATCH="${1:-}" # optional positional argument to filter records by name
13+
14+
zones=$(aws route53 list-hosted-zones-by-name --query "HostedZones[].Id" --output json)
15+
16+
echo "$zones" | jq -r '.[]' | while IFS= read -r hosted_zone_id; do
17+
zone=${hosted_zone_id#"/hostedzone/"}
18+
echo "Checking records for zone: $zone"
19+
20+
if [ -z "$MATCH" ]; then
21+
# default behaviour (unchanged)
22+
aws route53 list-resource-record-sets \
23+
--hosted-zone-id "$zone" \
24+
--query "ResourceRecordSets[].{Name:Name, Type:Type, Value:ResourceRecords[*].Value, TTL:TTL}" \
25+
--output json
26+
else
27+
# filtered behaviour
28+
aws route53 list-resource-record-sets \
29+
--hosted-zone-id "$zone" \
30+
--query "ResourceRecordSets[?contains(Name, \`${MATCH}\`)].{Name:Name, Type:Type, Value:ResourceRecords[*].Value, TTL:TTL}" \
31+
--output json
32+
fi
33+
done
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# ref: docs/snippets/tutorials/aws-localstack/foo-app.yml
2+
---
3+
apiVersion: v1
4+
kind: Service
5+
metadata:
6+
name: foo-app
7+
annotations:
8+
external-dns.alpha.kubernetes.io/hostname: foo-app.example.com
9+
dns.why/type: aws-localstack-tutorial
10+
spec:
11+
type: ClusterIP
12+
clusterIP: None
13+
ports:
14+
- port: 80
15+
targetPort: 80
16+
protocol: TCP
17+
selector:
18+
app: foo
19+
---
20+
apiVersion: apps/v1
21+
kind: Deployment
22+
metadata:
23+
name: foo-app
24+
annotations:
25+
dns.why/type: aws-localstack-tutorial
26+
spec:
27+
replicas: 3
28+
selector:
29+
matchLabels:
30+
app: foo
31+
template:
32+
metadata:
33+
labels:
34+
app: foo
35+
spec:
36+
containers:
37+
- name: foo
38+
image: nginx:latest
39+
ports:
40+
- containerPort: 80
41+
resources:
42+
requests:
43+
memory: "5Mi"
44+
cpu: "25m"
45+
limits:
46+
memory: "5Mi"
47+
cpu: "25m"
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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/aws-localstack/kind.yaml
5+
# kind delete cluster --name aws-localstack
6+
# kubectl cluster-info --context kind-aws-localstack
7+
# kubectl get nodes -o wide
8+
---
9+
kind: Cluster
10+
apiVersion: kind.x-k8s.io/v1alpha4
11+
name: aws-localstack
12+
networking:
13+
apiServerAddress: 127.0.0.1
14+
apiServerPort: 6443
15+
ipFamily: dual
16+
nodes:
17+
- role: control-plane
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
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# ref: docs/snippets/tutorials/aws-localstack/service-lb.yml
2+
---
3+
apiVersion: v1
4+
kind: Service
5+
metadata:
6+
name: loadbalancer-service
7+
annotations:
8+
external-dns.alpha.kubernetes.io/hostname: my-loadbalancer.example.com
9+
dns.why/type: aws-localstack-tutorial
10+
namespace: default
11+
spec:
12+
type: LoadBalancer
13+
ports:
14+
- port: 80
15+
name: http
16+
targetPort: 80
17+
selector:
18+
app: test-app
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# ref: https://github.com/kubernetes-sigs/external-dns/blob/master/charts/external-dns/values.yaml
2+
logLevel: info # debug, info, warn, error
3+
policy: sync
4+
5+
provider:
6+
name: aws
7+
8+
txtOwnerId: aws-localstack
9+
10+
domainFilters:
11+
- example.com
12+
- local.tld
13+
14+
sources:
15+
- service
16+
- ingress
17+
- crd
18+
19+
env:
20+
- name: AWS_REGION
21+
value: eu-west-1
22+
- name: AWS_ACCESS_KEY_ID
23+
value: foo-fake
24+
- name: AWS_SECRET_ACCESS_KEY
25+
value: bar-fake
26+
- name: AWS_ENDPOINT_URL
27+
value: http://localstack.localstack.svc.cluster.local:4566
28+
29+
interval: 1m
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# ref: https://github.com/localstack/helm-charts/blob/main/charts/localstack/values.yaml
2+
3+
debug: false
4+
5+
extraLabels:
6+
app: localstack
7+
8+
extraEnvVars:
9+
- name: SERVICES
10+
value: "route53"
11+
12+
# -- Set a fixed port for LocalStack edge service --
13+
service:
14+
type: NodePort
15+
edgeService:
16+
name: edge
17+
targetPort: 4566
18+
nodePort: 32379
19+
20+
enableStartupScripts: true
21+
startupScriptContent: |
22+
#!/bin/bash
23+
create_zone_if_missing() {
24+
ZONE_NAME="$1"
25+
COMMENT="$2"
26+
27+
EXISTING_ZONE_ID=$(
28+
awslocal route53 list-hosted-zones-by-name \
29+
--dns-name "${ZONE_NAME}." \
30+
--query "HostedZones[?Name=='${ZONE_NAME}.'].Id | [0]" \
31+
--output text
32+
)
33+
34+
if [ "$EXISTING_ZONE_ID" != "None" ]; then
35+
echo "Route53 zone '${ZONE_NAME}' already exists (${EXISTING_ZONE_ID})"
36+
return 0
37+
fi
38+
39+
echo "Creating Route53 zone '${ZONE_NAME}'"
40+
awslocal route53 create-hosted-zone \
41+
--name "$ZONE_NAME" \
42+
--caller-reference "$(date +%s)" \
43+
--hosted-zone-config Comment="$COMMENT"
44+
}
45+
46+
create_zone_if_missing "local.tld" "external-dns"
47+
create_zone_if_missing "example.com" "external-dns"
48+
49+
lambda:
50+
executor: "kubernetes"

0 commit comments

Comments
 (0)