Add a simple A record to the CoreDNS service on Kubernetes
Asked Answered
S

2

7

Here is the issue: We have several microk8s cluster running on different networks; yet each have access to our storage network where our NAS are.

within Kubernetes, we create disks with an nfs-provisioner (nfs-externalsubdir). Some disks were created with the IP of the NAS server specified. Once we had to change the IP, we discovered that the disk was bound to the IP, and changing the IP meant creating a new storage resource within.

To avoid this, we would like to be able to set a DNS record on the Kubernetes cluster level so we could create storage resources with the nfs provisioner based on a name an not an IP, and we could alter the DNS record when needed (when we upgrade or migrate our external NAS appliances, for instance) for instance, I'd like to tell every microk8s environments that:

192.168.1.4 my-nas.mydomain.local

... like I would within the /etc/hosts file.

Is there a proper way to achieve this? I tried to follow the advices on this link: Is there a way to add arbitrary records to kube-dns? (the answer upvoted 15 time, the cluster-wise section), restarted a deployment, but it didn't work

I cannot use the hostAliases feature since it isn't provided on every chart we are using, that's why I'm looking for a more global solution.

Best Regards,

Shon answered 11/1, 2022 at 16:39 Comment(1)
Just to check, you added the configmap to CoreDNS volumes and restarted CoreDNS?Tsarina
B
1

You can set you custom DNS in K8s using the Kube-DNS (Core-DNS)

You have to inject/pass the configuration file as configmap to Core DNS volume.

Configmap will look like

apiVersion: v1
kind: ConfigMap
metadata:
  name: coredns
  namespace: kube-system
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
        cache 30
        loop
        reload
        loadbalance
    }  

You read more about at : https://kubernetes.io/docs/tasks/administer-cluster/dns-custom-nameservers/

https://platform9.com/kb/kubernetes/how-to-customize-coredns-configuration-for-adding-additional-ext

Or else you can also use the external DNS with the Core DNS

You can annotate the service(resource) and external DNS will add the address to core-dns

Read more about it at :

https://github.com/kubernetes-sigs/external-dns/blob/master/docs/tutorials/coredns.md

https://docs.mirantis.com/mcp/q4-18/mcp-deployment-guide/deploy-mcp-cluster-using-drivetrain/deploy-k8s/external-dns/verify-external-dns/coredns-etxdns-verify.html

Brail answered 11/1, 2022 at 19:18 Comment(0)
H
3

...we could create storage resources with the nfs provisionner based on a name an not an IP, and we could alter the DNS record when needed...

For this you can try headless service without touching coreDNS:

apiVersion: v1
kind: Service
metadata:
  name: my-nas
  namespace: kube-system  # <-- you can place it somewhere else
  labels:
    app: my-nas
spec:
 ports:
 - protocol: TCP
   port: <nas port>
---
apiVersion: v1
kind: Endpoints
metadata:
  name: my-nas
subsets: 
- addresses:
  - ip: 192.168.1.4
  ports:
  - port: <nas port>

Use it as: my-nas.kube-system.svc.cluster.local

Handsomely answered 12/1, 2022 at 2:18 Comment(0)
B
1

You can set you custom DNS in K8s using the Kube-DNS (Core-DNS)

You have to inject/pass the configuration file as configmap to Core DNS volume.

Configmap will look like

apiVersion: v1
kind: ConfigMap
metadata:
  name: coredns
  namespace: kube-system
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
        cache 30
        loop
        reload
        loadbalance
    }  

You read more about at : https://kubernetes.io/docs/tasks/administer-cluster/dns-custom-nameservers/

https://platform9.com/kb/kubernetes/how-to-customize-coredns-configuration-for-adding-additional-ext

Or else you can also use the external DNS with the Core DNS

You can annotate the service(resource) and external DNS will add the address to core-dns

Read more about it at :

https://github.com/kubernetes-sigs/external-dns/blob/master/docs/tutorials/coredns.md

https://docs.mirantis.com/mcp/q4-18/mcp-deployment-guide/deploy-mcp-cluster-using-drivetrain/deploy-k8s/external-dns/verify-external-dns/coredns-etxdns-verify.html

Brail answered 11/1, 2022 at 19:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.