...
1# Dnsmasq-controller
2
3A Dnsmasq-controller for Kubernetes, implemented in go using [kubebuilder](https://kubebuilder.io/).
4
5## Status
6
7
8
9
10
11## Supported resources
12
13- DnsmasqOptions
14- DnsHosts
15- DhcpHosts
16- DhcpOptions
17
18
19### Configuration
20
21| Flag | Type | Required | Description |
22|---------------------------|--------|----------|-----------------------------------------------------------------------------------------------------------------------------------------|
23| `-cleanup` | bool | false | Cleanup Dnsmasq config directory before start. |
24| `-conf-dir` | string | false | Dnsmasq config directory for write configuration to. (default "/etc/dnsmasq.d") |
25| `-controller` | string | false | Name of the controller this controller satisfies. (default "") |
26| `-development` | bool | false | Run the controller in development mode. |
27| `-dhcp` | bool | false | Enable DHCP Service and configuration discovery. |
28| `-dns` | bool | false | Enable DNS Service and configuration discovery. |
29| `-enable-leader-election` | bool | false | Enable leader election for controller manager. Enabling this will ensure there is only one active controller manager. |
30| `-kubeconfig` | string | false | Paths to a kubeconfig. Only required if out-of-cluster. |
31| `-log-level` | string | false | The log level used by the operator. (default "info") |
32| `-metrics-addr` | string | false | The address the metric endpoint binds to. (default ":8080") |
33| `-sync-delay` | int | false | Time in seconds to syncronise Dnsmasq configuration. (default 1) |
34| `-watch-namespace` | string | false | Namespace the controller watches for updates to Kubernetes objects. All namespaces are watched if this parameter is left empty. |
35| `--` | array | false | Additional command line arguments for Dnsmasq may be specified after `--` (read [dnsmasq-man] for more details) |
36
37[dnsmasq-man]: http://www.thekelleys.org.uk/dnsmasq/docs/dnsmasq-man.html
38
39## Installation
40
41```bash
42# CRDs
43kubectl apply -k config/crd/bases
44
45# RBAC
46kubectl apply -k config/rbac
47
48# DNS-server (for infra.example.org)
49kubectl apply -k config/dns-server
50
51# DHCP-server
52kubectl apply -k config/dhcp-server
53
54# Add dnsmasq role to your nodes
55kubectl label node <node1> <node2> <node3> node-role.kubernetes.io/dnsmasq=
56```
57
58## Examples
59
60Global DHCP-configuration:
61
62```yaml
63---
64apiVersion: dnsmasq.kvaps.cf/v1beta1
65kind: DhcpOptions
66metadata:
67 name: default-network-configuration
68spec:
69 controller: ""
70 options:
71 - key: option:router
72 values: [192.168.67.1]
73 - key: option:dns-server
74 values: [192.168.67.1]
75 - key: option:domain-name
76 values: [infra.example.org]
77 - key: option:domain-search
78 values: [infra.example.org]
79---
80apiVersion: dnsmasq.kvaps.cf/v1beta1
81kind: DnsmasqOptions
82metadata:
83 name: default-matchers
84spec:
85 controller: ""
86 options:
87 - key: dhcp-range
88 values: [192.168.67.0,static,infinite]
89 - key: dhcp-match
90 values: [set:iPXE,"175","39"]
91 - key: dhcp-match
92 values: [set:X86PC,option:client-arch,"0"]
93 - key: dhcp-match
94 values: [set:X86-64_EFI,option:client-arch,"7"]
95 - key: dhcp-match
96 values: [set:X86-64_EFI,option:client-arch,"9"]
97```
98
99Global DNS-configuration:
100
101```yaml
102---
103apiVersion: dnsmasq.kvaps.cf/v1beta1
104kind: DnsmasqOptions
105metadata:
106 name: global-dns
107spec:
108 controller: ""
109 options:
110 - key: srv-host
111 values: [_kerberos-master._tcp.infra.example.org,freeipa.example.org,"88"]
112 - key: srv-host
113 values: [_kerberos-master._udp.infra.example.org,freeipa.example.org,"88"]
114 - key: srv-host
115 values: [_kerberos._tcp.infra.example.org,freeipa.example.org,"88"]
116 - key: srv-host
117 values: [_kerberos._udp.infra.example.org,freeipa.example.org,"88"]
118 - key: srv-host
119 values: [_kpasswd._tcp.infra.example.org,freeipa.example.org,"464"]
120 - key: srv-host
121 values: [_kpasswd._udp.infra.example.org,freeipa.example.org,"464"]
122 - key: srv-host
123 values: [_ldap._tcp.infra.example.org,freeipa.example.org,"389"]
124 - key: srv-host
125 values: [_ntp._udp.infra.example.org,129.6.15.28,"123"]
126 - key: srv-host
127 values: [_ntp._udp.infra.example.org,129.6.15.29,"123"]
128 - key: txt-record
129 values: [_kerberos.infra.example.org,EXAMPLE.ORG]
130```
131
132Netboot-server configuration with tag `ltsp1`:
133
134```yaml
135---
136apiVersion: dnsmasq.kvaps.cf/v1beta1
137kind: DhcpOptions
138metadata:
139 name: ltsp1
140spec:
141 controller: ""
142 options:
143 - key: option:server-ip-address
144 tags: [ltsp1]
145 values: [192.168.67.11]
146 - key: option:tftp-server
147 tags: [ltsp1]
148 values: [ltsp1]
149 - key: option:bootfile-name
150 tags: [ltsp1,X86PC]
151 values: [ltsp/grub/i386-pc/core.0]
152 - key: option:bootfile-name
153 tags: [ltsp1,X86-64_EFI]
154 values: [ltsp/grub/x86_64-efi/core.efi]
155```
156
157DHCP-client for network booting using assigned tag `ltsp1`:
158
159```yaml
160---
161apiVersion: dnsmasq.kvaps.cf/v1beta1
162kind: DhcpHosts
163metadata:
164 name: netboot-client
165spec:
166 controller: ""
167 hosts:
168 - ip: 192.168.67.20
169 macs:
170 - 94:57:a5:d3:b6:f2
171 - 94:57:a5:d3:b6:f3
172 clientIDs: ["*"]
173 setTags: [ltsp1]
174 hostname: node1
175 leaseTime: infinite
176```
177
178Add A, AAAA and PTR records to the DNS:
179
180```yaml
181---
182apiVersion: dnsmasq.kvaps.cf/v1beta1
183kind: DnsHosts
184metadata:
185 name: netboot-client
186spec:
187 controller: ""
188 hosts:
189 - ip: 192.168.67.20
190 hostnames:
191 - node1
192 - node1.infra.example.org
193```
194
195## Development
196
197### Pre-requisites
198- [Go](https://golang.org/) 1.13 or later
199- [Kubebuilder](https://kubebuilder.io/) 2.3.1
200- [Kubernetes](https://kubernetes.io/) cluster
201
202### Getting started
203```bash
204make install
205make run
206```
207
208### Running tests
209```bash
210make test
211```
View as plain text