If a pod is running in the host network of the node where the pod resides, the pod can use the network namespace and network resources of the node. This means that the pod can access loopback devices, listen to addresses, and monitor the traffic of other pods on the node.
- Open the YAML file host-network.yaml and set
hostNetworkto true under spec.A complete example of the YAML file is as follows:
apiVersion: v1 kind: Pod metadata: name: nginx spec: hostNetwork: true containers: - name: nginx image: nginx
- Run the following command to create a pod:
kubectl apply -f host-network.yaml
- Run the following command to check whether the pod is running in the host network
of the node where the pod resides:
kubectl get pod -o wideIf the IP address of the pod is the same as that of the node according to the command output, the pod is running in the host network of the node.
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE nginx 1/1 Running 0 29s 192.168.XX.XX cn-zhangjiakou.192.168.XX.XX <none>