0

I encounter a issue: 1) declare hostNetwork=true for POD in a deployment, and create the deployment. 2) Declare a service with nodePort to the deployment pods

I found the nodePort cannot be accessed by serviceClusterIP:nodePort in the host which the pod is not running on.

While I remove hostnetwork=true, the serviceClusterIP:nodePort can be accessed by any host node in the cluster.

What's the worong?

My kubernetes version is listed below, I am using weave net.

# kubectl version
Client Version: version.Info{Major:"1", Minor:"5", GitVersion:"v1.5.1", GitCommit:"82450d03cb057bab0950214ef122b67c83fb11df", GitTreeState:"clean", BuildDate:"2016-12-14T00:57:05Z", GoVersion:"go1.7.4", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"5", GitVersion:"v1.5.0", GitCommit:"58b7c16a52c03e4a849874602be42ee71afdcab1", GitTreeState:"clean", BuildDate:"2016-12-12T23:31:15Z", GoVersion:"go1.7.4", Compiler:"gc", Platform:"linux/amd64"}
Bo Wang
  • 499
  • 1
  • 8
  • 15

1 Answers1

2

In Kubernetes, nodePort is a mechanism to map a port on a pod's network interface out to a port on all nodes.

The normal case, when you don't say hostNetwork=true is that each pod has its own "network namespace" - it has its own virtual network device with a unique IP address and it has a localhost interface on 127.0.0.1 that is shared by all containers in the pod.

When you ask for your pod to use the host's network interface by saying hostNetwork=true, it has none of the above; it just uses the host network devices. And the nodePort mechanism is not available in this mode.

Possibly there is an error message somewhere to tell you about this - look in kubectl events or in kubelet's log file. If you cannot find an error anywhere please file this fact as a bug against Kubernetes.

Bryan
  • 11,398
  • 3
  • 53
  • 78
  • Thanks. my understanding is: 1) nodePort is to expose service with specified node and nodePort; 2) hostNetwork is to run the pod in the node it is running on. if a pod is running at host network model, but a service can expose some of the port to be the service node port, am I right? – Bo Wang Feb 27 '17 at 13:27
  • "nodePort is to expose service with specified node" - no, it exposes on _all_ nodes. I linked to the docs. Also I expanded my answer to describe hostNetwork vs normal pod networking. – Bryan Mar 03 '17 at 11:56