简体   繁体   中英

How to configure DHCP IPAM plugin + Macvlan + Multus for the additional interface creation inside a k8s pod?

I'm facing the below mentioned issue while using DHCP IPAM plugin + Macvlan + Multus for the additional interface creation inside my pod and assigning IP from DHCP server.

I actually went through the related issues around this problem and tried all the solutions/different configurations mentioned there. But none of them were working so far. The documentation for CNI plugin w.r.t DHCP usage also not quite clear.

Related Issues:

  1. https://github.com/k8snetworkplumbingwg/multus-cni/issues/291
  2. https://github.com/containernetworking/plugins/issues/587
  3. https://github.com/containernetworking/plugins/issues/371
  4. https://github.com/containernetworking/plugins/issues/440
  5. https://github.com/containernetworking/cni/issues/398
  6. https://github.com/containernetworking/cni/issues/225
  7. https://github.com/containernetworking/plugins/issues/371

Solutions Suggested:

  1. https://github.com/containernetworking/plugins/pull/577

DHCP Daemon Logs:

[root@test-node cni_plugins]# ./dhcp daemon -broadcast=true
2022/06/09 12:00:03 ac7d57597540992a1af43455da24b3210561ce12b164820ee18f583a304a/test_net_attach1/net1: acquiring lease
2022/06/09 12:00:03 Link "net1" down. Attempting to set up
2022/06/09 12:00:03 network is down
2022/06/09 12:00:03 retrying in 2.881018 seconds
2022/06/09 12:00:16 no DHCP packet received within 10s
2022/06/09 12:00:16 retrying in 2.329120 seconds
2022/06/09 12:00:29 no DHCP packet received within 10s
2022/06/09 12:00:29 retrying in 1.875428 seconds

NetworkAttachmentDefinition:

apiVersion: k8s.cni.cncf.io/v1
kind: NetworkAttachmentDefinition
metadata:
  name: "test1"
  annotations:
    k8s.v1.cni.cncf.io/resourceName: intel.com/test_net_attach1
spec:
  config:
    '{
    "name": "test_net_attach1",
    "type": "macvlan",
    "master": "ens2f0",
    "ipam": {
        "type": "dhcp"
    }
    }'

Test Pod YAML:

apiVersion: v1
kind: Pod
metadata:
  name: dhcp-test1
  annotations:
    k8s.v1.cni.cncf.io/networks: test1
spec:
  nodeSelector:
    deploy: vm1
  containers:
    - name: c1
      image: centos:latest
      command: ["/bin/sh","-c"]
      args: ["sleep infinity"]

DHCP SERVER Logs:

Internet Systems Consortium DHCP Server 4.4.1
Copyright 2004-2018 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/
Config file: /data/dhcpd.conf
Database file: /data/dhcpd.leases
PID file: /var/run/dhcpd.pid
Wrote 0 leases to leases file.
Listening on LPF/ens2f0/b4:96:91:a5:8c:82/192.168.231.0/24
Sending on   LPF/ens2f0/b4:96:91:a5:8c:82/192.168.231.0/24
Sending on   Socket/fallback/fallback-net
Server starting service.
DHCPDISCOVER from 4a:63:ad:6d:9a:44 via ens2f0
DHCPOFFER on 192.168.231.120 to 4a:63:ad:6d:9a:44 via ens2f0
DHCPDISCOVER from 4a:63:ad:6d:9a:44 via ens2f0
DHCPOFFER on 192.168.231.120 to 4a:63:ad:6d:9a:44 via ens2f0

Observations:

  1. DHCP request and response are seen by tcpdump on the interface but the dhcp daemon says none was received.
  2. Looks like the DHCP daemon is not picking up the offer.

ENVIRONMENT: CNI: cni-plugins-linux-amd64-v1.1.1.tgz

Could someone please share the working configurations for the below mentioned items

  1. Network attachment definition
  2. Sample Pod YAML
  3. How to run DHCP Daemon?

for the better documentation and for the new comers who is facing issues around this? Please let me know if you needed anything or if I'm missing anything?

I started the daemon on the server node with:

cd /opt/cni/bin
sudo ./dhcp daemon

In a couple of seconds my pod received its IP address from my DHCP server.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM