Search code examples
kubernetesgoogle-cloud-platformdnsgoogle-kubernetes-enginenameservers

GCP Kubernetes Nodes update with Internal Private Nameservers


We have a docker image repository on GitLab which is hosted on the internal network ( repo.mycomapanydomain.io).

My K8 deployment is failing with Name not resolved error for repo.mycomapanydomain.io

I tried updating the kube-dns config as below. But I still have the same error.

apiVersion: v1
kind: ConfigMap
metadata:
  name: kube-dns
  namespace: kube-system
data:
 stubDomains: |
   {“mycomapanydomain”: [“10.131.0.4”]}
 upstreamNameservers: |
   [“10.131.0.4”]

How can I make my resolv.conf to have the Internal nameservers by default or K8 to resolve with my internal DNS IPs?


Solution

  • Editing /etc/resolv.conf either manually or automatically is discouraged as for:

    Internal DNS and resolv.conf

    By default, most Linux distributions store DHCP information in resolv.conf. Compute Engine instances are configured to renew DHCP leases every 24 hours. For instances that are enabled for zonal DNS, the DHCP lease expires every hour. DHCP renewal overwrites this file, undoing any changes that you might have made. Instances using zonal DNS have both zonal and global entries in the resolv.conf file.

    -- Cloud.google.com: Compute: Docs: Internal DNS: resolv.conf

    Also:

    Modifications on the boot disk of a node VM do not persist across node re-creations. Nodes are re-created during manual upgrade, auto-upgrade, auto-repair, and auto-scaling. In addition, nodes are re-created when you enable a feature that requires node re-creation, such as GKE sandbox, intranode visibility, and shielded nodes.

    -- Cloud.google.com: Kubernetes Engine: Docs: Concepts: Node images: Modifications


    As for:

    How can I make my resolv.conf to have the Internal nameservers by default or K8 to resolve with my internal DNS IPs?

    From the GCP and GKE perspective, you can use the Cloud DNS to configure your DNS resolution in either way that:

    • your whole DOMAIN is residing in GCP infrastructure (and you specify all the records).
    • your DOMAIN queries are forwarded to the DNS server of your choosing.

    You can create your DNS zone by following:

    • GCP Cloud Console (Web UI) -> Network Services -> Cloud DNS -> Create zone:

    Assuming that you want to forward your DNS queries to your internal DNS server residing in GCP your configuration should look similar to the one below:

    DNS

    A side note!

    1. Remember to follow the "Destination DNS Servers" steps to allow the DNS queries to your DNS server.
    2. Put the internal IP address of your DNS server where the black rectangle is placed.

    After that your GKE cluster should be able to resolve the DNS queries of your DOMAIN.NAME.


    Additional resources:

    I found an article that shows how you can create a DNS forwarding for your GCP instances: