From 0b7ce957e19460daa502da9249d6d41c9b8c2d27 Mon Sep 17 00:00:00 2001
From: royalcat <k.adamovich20@gmail.com>
Date: Fri, 14 Mar 2025 15:12:20 +0400
Subject: [PATCH] external-dns

---
 ingress-system/cloudflare-api-token.yaml |   7 ++
 ingress-system/external-dns-crd.yaml     | 104 +++++++++++++++++++++++
 ingress-system/external-dns.yaml         |  53 ++++++++++++
 3 files changed, 164 insertions(+)
 create mode 100644 ingress-system/cloudflare-api-token.yaml
 create mode 100644 ingress-system/external-dns-crd.yaml
 create mode 100644 ingress-system/external-dns.yaml

diff --git a/ingress-system/cloudflare-api-token.yaml b/ingress-system/cloudflare-api-token.yaml
new file mode 100644
index 0000000..8f6bc0d
--- /dev/null
+++ b/ingress-system/cloudflare-api-token.yaml
@@ -0,0 +1,7 @@
+apiVersion: v1
+kind: Secret
+metadata:
+  name: cloudflare-api-token
+  namespace: ingress-system
+data:
+  token: 9gCqm5J98tBKKZlcH5oUvQ5GmNKAxtSoRa5TfWea
diff --git a/ingress-system/external-dns-crd.yaml b/ingress-system/external-dns-crd.yaml
new file mode 100644
index 0000000..20b4b5a
--- /dev/null
+++ b/ingress-system/external-dns-crd.yaml
@@ -0,0 +1,104 @@
+---
+apiVersion: apiextensions.k8s.io/v1
+kind: CustomResourceDefinition
+metadata:
+  annotations:
+    api-approved.kubernetes.io: https://github.com/kubernetes-sigs/external-dns/pull/2007
+    controller-gen.kubebuilder.io/version: v0.15.0
+  name: dnsendpoints.externaldns.k8s.io
+spec:
+  group: externaldns.k8s.io
+  names:
+    kind: DNSEndpoint
+    listKind: DNSEndpointList
+    plural: dnsendpoints
+    singular: dnsendpoint
+  scope: Namespaced
+  versions:
+    - name: v1alpha1
+      schema:
+        openAPIV3Schema:
+          properties:
+            apiVersion:
+              description: |-
+                APIVersion defines the versioned schema of this representation of an object.
+                Servers should convert recognized schemas to the latest internal value, and
+                may reject unrecognized values.
+                More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
+              type: string
+            kind:
+              description: |-
+                Kind is a string value representing the REST resource this object represents.
+                Servers may infer this from the endpoint the client submits requests to.
+                Cannot be updated.
+                In CamelCase.
+                More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
+              type: string
+            metadata:
+              type: object
+            spec:
+              description: DNSEndpointSpec defines the desired state of DNSEndpoint
+              properties:
+                endpoints:
+                  items:
+                    description:
+                      Endpoint is a high-level way of a connection between
+                      a service and an IP
+                    properties:
+                      dnsName:
+                        description: The hostname of the DNS record
+                        type: string
+                      labels:
+                        additionalProperties:
+                          type: string
+                        description: Labels stores labels defined for the Endpoint
+                        type: object
+                      providerSpecific:
+                        description: ProviderSpecific stores provider specific config
+                        items:
+                          description:
+                            ProviderSpecificProperty holds the name and value
+                            of a configuration which is specific to individual DNS providers
+                          properties:
+                            name:
+                              type: string
+                            value:
+                              type: string
+                          type: object
+                        type: array
+                      recordTTL:
+                        description: TTL for the record
+                        format: int64
+                        type: integer
+                      recordType:
+                        description:
+                          RecordType type of record, e.g. CNAME, A, AAAA,
+                          SRV, TXT etc
+                        type: string
+                      setIdentifier:
+                        description:
+                          Identifier to distinguish multiple records with
+                          the same name and type (e.g. Route53 records with routing
+                          policies other than 'simple')
+                        type: string
+                      targets:
+                        description: The targets the DNS record points to
+                        items:
+                          type: string
+                        type: array
+                    type: object
+                  type: array
+              type: object
+            status:
+              description: DNSEndpointStatus defines the observed state of DNSEndpoint
+              properties:
+                observedGeneration:
+                  description: The generation observed by the external-dns controller.
+                  format: int64
+                  type: integer
+              type: object
+          type: object
+      served: true
+      storage: true
+      subresources:
+        status: {}
diff --git a/ingress-system/external-dns.yaml b/ingress-system/external-dns.yaml
new file mode 100644
index 0000000..9a858ec
--- /dev/null
+++ b/ingress-system/external-dns.yaml
@@ -0,0 +1,53 @@
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: external-dns
+  namespace: ingress-system
+spec:
+  strategy:
+    type: Recreate
+  selector:
+    matchLabels:
+      app.kubernetes.io/name: external-dns
+  template:
+    metadata:
+      labels:
+        app.kubernetes.io/name: external-dns
+    spec:
+      containers:
+        - name: external-dns
+          image: registry.k8s.io/external-dns/external-dns:v0.15.1
+          args:
+            - --source=crd
+            - --provider=cloudflare
+            - --domain-filter=royalcat.dev
+            - --domain-filter=konfa.ch
+            - --domain-filter=kmsign.ru
+            - --managed-record-types=A
+            - --managed-record-types=CNAME
+            - --managed-record-types=NS
+          env:
+            - name: CF_API_TOKEN
+              valueFrom:
+                secretKeyRef:
+                  name: cloudflare-api-token
+                  key: apiToken
+---
+# Source: external-dns/templates/service.yaml
+apiVersion: v1
+kind: Service
+metadata:
+  name: external-dns
+  namespace: ingress-system
+  labels:
+    app.kubernetes.io/name: external-dns
+spec:
+  type: ClusterIP
+  selector:
+    app.kubernetes.io/name: external-dns
+    app.kubernetes.io/instance: release-name
+  ports:
+    - name: http
+      port: 7979
+      targetPort: http
+      protocol: TCP