This topic explains how to configure Cloud Native Runtimes for Tanzu to develop locally on kind. Developing locally on kind allows you to visit URLs generated by Knative for your services in a browser, or use curl to view URLs.

Prerequisites

Before you follow the procedures below, you must have access to:

  • Docker Hub
  • The internet

Because this feature uses the CoreDNS container image hosted on Docker Hub, you need internet access to pull the image.

Configure Your Local Kind Cluster

To develop locally with Cloud Native Runtimes on kind, you need to create a cluster with ports mapped from your host machine to your kind cluster.

To create a cluster and map ports from your host machine to your kind cluster:

  1. Create and save a file named kind-cluster.yaml that contains following code:

    kind: Cluster
    apiVersion: kind.x-k8s.io/v1alpha4
    nodes:
     - role: control-plane
     - role: worker
       extraPortMappings:
       - containerPort: 31443 # expose port 31443 of the node to port 80 on the host for use later by Contour ingress (envoy)
         hostPort: 443
       - containerPort: 31080 # expose port 31080 of the node to port 80 on the host for use later by Contour ingress (envoy)
         hostPort: 80
       - containerPort: 30053 # expose CoreDNS port to port 53 on the host machine
         hostPort: 53
         protocol: udp
       - containerPort: 30053 # expose CoreDNS port to port 53 on the host machine
         hostPort: 53
         protocol: tcp
    
  2. Create a kind cluster. Run:

    kind create cluster --config kind-cluster.yaml
    

Install Cloud Native Runtimes Locally

After you create a local cluster with kind, you can install Cloud Native Runtimes on that cluster with a flag to enable local DNS. The install script and flag adds a CoreDNS deployment in the cloud-native-runtimes namespace.

  1. Ensure that your Kubernetes client targets your local kind cluster. Run:

    kubectl cluster-info
    

    If your Kubernetes client targets your local cluster, the return includes your local cluster information.

  2. From the cloud-native-runtimes directory, run the installation script:

    cnr_provider=local cnr_local_dns__enable=true ./bin/install.sh
    

Note: Knative Serving routes use example.com as the default domain. See Setting up a custom domain in the Knative documentation. If you want to use the Local DNS feature with your custom domain, specify your custom domain in the install command: for example, cnr_provider=local cnr_local_dns__enable=true cnr_local_dns__domain=mydomain.com.

Test Your CoreDNS

You can verify that your CoreDNS is configured correctly using Dig. For information about using Dig DNS lookup, see Dig in the Google Admin Toolbox.

To use Dig to verify your CoreDNS:

  1. Run:

    dig test.YOUR-DOMAIN @127.0.0.1
    

    Where YOUR-DOMAIN is the name of your domain.

    If your CoreDNS is configured correctly, the return includes the IPv4 loopback address 127.0.0.1.

Set the Host Machine DNS

To use your CoreDNS to resolve queries, set your host machine to use the IPv4 loopback address 127.0.0.1 as the DNS server.

If you are using DHCP, disconnecting and reconnecting your network connection resets your nameserver.

If your local cluster is deleted, your normal DNS queries continue working because you have other DNS servers configured.

Set on MacOS

To set the host machine DNS on MacOS:

  1. Create a directory called /etc/resolver, if the directory does not already exist.

  2. Inside this directory, create a file with the same name as your domain. If you are using the default domain, the filename is /etc/resolver/example.com.

  3. Populate the file with the following nameserver to let your machine know to send any requests for your domain to localhost: nameserver 127.0.0.1.

Set on Linux

To set the host machine DNS on Linux:

  1. Add the following line to the top of your /etc/resolv.conf file:

    nameserver 127.0.0.1
    

    The nameserver entries are an ordered list, so anything not served by localhost continues down the file to try other entries.

Note: Setting 127.0.0.1 as your primary DNS server can break nslookup on Linux, because it uses only the primary DNS server.

Set on Windows

To set the host machine DNS on Windows:

  1. Complete the steps under Change your DNS servers settings, and enter the IPv4 loopback address 127.0.0.1 as the preferred DNS server. See Change your DNS servers settings in the Google Public DNS documentation.

  2. (Optional) Input another preferred DNS server as the alternate DNS server.

  3. (Optional) You may need to disable IPv6 for the resolution to be successful.

Note: Setting 127.0.0.1 as your primary DNS server can break nslookup on Windows, because it uses only the primary DNS server.

Reset the Host Machine DNS

You can reset the host machine DNS to another IPv4 loopback address using the procedure for your operating system below.

Reset on MacOS

To reset the host machine DNS on MacOS:

  1. Remove the /etc/resolver/YOUR-DOMAIN file.

Reset on Linux

To reset the host machine DNS on Linux:

  1. Remove the following line from the top of your /etc/resolv.conf file:

    nameserver 127.0.0.1
    

Reset on Windows

To reset the host machine DNS on Windows:

  1. Complete the steps under Change your DNS servers settings, and enter the IPv4 loopback address as your original preferred DNS server address. See Change your DNS servers settings in the Google Public DNS documentation.

  2. (Optional) Enable IPv6 if you disabled it when you set the host machine DNS.

check-circle-line exclamation-circle-line close-line
Scroll to top icon