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

macvlan static pod IP address #200

Open
vduduh opened this issue Jan 18, 2020 · 1 comment
Open

macvlan static pod IP address #200

vduduh opened this issue Jan 18, 2020 · 1 comment

Comments

@vduduh
Copy link

vduduh commented Jan 18, 2020

How to add static IP address to pod with annotations fields?
Example:

apiVersion: v1
kind: Pod
metadata:
  annotations:
    cni: macvlan,flannel
    multi-ip-preferences: '{"ips": {"macvlan":{"ip":"10.10.10.10"}}}'
  name: some-worker
spec:
  containers:
  - args:
@vduduh
Copy link
Author

vduduh commented Jan 21, 2020

Resolved.
Create network attachment definition:

---
apiVersion: "k8s.cni.cncf.io/v1"
kind: NetworkAttachmentDefinition
metadata:
  name: flannel-conf
spec: 
  config: '{
    "name": "cbr0",
    "cniVersion": "0.3.1",
    "plugins": [
      {
        "type": "flannel",
        "delegate": {
          "hairpinMode": true,
          "ipMasq": false,
          "isDefaultGateway": true
        }
      },
      {
        "type": "portmap",
        "capabilities": {
          "portMappings": true
        }
      }
    ]
  }'

Add annotation to pod:

    k8s.v1.cni.cncf.io/networks: |
      [
        {
          "name":"macvlan-conf",
          "interface": "eth1",
          "ips": ["{{ .pod_ip }}"]
        },
        {
          "name":"flannel-conf",
          "interface": "eth2"
        }
      ]

BUT In fact, there will be three interfaces in the container, those that we specified, and the default interface specified in genie.
How to remove default from container?
Workaround:

...
spec:
  containers:
  - args:
    - -c
    - 'ip route replace default via $(ip r|egrep 18.*via.*eth2|cut -f 3 -d" "); /sbin/init'
    command:
    - /bin/sh
    securityContext:
      privileged: true // not secure
...

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

1 participant