Deploying a dhcpd server

3/15/2019

I'm trying to deploy a DHCP server in a pod on my Kubernetes cluster. I've created the following resources:

$ cat dhcpd-deployment.yaml

kind: Deployment
metadata:
  name: dhcpd
  namespace: kube-mngt
spec:
  selector:
    matchLabels:
      app: dhcpd
  replicas: 1
  template:
    metadata:
      labels:
        app: dhcpd
    spec:
      nodeSelector:
        kubernetes.io/hostname: neo1
      containers:
      - name: dhcpd
        image: 10.0.100.1:5000/dhcpd:latest
        volumeMounts:
        - name: dhcpd-config
          mountPath: /etc/dhcp
      volumes:
        - name: dhcpd-config
          persistentVolumeClaim:
            claimName: dhcpd-config-volume-claim

$ kubectl create -f dhcpd-deployment.yaml

$ cat dhcpd-service.yaml

apiVersion: v1

kind: Service
metadata:
  name: dhcpd
  namespace: kube-mngt
spec:
  selector:
    app: dhcpd
  ports:
  - name: dhcp
    protocol: UDP
    port: 67
    targetPort: 67

$ kubectl create -f dhcpd-service.yaml

Everything is created successfully, pod and service but unfortunately, the DHCPD pod does not receive any packet on UDP port 67.

Did I miss something?

-- jpm
dhcp
kubernetes

1 Answer

3/18/2019

I've found the solution to make the dhcpd pod working well. The example below is to server a external network outside of the k8s service network (clusterIPs). The dhcp configuration is like following:

include "/etc/dhcp/dhcpd-options.conf";

subnet 192.168.0.0 netmask 255.255.0.0 {}

# management network
subnet 10.0.0.0 netmask 255.255.0.0 {
  option routers 10.0.255.254;
  option broadcast-address 10.0.255.255;
  next-server 10.0.100.6;
  include "/etc/dhcp/lease-bmc.conf";
  include "/etc/dhcp/lease-node.conf";
}

The k8s service is as following:

$ cat dhcpd-service.yaml

apiVersion: v1
kind: Service
metadata:
  name: dhcpd
  namespace: kube-mngt
spec:
  selector:
    app: dhcpd
  ports:
  - protocol: UDP
    port: 67
    targetPort: 67
  externalIPs:
  - 10.0.100.5

Then, configure the switch (interface vlan X) to specify an helper-address that point the the dhcp server (in our case, 10.0.100.5)

interface Vlan1
 ip address 10.0.255.254 255.255.0.0 secondary
 ip address 10.0.0.1 255.255.0.0
 ip helper-address 10.0.100.5
!
-- jpm
Source: StackOverflow