containernetworking / plugins

Some reference and example networking plugins, maintained by the CNI team.
Apache License 2.0
2.22k stars 784 forks source link

how to config dhcp ipam plugin #1090

Open 13567436138 opened 2 months ago

13567436138 commented 2 months ago
cat <<EOF | kubectl apply -f -
apiVersion: "k8s.cni.cncf.io/v1"
kind: NetworkAttachmentDefinition
metadata:
  name: dhcp-net
spec:
  config: '{
    "cniVersion": "0.3.1",
    "type": "macvlan",
    "master": "ens33",
    "mode": "bridge",
    "ipam": {
        "type": "dhcp",
        "daemonSocketPath": "/run/cni/dhcp.sock",
        "request": [
            {
                "skipDefault": false
            }
        ],
        "provide": [
            {
                "option": "subnet-mask",
                "value": "192.168.1.1/24"
            }
        ]
    }
  }'
EOF

Warning FailedCreatePodSandBox 3m19s (x136 over 17m) kubelet (combined from similar events): Failed to create pod sandbox: rpc error: code = Unknown desc = failed to setup network for sandbox "e162a982e4cf574daa9544100e5466ebdd7939b1d0470437e2d91b6411a402f3": plugin type="multus-shim" name="multus-cni-network" failed (add): CmdAdd (shim): CNI request failed with status 400: 'ContainerID:"e162a982e4cf574daa9544100e5466ebdd7939b1d0470437e2d91b6411a402f3" Netns:"/var/run/netns/cni-60d1a714-9279-2e14-7c7f-bd8d780b9ff3" IfName:"eth0" Args:"IgnoreUnknown=1;K8S_POD_NAMESPACE=default;K8S_POD_NAME=samplepod;K8S_POD_INFRA_CONTAINER_ID=e162a982e4cf574daa9544100e5466ebdd7939b1d0470437e2d91b6411a402f3;K8S_POD_UID=36e51649-5257-43ce-b51a-13231cede974" Path:"" ERRORED: error configuring pod [default/samplepod] networking: [default/samplepod/36e51649-5257-43ce-b51a-13231cede974:dhcp-net]: error adding container to network "dhcp-net": error calling DHCP.Allocate: Can not parse option "": Can not parse option: strconv.ParseUint: parsing "": invalid syntax ': StdinData: {"capabilities":{"bandwidth":true,"portMappings":true},"clusterNetwork":"/host/etc/cni/net.d/10-calico.conflist","cniVersion":"0.3.1","logLevel":"verbose","logToStderr":true,"name":"multus-cni-network","type":"multus-shim"}

lisongmin commented 1 month ago

The option must set in each request, so you may remove the

            {
                "skipDefault": false
            }

Or add an option to it.

13567436138 commented 1 month ago

How to add option to it Can you give full example