Open vduduh opened 4 years ago
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
...
How to add static IP address to pod with annotations fields? Example: