Kubernetes: How to configure hostnetwork pod IP address?

3/11/2019

I am trying to setup an IPv6 kubernetes cluster. I have two IPv6 interfaces and one docker interface (172.17.0.1). The docker interface is setup by docker itself.

kahou@kahou-master:~$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: ens192: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:50:56:af:1d:25 brd ff:ff:ff:ff:ff:ff
    inet6 2001:420:293:242d:250:56ff:feaf:1d25/64 scope global dynamic mngtmpaddr noprefixroute
       valid_lft 2591949sec preferred_lft 604749sec
    inet6 fe80::250:56ff:feaf:1d25/64 scope link
       valid_lft forever preferred_lft forever
3: ens224: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:50:56:af:a5:15 brd ff:ff:ff:ff:ff:ff
    inet6 2000::250:56ff:feaf:a515/64 scope global dynamic mngtmpaddr noprefixroute
       valid_lft 2591933sec preferred_lft 604733sec
    inet6 2000::3/64 scope global
       valid_lft forever preferred_lft forever
    inet6 fe80::250:56ff:feaf:a515/64 scope link
       valid_lft forever preferred_lft forever
4: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
    link/ether 02:42:53:f2:46:8c brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
       valid_lft forever preferred_lft forever
5: tunl0@NONE: <NOARP,UP,LOWER_UP> mtu 1440 qdisc noqueue state UNKNOWN group default qlen 1000
    link/ipip 0.0.0.0 brd 0.0.0.0

When I initialize my cluster thru kubeadm, all the hostnetwork pods IP are using the docker IP addresses:

etcd-kahou-master                          1/1     Running             0          177m   172.17.0.1   kahou-master   <none>
kube-apiserver-kahou-master                1/1     Running             0          177m   172.17.0.1   kahou-master   <none>
kube-controller-manager-kahou-master       1/1     Running             0          177m   172.17.0.1   kahou-master   <none>
kube-proxy-pnq7g                           1/1     Running             0          178m   172.17.0.1   kahou-master   <none>
kube-scheduler-kahou-master                1/1     Running             0          177m   172.17.0.1   kahou-master   <none>

Is it possible to tell kubeadm which interface I use during the installation?

Below is my api-server call (generated by kubeadm)

kube-apiserver --authorization-mode=Node,RBAC --bind-address=2001:420:293:242d:250:56ff:feaf:1d25 --service-cluster-ip-range=fd03::/112 --advertise-address=2001:420:293:242d:250:56ff:feaf:1d25 --allow-privileged=true --client-ca-file=/etc/kubernetes/pki/ca.crt --enable-admission-plugins=NodeRestriction --enable-bootstrap-token-auth=true --etcd-cafile=/etc/kubernetes/pki/etcd/ca.crt --etcd-certfile=/etc/kubernetes/pki/apiserver-etcd-client.crt --etcd-keyfile=/etc/kubernetes/pki/apiserver-etcd-client.key --etcd-servers=https://127.0.0.1:2379 --insecure-port=0 --kubelet-client-certificate=/etc/kubernetes/pki/apiserver-kubelet-client.crt --kubelet-client-key=/etc/kubernetes/pki/apiserver-kubelet-client.key --kubelet-preferred-address-types=InternalIP,ExternalIP,Hostname --proxy-client-cert-file=/etc/kubernetes/pki/front-proxy-client.crt --proxy-client-key-file=/etc/kubernetes/pki/front-proxy-client.key --requestheader-allowed-names=front-proxy-client --requestheader-client-ca-file=/etc/kubernetes/pki/front-proxy-ca.crt --requestheader-extra-headers-prefix=X-Remote-Extra- --requestheader-group-headers=X-Remote-Group --requestheader-username-headers=X-Remote-User --secure-port=6443 --service-account-key-file=/etc/kubernetes/pki/sa.pub --tls-cert-file=/etc/kubernetes/pki/apiserver.crt --tls-private-key-file=/etc/kubernetes/pki/apiserver.key

This is my kubeadm config file:

apiVersion: kubeadm.k8s.io/v1alpha2
kind: MasterConfiguration
api:
  advertiseAddress: 2001:420:293:242d:250:56ff:feaf:1d25
apiServerExtraArgs:
  bind-address: 2001:420:293:242d:250:56ff:feaf:1d25
  service-cluster-ip-range: fd03::/112
controllerManagerExtraArgs:
  node-cidr-mask-size: "96"
  cluster-cidr: fd02::/80
  service-cluster-ip-range: fd03::/112
networking:
  serviceSubnet: fd03::/112
nodeRegistration:
  node-ip: 2001:420:293:242d:250:56ff:feaf:1d25
-- Kintarō
kubeadm
kubernetes

2 Answers

3/11/2019

You can configure this behavior using kubeadm config. Have you tried using --pod-network-cidr string. More details in official documents https://kubernetes.io/docs/reference/setup-tools/kubeadm/kubeadm-config/

-- Balkrishna
Source: StackOverflow

11/26/2019

A helpful note for configuring node-ip to be passed on to kubelet via kubeadm config file: according to https://godoc.org/k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta1 and some experimentation, it should be under kubeletExtraArgs of the nodeRegistration section (example using IP from your config file):

apiVersion: kubeadm.k8s.io/v1beta2
kind: InitConfiguration
nodeRegistration:
  kubeletExtraArgs:
    node-ip: 2001:420:293:242d:250:56ff:feaf:1d25
-- IG_
Source: StackOverflow