k8snetworkplumbingwg / whereabouts

A CNI IPAM plugin that assigns IP addresses cluster-wide
Apache License 2.0
289 stars 125 forks source link

manually assign macvlan IP to pod #111

Open flower01840 opened 3 years ago

flower01840 commented 3 years ago

Hi, I'd like to manually assign macvlan IP to a pod. it is possible but the pod will have two macvlan IP, one is automatically be attached, another is from pod annotation, so it will waste ip resources..... Is it possible to assign only one macvlan IP(which defined by me) to a pod? here is my configuration:

# NetworkAttachmentDefinition
apiVersion: "k8s.cni.cncf.io/v1"
kind: NetworkAttachmentDefinition
metadata:
  name: whereabouts-conf
spec:
  config: '{
      "cniVersion": "0.3.0",
      "name": "whereaboutsexample",
      "type": "macvlan",
      "master": "ens3",
      "mode": "bridge",
      "log_file": "/var/log/whereabouts.log",
      "log_level": "debug",
      "ipam": {
        "type": "whereabouts",
        "range": "172.32.3.20-172.32.3.29/24",
        "gateway": "172.32.3.1",
        "exclude": [
          "172.32.3.22/32"
        ],
        "routes": [
          { "dst": "0.0.0.0/0" }
        ],
        "gateway": "172.32.3.1"
      }
    }'

# pod definition
apiVersion: v1
kind: Pod
metadata:
  name: pod-1
  annotations:
    k8s.v1.cni.cncf.io/networks: '[{
      "name": "whereabouts-conf",
      "ips": [ "172.32.3.29/24" ],
      "mac": "c2:b0:57:aa:aa:aa",
      "gateway": [ "172.32.3.22" ]
    }]'
spec:
  containers:
  - name: pod-1
    command: ["/bin/ash", "-c", "trap : TERM INT; sleep infinity & wait"]
    image: 172.32.3.166/library/alpine
maiqueb commented 2 years ago

I think the best option available for having a static IP address on a pod is to use the static IPAM plugin.

Why do you need to use whereabouts for this scenario @flower01840 ?

salkin commented 1 year ago

I think the best option available for having a static IP address on a pod is to use the static IPAM plugin.

Why do you need to use whereabouts for this scenario @flower01840 ?

The use case is when you need static IPs for some of the pods in the network but not all.