kubernetes_pod_v1

A pod is a group of one or more containers, the shared storage for those containers, and options about how to run the containers. Pods are always co-located and co-scheduled, and run in a shared context.

Read more at Kubernetes reference

Example Usage

resource "kubernetes_pod_v1" "test" {
  metadata {
    name = "terraform-example"
  }

  spec {
    container {
      image = "nginx:1.21.6"
      name  = "example"

      env {
        name  = "environment"
        value = "test"
      }

      port {
        container_port = 80
      }

      liveness_probe {
        http_get {
          path = "/"
          port = 80

          http_header {
            name  = "X-Custom-Header"
            value = "Awesome"
          }
        }

        initial_delay_seconds = 3
        period_seconds        = 3
      }
    }

    dns_config {
      nameservers = ["1.1.1.1", "8.8.8.8", "9.9.9.9"]
      searches    = ["example.com"]

      option {
        name  = "ndots"
        value = 1
      }

      option {
        name = "use-vc"
      }
    }

    dns_policy = "None"
  }
}

terraform version of the pods/pod-with-node-affinity.yaml example.

resource "kubernetes_pod_v1" "with_node_affinity" {
  metadata {
    name = "with-node-affinity"
  }

  spec {
    affinity {
      node_affinity {
        required_during_scheduling_ignored_during_execution {
          node_selector_term {
            match_expressions {
              key      = "kubernetes.io/e2e-az-name"
              operator = "In"
              values   = ["e2e-az1", "e2e-az2"]
            }
          }
        }

        preferred_during_scheduling_ignored_during_execution {
          weight = 1

          preference {
            match_expressions {
              key      = "another-node-label-key"
              operator = "In"
              values   = ["another-node-label-value"]
            }
          }
        }
      }
    }

    container {
      name  = "with-node-affinity"
      image = "k8s.gcr.io/pause:2.0"
    }
  }
}

terraform version of the pods/pod-with-pod-affinity.yaml example.

resource "kubernetes_pod_v1" "with_pod_affinity" {
  metadata {
    name = "with-pod-affinity"
  }

  spec {
    affinity {
      pod_affinity {
        required_during_scheduling_ignored_during_execution {
          label_selector {
            match_expressions {
              key      = "security"
              operator = "In"
              values   = ["S1"]
            }
          }

          topology_key = "failure-domain.beta.kubernetes.io/zone"
        }
      }

      pod_anti_affinity {
        preferred_during_scheduling_ignored_during_execution {
          weight = 100

          pod_affinity_term {
            label_selector {
              match_expressions {
                key      = "security"
                operator = "In"
                values   = ["S2"]
              }
            }

            topology_key = "failure-domain.beta.kubernetes.io/zone"
          }
        }
      }
    }

    container {
      name  = "with-pod-affinity"
      image = "k8s.gcr.io/pause:2.0"
    }
  }
}

Argument Reference

The following arguments are supported:

Nested Blocks

metadata

Arguments

Attributes

spec

Arguments

affinity

Arguments

node_affinity

Arguments

required_during_scheduling_ignored_during_execution

Arguments

node_selector_term

Arguments

match_expressions / match_fields

Arguments

preferred_during_scheduling_ignored_during_execution

Arguments

preference

Arguments

match_expressions / match_fields

Arguments

pod_affinity

Arguments

pod_anti_affinity

Arguments

required_during_scheduling_ignored_during_execution (pod_affinity_term)

Arguments

preferred_during_scheduling_ignored_during_execution

Arguments

os

Arguments

container

Arguments

aws_elastic_block_store

Arguments

azure_disk

Arguments

azure_file

Arguments

capabilities

Arguments

ceph_fs

Arguments

cinder

Arguments

config_map

Arguments

config_map_ref

Arguments

config_map_key_ref

Arguments

dns_config

Arguments

The option block supports the following:

downward_api

Arguments

empty_dir

Arguments

env

Arguments

env_from

Arguments

exec

Arguments

fc

Arguments

field_ref

Arguments

flex_volume

Arguments

flocker

Arguments

gce_persistent_disk

Arguments

git_repo

Arguments

glusterfs

Arguments

grpc

Arguments

host_aliases

Arguments

host_path

Arguments

http_get

Arguments

http_header

Arguments

image_pull_secrets

Arguments

iscsi

Arguments

items

Arguments

lifecycle

Arguments

liveness_probe

Arguments

nfs

Arguments

persistent_volume_claim

Arguments

photon_persistent_disk

Arguments

port

Arguments

post_start

Arguments

pre_stop

Arguments

quobyte

Arguments

rbd

Arguments

readiness_probe

Arguments

resources

Arguments

resources is a computed attribute and thus if it is not configured in terraform code, the value will be computed from the returned Kubernetes object. That causes a situation when removing resources from terraform code does not update the Kubernetes object. In order to delete resources from the Kubernetes object, configure an empty attribute in your code.

Please, look at the example below:

resources {
  limits   = {}
  requests = {}
}

resource_field_ref

Arguments

seccomp_profile

Attributes

se_linux_options

Arguments

secret

Arguments

The items block supports the following:

secret_ref

Arguments

secret_key_ref

Arguments

secret_ref

Arguments

container security_context

Arguments

Sysctl

capabilities

Arguments

pod security_context

Arguments

tcp_socket

Arguments

toleration

Arguments

topology_spread_constraint

Arguments

value_from

Arguments

projected

Arguments

sources

Arguments

service_account_token

Arguments

volume

Arguments

volume_mount

Arguments

vsphere_volume

Arguments

ephemeral

Arguments

volume_claim_template

Arguments

readiness_gate

Arguments

Timeouts

The following Timeout configuration options are available for the kubernetes_pod_v1 resource:

Import

Pod can be imported using the namespace and name, e.g.

$ terraform import kubernetes_pod_v1.example default/terraform-example