Review container image pull policies

Choose a pull policy that matches image identification and registry availability requirements.

Description

image_pull_policy takes effect when a container starts. With IfNotPresent and a mutable tag, different nodes can run different cached images.

Potential impact

A cached image can miss a patch. A policy that checks the registry can prevent startup if the registry is unavailable or authentication fails.

Remediation

Use image_pull_policy = "Always" to check the tag at every start. IfNotPresent is also suitable with a verified digest. Review provenance and vulnerabilities, then redeploy tested updates. Check the effective policy and registry access.

Examples

Both Pods use busybox with the implicit latest tag. Supply a maintained image and any required registry credentials for deployment.

Before

hcl
resource "kubernetes_pod" "busybox" {
  metadata {
    name = "busybox-tf"
  }

  spec {
    container {
      image             = "busybox"
      command           = ["sleep", "3600"]
      name              = "busybox"
      image_pull_policy = "IfNotPresent"
    }

    restart_policy = "Always"
  }
}

After

hcl
resource "kubernetes_pod" "busybox" {
  metadata {
    name = "busybox-tf"
  }

  spec {
    container {
      image             = "busybox"
      command           = ["sleep", "3600"]
      name              = "busybox"
      image_pull_policy = "Always"
    }

    restart_policy = "Always"
  }
}

The first Pod can use a local image. The second checks the digest at startup and reuses matching layers. Both use the same restart_policy, and running containers are not updated automatically.

References