Description
Terraform’s host_network = true shares the node’s IP address and ports with the Pod. For ordinary workloads, use false and configure the access you need through a Service or Ingress.
Potential impact
A service listening on a node interface can conflict with another service or be reachable from unintended networks. Its reach depends on routing and firewalls.
Remediation
For a system workload that needs host networking, check the listening addresses and ports, firewall and authentication. NetworkPolicy behavior for host-network Pods depends on the network plugin.
Examples
Both excerpts use the historical nginx:1.7.9 image. Select a maintained image for deployment.
Before
resource "kubernetes_pod" "pod" {
metadata {
name = "terraform-example"
}
spec {
host_network = true
container {
image = "nginx:1.7.9"
name = "example"
}
}
}
After
resource "kubernetes_pod" "pod" {
metadata {
name = "terraform-example"
}
spec {
host_network = false
container {
image = "nginx:1.7.9"
name = "example"
}
}
}
The second Pod uses its own network namespace. Check which clients can still reach it through your Service or Ingress.