Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set mac address to an interface #266

Closed
wei0313 opened this issue Feb 21, 2019 · 14 comments
Closed

set mac address to an interface #266

wei0313 opened this issue Feb 21, 2019 · 14 comments

Comments

@wei0313
Copy link

wei0313 commented Feb 21, 2019

Hi
I want to have a "fixed" mac-address and my own interface name instead of "net1" for my interface; meaning, which time I redeploy the pod I want the interface to always have the same mac. Below are my original yaml files. I have also tried putting my network-definition under /et/cni/multus/net.d/macvlan-conf.conf and change my network-attachment-definition, but this still doesn't work.
I also tried removing the network-status section and add interfaceRequest: ifname which gives me the interface name I want, but even with macRequest, I am still unable to change the mac-address. I have been googling, and I am unable to find the an example on changing the mac-address. I also looked at code. It seems like delegate.macRequest is always empty string. I traced and found net.macRequest in LoadDelegateNetConf is also empty. When I enable debug log, I could see my mac in setPodNetworkAnnotation.
Is it because delegate is not reading from the pod annotation? Where should I config the delegate?
Does v0.3.1 support macRequest? If so, how should I configure?
If I want my pod yaml / network-attachment-def yaml to handle the configurations only, do i need to change anything in the multus.conf? If so, would you show an example?

Here is my network-attachment-definition yaml.
apiVersion: "k8s.cni.cncf.io/v1" kind: NetworkAttachmentDefinition metadata: name: macvlan-conf spec: config: '{ "cniVersion": "0.3.0", "type": "macvlan", "master": "ens255f1", "mode": "bridge", "ipam": { "type": "host-local", "subnet": "192.168.1.0/24", "rangeStart": "192.168.1.200", "rangeEnd": "192.168.1.216", "routes": [ { "dst": "0.0.0.0/0" } ], "gateway": "192.168.1.1" }, }'
Here is my pod yaml
piVersion: v1 # for versions before 1.9.0 use apps/v1beta2 kind: Pod metadata: name: rhel75-pod annotations: k8s.v1.cni.cncf.io/networks: macvlan-conf k8s.v1.cni.cncf.io/networks-status: '[{ "name": "macvlan-conf", "interface": "agnes-1", "mac": "20:01:02:03:04:05", "ips": [ "192.168.1.200" ], "dns": {} }]' spec: containers: - name: rhel75base image: rhel7.5-base-new:base imagePullPolicy: Never

Thanks in advance

@s1061123
Copy link
Member

To configure MAC address, you need:

Could you please change your config and check it again?

@wei0313
Copy link
Author

wei0313 commented Feb 21, 2019

Thanks @s1061123 I will give it a try.
If later on I need to use ovs instead of macvlan, can I still use tuning on top of ovs? I have been testing with ovs-cni.

@SchSeba
Copy link
Contributor

SchSeba commented Feb 21, 2019

Hi @wei0313 the question is if the ovs write the mac he assign on a mac filter or something if not yes you can use the tuning.

@wei0313
Copy link
Author

wei0313 commented Feb 21, 2019

@SchSeba judging by the ovs-cni code, it reads mac attribute, but since multus is not setting it so it doesn't reflect. I am wondering if using tuning would help in this matter

@SchSeba
Copy link
Contributor

SchSeba commented Feb 24, 2019

Hi @wei0313 if the ovs knows how to read the mac address you can try to configure the pod this way

apiVersion: v1
kind: Pod
metadata:
  name: pod-case-01
  annotations:
    k8s.v1.cni.cncf.io/networks: [{"name": "macvlan-conf-1","mac":"20:01:02:03:04:05"}]
spec:
  containers:
  - name: pod-case-01
    image: docker.io/centos/tools:latest
    command:
    - /sbin/init

If he can't read the mac but he doesn't configure a mac filter you can use tuning like this

apiVersion: "k8s.cni.cncf.io/v1"
kind: NetworkAttachmentDefinition
metadata:
  name: ovs-conf
spec:
  config: '{
      "cniVersion": "0.3.1",
      "name": "ovs-conf",
      "plugins" : [
        {
          "type": "ovs",
          "bridge": "br1",
          "vlan": 100
        },
        {
          "type": "tuning"
        }
      ]
    }'

@Elegant996
Copy link

Elegant996 commented Feb 27, 2019

I am experiencing the same issue using the below but please take note of the annotations for interface and interfaceRequest as the former does not work.

When digging into this, it appears that there is no definition for interface, mac or ips per the parsePodNetworkAnnotation and parsePodNetworkObjectName functions of k8clients.go. This appears to be the reason unless I am overlooking something.

NetworkAttachmentDefinition:

apiVersion: "k8s.cni.cncf.io/v1"
kind: NetworkAttachmentDefinition
metadata:
  name: macvlan-conf
spec: 
  config: '{
      "cniVersion": "0.3.0",
      "plugins": [ {
        "type": "macvlan",
        "master": "net0",
        "mode": "bridge",
        "ipam": {
          "type": "static"
          "addresses": [
            {
              "address": "192.168.10.30/24",
              "gateway": "192.168.10.1"
            }
          ],
          "dns": {
            "nameservers" : ["8.8.8.8"]
          }
        }
      },
      {
        "type":"tuning"
      }]
    }'

Pod:

apiVersion: v1
kind: Pod
metadata:
  name: samplepod
  annotations:
    k8s.v1.cni.cncf.io/networks: '[
      {
        "name": "macvlan-conf",
        "interfaceRequest": "mgmt", # works
        "interface": "mgmt", # doesn't work
        "mac": "aa:bb:cc:dd:ee:ff"
      }
    ]'
spec:
  containers:
  - name: samplepod
    command: ["/bin/bash", "-c", "sleep 2000000000000"]
    image: dougbtv/centos-network

Thanks!

@wei0313
Copy link
Author

wei0313 commented Mar 5, 2019

interface
@Elegant996 I tried with "mac": "aa:bb:cc:dd:ee:ff" and it doesn't seem to take effect. did it work for you?

@SchSeba
Copy link
Contributor

SchSeba commented Mar 5, 2019

Hi @wei0313 what is the image tag that you use for multus ?

@Elegant996
Copy link

Elegant996 commented Mar 5, 2019

That could be it, I'm using latest perhaps this is only available when using snapshot?

@rkamudhan
Copy link
Member

The 'snapshot' will point to master. If you need the latest commit. Please use the snapshot.

@wei0313
Copy link
Author

wei0313 commented Mar 5, 2019

I am using master. I only ran the "cat .images/{multus...flannel...} | kubectl apply -f -" cmd. Should i change to snapshot? I don't see a snapshot branch tho.

@Elegant996
Copy link

Elegant996 commented Mar 5, 2019

@wei0313 We're refering to this line in multus-daemonset.yaml. The tag latest is 7 months old and snapshot uses the latest commits which is likely what we're after. Will confirm once I get home.

EDIT: Was definitely the issue. Thanks!

@Nokia1Aditya
Copy link

new interface is not getting created , any tips on what could be the issue.

@dougbtv
Copy link
Member

dougbtv commented Mar 25, 2020

Looks like this one got fixed by using the latest version (and the :latest tag is now actually master@HEAD)

@dougbtv dougbtv closed this as completed Mar 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants