Reputation: 31
I have a very simple program:
package main
import (
"fmt"
"github.com/vishvananda/netlink"
)
func main() {
_, err := netlink.LinkByName("wlp164s0")
if err != nil {
fmt.Println("error finding VIP Interface, for building DHCP Link : %v", err)
return
}
fmt.Println("Worked..")
}
If I create a docker image and run it with "--net host", this program prints "Worked". It is able to find the interface wlp164s0.
If I create a k8s deployment like this:
apiVersion: apps/v1
kind: Deployment
metadata:
name: netlink-example
labels:
app: netlink-example
spec:
replicas: 1
selector:
matchLabels:
app: netlink-example
template:
metadata:
labels:
app: netlink-example
spec:
hostNetwork: true
containers:
- name: netlink
image: suruti94/netlink:0.1
imagePullPolicy: IfNotPresent
hostNetwork: true
nodeSelector:
kubernetes.io/os: linux
This program prints the error indicating that it can't lookup the interface which means the "hostNetwork: true" is not taking effect. From all my research, this looks right. Any help would be appreciated. I am running this program on Ubuntu 21.04, k8s version 1.22.
Upvotes: 1
Views: 3391
Reputation: 31
After some experimentation, I have come to an understanding that the docker option "--net host" is not the same as "hostNetwork: true" in k8s. I wrongly assumed they produce similar behavior.
Upvotes: 1