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

support device in route add #13

Closed
rootfs opened this issue Sep 3, 2020 · 1 comment
Closed

support device in route add #13

rootfs opened this issue Sep 3, 2020 · 1 comment

Comments

@rootfs
Copy link

rootfs commented Sep 3, 2020

For setups that have multiple interfaces, an interface name is needed when adding route, i.e. ip route add 10.123.123.1/32 dev br1

@dougbtv

@s1061123
Copy link
Contributor

s1061123 commented Sep 4, 2020

Hi @rootfs , thank you for the comment.

If you use route-override for net-attach-def, route-override automatically add device name of the net-attach-def because CNI config does not know the interface name created by the config.

For example, let's imagine that a pod is created with 4 interface (cluster network and 3 additional). At that time,

  • "test1" creates "net1"
  • "test2" creates "br1"
  • "test3" creates "net2"

Sample yaml:

apiVersion: v1
kind: Pod
metadata:
  name: centos
  annotations:
    k8s.v1.cni.cncf.io/networks: '[
            { "name": "test1" },
            { "name": "test2", "interface": "br1" },
            { "name": "test3" }
    ]'
spec:
(snip)

At that time, you can add route-override cni in net-attach-def, test2, as following. route-override CNI will add ip route add 10.123.123.1/32 dev br1.

---
apiVersion: "k8s.cni.cncf.io/v1"
kind: NetworkAttachmentDefinition
metadata:
  name: test2
spec:
  config: '{
    "cniVersion": "0.3.1",
    "plugins": [
    {
       (snip)
    },
    {
        "type" : "route-override",
        "addroutes": [
        {
            "dst": "10.123.123.1/32",
        }]
    }
    ]
}

CNI config does not know the device name because interface name is assigned dynamically at pod creation. User may create another pod as following. At that time, interfaces are created with different name from previous one such as:

  • "test1" creates "br0"
  • "test2" creates "br2"
  • "test3" creates "veth1"
apiVersion: v1
kind: Pod
metadata:
  name: centos2
  annotations:
    k8s.v1.cni.cncf.io/networks: '[
            { "name": "test1", "interface": "br0" },
            { "name": "test2", "interface": "br2" },
            { "name": "test3", "interface": "veth1" }
    ]'
spec:
(snip)

If the interface is created outside of CNI (e.g. initContainer creates some interface), then CNI cannot touch the interface because CNI can change configuration of the interface created by CNI. At that time, you need to change it in another way (e.g. ip route command in initContainer).

Does it make sense?

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

2 participants