1. The introduction
Mxsm-register. local indicates the domain name of the LAN registry. If you need to write the IP address of each deployed registry to the CoreDNS configuration file, you can set up a DNS server on the Intranet. This would require me to modify the Corefile configuration file each time. Is there a way I can start the service and automatically bind the IP address of the registry machine to mxsm-register.local, and remove the IP address of the registry offline from the DNS server? Here’s how to use CoreDNS+ ETCD to do this.
Tips: Since I can only code in Java (Go plan learning), the subsequent code will be explained in Java
2. CoreDNS ETCD plug-in
CoreDNS is a highly flexible plug-in component, which itself provides many plug-ins official plug-ins, but also allows developers to extend plug-ins. The above functionality relies on a plug-in called ETcd, which has the following features: SkyDNS service discovery, it is not suitable as a general DNS zone data plug-in. Only a subset of DNS record types are implemented.
Configuration syntax:
etcd [ZONES...] {
fallthrough [ZONES...]
path PATH
endpoint ENDPOINT...
credentials USERNAME PASSWORD
tls CERT KEY CACERT
}
Copy the code
- Fallthrough: If the region matches but no record can be generated, pass the request to the next plug-in
- Path: path in etcd, default /skydns
- endpoint: etcd endpoint
- Credentials: Indicates the user name and password of etcd
- The TLS: CA
3. How to set up
3.1 Environment Preparation
- Etcd environment setup (go to the etCD website to see the setup tutorial github.com/etcd-io/etc…)
- CoreDNS structures,
These are the two preconditions.
3.2 Configuration File
This is modified using the configuration in CoreDNS Setting up Intranet DNS service. Corefile:
{forward. 8.8.8.8} mxsm.local {file mxsm.local {reload 30s}} etcd-mxsm.local:53 {etcd {path/MXSM endpoint http://172.22.50.98:2379 -- fill this in according to your etCD deployment}}Copy the code
Start CoreDNS for authentication
3.3 EtCD Key Value Description
Etcd: / mxsm.local etcd: / mxsm.local etcd: / mxsm.local etcd: / mxsm.local / MXSM /local/etcd-mxsm/ / MXSM /local/etcd-mxsm/x/MXSM /local/etcd-mxsm/b etc. In this case, query etcd-mxsm.local.
3.4 validation
Use the etcdctl command put:
$./etcdctl put /mxsm/local/etcd-mxsm/ '{" host ", "172.22.50.28", "TTL" : 60}'
$./etcdctl put /mxsm/local/etcd-mxsm/1 '{" host ", "172.22.50.128", "TTL" : 60}'
$./etcdctl put /mxsm/local/etcd-mxsm/2 '{" host ", "172.22.50.228", "TTL" : 60}'
Copy the code
Then verify with DIG:
$Dig @ 127.0.0.1 etcd - MXSM. A local
Copy the code
4. How to integrate projects
Project integration replaces the manual etcdctl command above. Add Maven dependencies:
<dependency>
<groupId>io.etcd</groupId>
<artifactId>jetcd-core</artifactId>
<version>0.6.1</version>
</dependency>
Copy the code
Code:
public class Etcd {
public static void main(String[] args) throws Exception {
// create client using endpoints
Client client = Client.builder().endpoints("Fill in XXXX address by yourself").build();
KV kvClient = client.getKVClient();
ByteSequence key = ByteSequence.from("/mxsm/local/etcd-mxsm/".getBytes());
ByteSequence value = ByteSequence.from("{\" host \ ": \" 172.22.50.98 \ ", \ "TTL \" : 60}".getBytes());
PutResponse putResponse = kvClient.put(key, value).get();
System.out.println(putResponse.toString());
TimeUnit.SECONDS.sleep(20);
DeleteResponse deleteResponse = kvClient.delete(key, DeleteOption.newBuilder().isPrefix(true).build()).get(); System.out.println(deleteResponse); }}Copy the code
Here’s a demo of the code:
You can see that the results are as expected. This will enable the function described in the opening paragraph
I am ant back elephant, the article is helpful to you like to pay attention to me, the article has incorrect place please be corrected to leave a comment ~ thank you!
Reference Documents:
- Github.com/etcd-io/jet…
- etcd.io/
- Coredns. IO/plugins/etc…