<p>I am trying to create PV/PVC on a <code>kubernetes</code> GKE cluster using <code>Terraform</code></p>

<p>However the <a href="https://www.terraform.io/docs/providers/kubernetes/r/persistent_volume.html" rel="nofollow noreferrer">documentation</a> does not <a href="https://www.terraform.io/docs/providers/kubernetes/r/persistent_volume_claim.html" rel="nofollow noreferrer">mention</a> how can one specify the <code>namespace</code> that these resources should be created in.</p>

<p>I have tried adding it both in the <code>spec</code> and the <code>metadata</code> section but I get an error message:</p>

<pre><code>resource "kubernetes_persistent_volume" "jenkins-persistent-volume" {
  metadata {
    name = "${var.kubernetes_persistent_volume_metadata_name}"
    # tried placing it here --&gt;&gt; namespace = "${var.kubernetes_jenkins_namespace}"

  }
  spec {
    # tried placing it here --&gt;&gt; namespace = "${var.kubernetes_jenkins_namespace}"
    capacity = {
      storage = "${var.kubernetes_persistent_volume_spec_capacity_storage}"
    }
    storage_class_name = "standard"
    access_modes = ["ReadWriteMany"]
    persistent_volume_source {
      gce_persistent_disk {
        fs_type = "ext4"
        pd_name = "${google_compute_disk.jenkins-disk.name}"
      }
    }
  }
}
</code></pre>

<blockquote>
  <p>Error: module.jenkins.kubernetes_persistent_volume.jenkins-persistent-volume: spec.0: invalid or unknown key: namespace</p>
</blockquote>

<p>Where such a configuration be placed?</p>

pkaramol
<p><a href="https://kubernetes.io/docs/concepts/storage/persistent-volumes/" rel="nofollow noreferrer">Persistent volumes</a> are cluster-global objects and do not live in specific namespaces.  ("It is a resource in the cluster just like a node is a cluster resource.")  Correspondingly you can't include a namespace name anywhere on a <code>kubernetes_persistent_volume</code> resource.</p>

<p>If you're running in a cloud environment (and here your PV is creating a Google storage volume) its typical to only create a persistent volume claim, and let the cluster allocate the underlying volume for you.  PVCs <em>are</em> namespace-scoped, and the Terraform <a href="https://www.terraform.io/docs/providers/kubernetes/r/persistent_volume_claim.html" rel="nofollow noreferrer"><code>kubernetes_persistent_volume_claim</code> resource</a> explicitly <a href="https://www.terraform.io/docs/providers/kubernetes/r/persistent_volume_claim.html#namespace" rel="nofollow noreferrer">documents</a> that you can include a <code>namespace</code> in the <code>metadata</code> block.</p>
