“This is the 30th day of my participation in the First Challenge 2022. For details: First Challenge 2022”
1. The background
Since I was developing a chat service, the registry design referenced RocketMQ’s NameServer. Registries are deployed separately and there is no data interaction between registries. The registry interacts only with access services and messaging services. That is, each registry is linked to all access services and messaging services. Maintain connection over heartbeat protocol:
However, there is a problem with this. For example, if I add a new registry, the access service and message processing service can only synchronize information to the registry without downtime. The previous access service and message processing service on the registry IP is written dead in the configuration file without doing dynamic loading (dynamic loading would also be cumbersome to change the registry IP address of the service deployed on each machine). Then think of DNS, DNS has domain name and IP correspondence, just need to determine the domain name of the registry, and then obtain the DNS domain name corresponding IP address can achieve dynamic access services and message processing services dynamic synchronization to the new registry:
Since this is an Intranet domain name service, THE DNS service needs to be set up by myself. When RESEARCHING Nacos, I found a domain name service of CoreDNS. Then, it is found that CoreDNS can be used as an Intranet self-established domain name service and can be applied in K8s.
2. CoreDNS installation
There are two ways to install:
-
Directly download the compiled zip package
Download: github.com/coredns/cor…
This approach is not concerned with the development of custom plug-ins, just want to set up an environment that is more suitable
-
The source code to compile
This is done by compiling and installing the source code
2.1 Local source compilation
CoreDNS is written in Go, so make sure you have the Go development environment installed before compiling
The GO version needs to be greater than 1.17
Check out the project from Github and use make to compile the project:
$ git clone https://github.com/coredns/coredns
$ cd coredns
$ make
Copy the code
2.2 Docker compilation
$ docker run --rm -i -t -v $PWD:/v -w /v golang:1.17 make
Copy the code
Golang Docker image versions are optional
3. Configure examples
3.1 Official Hello Word Configuration
Direct launch according to the official website
$ ./coredns
Copy the code
To query the CoreDNS service:
Dig @127.0.0.1 -p 53 www.example.comCopy the code
Parsing succeeded.
3.2 Custom domain name resolution
The configuration file is in the same Corefile as the coredns command
Grammar:
# define a snippet
(snip) {
prometheus
log
errors
}
. {
whoami
import snip
}
Copy the code
Custom configuration:
.{forward. 8.8.8.8} mxsm.local {file mxsm.local {reload 30s}}Copy the code
Configure a mxsm.local file:
@ IN SOA mxsm.local. devops.mxsm.local. ( 20200202 ; SERIAL 7200 ; REFRESH 600 ; RETRY 3600000 ; EXPIRE 60) ; MINIMUM @in NS dns1.mxsm.local.mxsm.local. IN A 192.168.43.128 redis.mxsm.local. IN A 192.168.43.128 mysql.mxsm.local. IN A 192.168.43.128 elasticsearch. MXSM. Local. IN A 192.168.43.128 192.168.43.128 FTP IN ACopy the code
Re-run the COREDNS service to verify:
Extranet parsing validation
This is where the setup is done
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:
- coredns.io/