If a pod runs in the host network of the node where the pod is deployed, the pod can use the network namespace and network resources of the node. In this case, 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.The following example shows the YAML file:
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 runs in the host network of the
node where the pod is deployed:
kubectl get pod -o wideThe command output shows that the IP address of the pod is the same as that of the node. This indicates that the pod runs 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>