Kubernetes native dhcp server.
The server can be configured by creating and editing kubernetes objects
dhcpsubnet and optionally
To start listening, at least one
dhcpserver object must be created:
apiVersion: dhcp.kaas.mirantis.com/v1alpha1 kind: DHCPServer metadata: name: dhcpserver-sample-1 spec: listenInterface: enp0s3 listenAddress: 10.0.1.1
listenInterfaceServer will listen on all interfaces if this field is empty.
listenAddressServer will listen at
Each subnet is represented by
apiVersion: dhcp.kaas.mirantis.com/v1alpha1 kind: DHCPSubnet metadata: name: dhcpsubnet-sample-broadcast spec: subnet: 10.0.1.0/24 rangeFrom: 10.0.1.100 rangeTo: 10.0.1.200 gateway: 10.0.1.254 bootFileName: http://126.96.36.199/undionly.kpxe leaseTime: 3600 dns: - 188.8.131.52 - 184.108.40.206 options: - id: 66 type: string value: 10.12.0.1
subnetsubnet address. Required.
optionslist of dhcp options to be included in response. Optional.
Each server instance may serve multiple subnets. Server will automatically detect proper subnet for each
request, and will construct dhcp response according to
dhcpsubnet and possibly
Requests on unknown subnets will be ignored.
Per host configuration may be applied if needed by creating
apiVersion: dhcp.kaas.mirantis.com/v1alpha1 kind: DHCPHost metadata: name: host-sample-1 spec: subnet: 10.0.1.0/24 mac: "00:01:02:03:04:05" ip: 10.0.1.20 gateway: 10.0.1.3 hostname: sample-pxe-node dns: - 220.127.116.11 - 18.104.22.168 options: - id: 66 type: string value: 22.214.171.124 serverHostName: example.net bootFileName: http://10.1.2.3/alternate.ipxe leaseTime: 3600
subnetis a reference to subnet. Required.
macclient hardware address. Required.
ipclient fixed ip address. may be outside of range but must be inside of subnet. Will be taken from pool if empty.
Server start listening and logging dhcp requests when at least one
dhcpserver is created, and start responding
when at least one
dhcpsubnet is created.
$ kubectl get dhcpservers NAME INTERFACE LISTEN dhcpserver-sample-br1 br1 dhcpserver-veth 1 veth1 10.7.0.1
$ kubectl get dhcpsubnets NAME SUBNET FROM TO GATEWAY dhcpsubnet-sample-br1 10.10.0.0/16 10.10.1.100 10.10.255.200 10.10.0.1 dhcpsubnet-sample-veth1 10.11.0.0/16 10.11.1.1 10.11.255.250 10.11.255.254 dhcpsubnet-test-relay 10.7.0.0/16 10.7.1.100 10.7.255.200 10.7.0.1
- keep as few dhcpleases objects as possible;
- detect start of another server;
- load all subnets, leases and hosts before starting the server;
- configure namespace;
- log server version;
- add ping check option;
- handle subnet update;
- handle hostnames;
- support dhcp NAK;
- support dhcp INFORM;
- add validation webhooks;
- add mutating webhooks to add OwnerRef;
- conditional options;
- respect requested options;
- make test client;
- add ReuseAddr property to server/listen;
- exit if failed to bind;
- dhcp option 43 (vendor-option-space);
You’ll need a Kubernetes cluster to run against. You can use Minikube to get a local cluster for testing, or run against a remote cluster.
Note: Your controller will automatically use the current context in your kubeconfig file (i.e. whatever cluster
kubectl cluster-info shows).
Running on the cluster
- Install Instances of Custom Resources:
kubectl apply -f config/samples/
- Build and push your image to the location specified by
make docker-build docker-push IMG=<some-registry>/k8s-dhcp:tag
- Deploy the controller to the cluster with the image specified by
make deploy IMG=<some-registry>/k8s-dhcp:tag
To delete the CRDs from the cluster:
UnDeploy the controller to the cluster:
// TODO(user): Add detailed information on how you would like others to contribute to this project
How it works
This project aims to follow the Kubernetes Operator pattern
It uses Controllers which provides a reconcile function responsible for synchronizing resources untile the desired state is reached on the cluster
Test It Out
- Install the CRDs into the cluster:
- Run your controller (this will run in the foreground, so switch to a new terminal if you want to leave it running):
NOTE: You can also run this in one step by running:
make install run
Modifying the API definitions
If you are editing the API definitions, generate the manifests such as CRs or CRDs using:
make --help for more information on all potential
More information can be found via the Kubebuilder Documentation
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.