Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: add dns controller to sync cluster node dns records #270

Merged
merged 1 commit into from
Apr 26, 2021

Conversation

SataQiu
Copy link
Member

@SataQiu SataQiu commented Apr 20, 2021

Ⅰ. Describe what this PR does

In the edge computing scenario, the IP addresses of the edge nodes are likely to be the same. So we can not rely on the node IP to forward the request but should use the node hostname(unique in one cluster).
This PR provides the ability for the tunnel-server to handle requests in the form of scheme://[hostname]:[port]/[req_path].

How to use it

The dns controller will generate a ConfigMap named yurt-tunnel-nodes in the kube-system namespace.
You need to manually config CoreDNS to use it according to the steps like the following:
First, mount the ConfigMap as volume of CoreDNS Pod, for example

        volumeMounts:
        - mountPath: /etc/edge
          name: hosts
          readOnly: true
...

      volumes:
      - configMap:
          defaultMode: 420
          name: yurt-tunnel-nodes
        name: hosts

Second, update CoreDNS ConfigMap (kube-system/coredns), add the hosts section

apiVersion: v1
data:
  Corefile: |
    .:53 {
        errors
        health :10260
        hosts /etc/edge/tunnel-nodes {
            reload 300ms
            fallthrough
        }
        kubernetes cluster.local in-addr.arpa ip6.arpa {
           pods insecure
           upstream
           fallthrough in-addr.arpa ip6.arpa
           endpoint http://169.254.2.1:10261
        }
        prometheus :9153
        proxy . /etc/resolv.conf
        cache 30
        reload
    }
kind: ConfigMap
metadata:
  name: coredns
  namespace: kube-system

Ⅱ. Does this pull request fix one issue?

Ⅲ. List the added test cases (unit test/integration test) if any, please explain if no tests are needed.

Ⅳ. Describe how to verify it

Ⅴ. Special notes for reviews

go.mod Outdated Show resolved Hide resolved
@rambohe-ch rambohe-ch marked this pull request as ready for review April 20, 2021 12:06
@rambohe-ch
Copy link
Member

@SataQiu Thank you for making the pull request.
would you add more detail info like background, reason, solution etc to explain why we need this pull request?

@SataQiu SataQiu force-pushed the feature-dns-controller branch 2 times, most recently from 4ff4f91 to c1b683b Compare April 22, 2021 12:11
continue
}
}
records = append(records, formatDNSRecord(ip, node.Name))
Copy link
Member

@rambohe-ch rambohe-ch Apr 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

records for edge nodes are forgotten?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will record whether it is an edge node or not, but the destination ip is different.

}

// parse tunnel server tcp port
tunnelServerAgentPort, _ := strconv.Atoi(constants.YurttunnelServerAgentPort)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tunnelServerAgentPort for insecure request is not 10262, is 10264(YurttunnelServerMasterInsecurePort)

found = true
if v != record {
result[i] = record
changed = true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about add a break to exit for loop?

} else {
klog.Errorf("fail to get configmap %s/%s: %v",
YurttunnelServerDnatConfigMapNs,
YurttunnelServerDnatConfigMapName, err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that we need to add error return value for func GetConfiguredDnatPorts, and when we failed to get yurt-server-tunnel-cfg configmap, we can return error instead of empty slice.

go wait.Until(func() {
if err := dnsctl.syncTunnelServerService(); err != nil {
klog.Errorf("failed to sync tunnel server service, %v", err)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why we need to add syncTunnelServerService here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on past experience, we should not rely solely on the watch mechanism, as there is a risk of lost events. We need to make sure that the information is synchronized through a periodic list function.

@SataQiu SataQiu force-pushed the feature-dns-controller branch from c1b683b to cb0f13b Compare April 26, 2021 09:15
@@ -127,6 +127,7 @@ spec:
- yurt-tunnel-server
args:
- --bind-address=$(NODE_IP)
- --insecure-bind-address=$(NODE_IP)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure that the tunnel-server listening address can be accessed by other cloud nodes in the cluster.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, tunnel-server need to listen on node ip for insecure requests.

}
updatedSvcPorts = append(updatedSvcPorts, port)
}
svc.Spec.Ports = updatedSvcPorts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about add a flag to check service port need to be updated or not?

@SataQiu SataQiu force-pushed the feature-dns-controller branch from cb0f13b to 1f82b2c Compare April 26, 2021 09:52
Copy link
Member

@rambohe-ch rambohe-ch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@rambohe-ch rambohe-ch merged commit c025f96 into openyurtio:master Apr 26, 2021
MrGirl pushed a commit to MrGirl/openyurt that referenced this pull request Mar 29, 2022
feature: add dns controller to sync cluster node dns records
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants