<p>I want to share a volume across pods in a node in GKE.</p>
<p>I am using Terraform to provision all of this and using GKE autoscaling but no auto-provsioning.</p>
<pre><code>cluster_autoscaling {
    enabled             = false
    autoscaling_profile = var.aggresive_node_autoscale ? &quot;OPTIMIZE_UTILIZATION&quot; : &quot;BALANCED&quot;
  }
</code></pre>
<p>Which means we will not get new node-pools created by GKE, just new nodes from the existing pools. Right?</p>
<p>My original idea was to attach a volume per node and then share that by creating a persistent volume.</p>
<p>I have failed to mount to such disks, so now I am trying to use the boot disk from the nodes.</p>
<p>From the <a href="https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/container_cluster#nested_node_config" rel="nofollow noreferrer">documentation</a> I understand that we can setup SSD disks as boot disk</p>
<pre><code>    disk_size_gb = 256
    disk_type = &quot;pd-ssd&quot;
</code></pre>
<p>And I want to make this boot disk usable as a <a href="https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/persistent_volume_v1#local" rel="nofollow noreferrer">Local Persistent Volume</a></p>
<p>From what I see, the boot disk have the same name as the node pool, so I can use that to reference them</p>
<pre><code>data &quot;google_compute_disk&quot; &quot;gke_boot_disk&quot; {
  name    = google_container_node_pool.cpu_pool_n2_highmem_8.name
  project = local.project_id
  zone    = var.google_zone
}
</code></pre>
<p>And then how would I actually create the persistent disk?</p>
<p>Should I approach this in a different way? Do you have any recommendations or a good read for how to share a local SSD across pods of a node in GKE?</p>
<p>Thank you.</p>

chamini2
<blockquote>
<p>Sharing a local volume across pods in GKE with autoscaling</p>
</blockquote>
<p>Sharing a local volume across pods in GKE with auto scaling is impossible as the Autoscaler cluster has some <a href="https://cloud.google.com/kubernetes-engine/docs/concepts/cluster-autoscaler#limitations" rel="nofollow noreferrer">limitations</a> in which Local PersistentVolumes are currently not supported by cluster autoscaler.</p>
<p>If you are using Pods tied to a node lifecycle, make sure to plan accordingly as your workloads may be disrupted during cluster maintenance and node upgrades. If you require persistent storage, consider using <a href="https://cloud.google.com/filestore/docs/accessing-fileshares" rel="nofollow noreferrer">Filestore</a> instead.</p>
<blockquote>
<p>How would I actually create the persistent disk and share a local SSD
across pods?</p>
</blockquote>
<p>Local SSDs can be specified as <a href="https://cloud.google.com/kubernetes-engine/docs/concepts/persistent-volumes" rel="nofollow noreferrer">PersistentVolumes</a>. A local persistent volume represents a local disk that is attached to a single node. Local persistent volumes allow you to share local SSDs across Pods. The data is still ephemeral. You can create PersistentVolumes from local SSDs by manually creating a PersistentVolume, or by running the local volume static provisioner.</p>
<p>Refer to this <a href="https://cloud.google.com/kubernetes-engine/docs/how-to/persistent-volumes/local-ssd#pv" rel="nofollow noreferrer">document</a> for creating the PersistentVolume manually for each local SSD on each node in your cluster.</p>
<p>We recommend this approach if any of the following run on your cluster:</p>
<ul>
<li>Workloads using StatefulSets and volumeClaimTemplates.</li>
<li>Workloads that share node pools. Each local SSD can be reserved through a PersistentVolumeClaim, and specific host paths are not encoded directly in the Pod spec.</li>
</ul>
<p>A GKE node pool can be configured to use local SSD for <a href="https://cloud.google.com/kubernetes-engine/docs/how-to/persistent-volumes/local-ssd#example_ephemeral" rel="nofollow noreferrer">ephemeral storage</a>, including <a href="https://cloud.google.com/kubernetes-engine/docs/concepts/local-ssd#emptydir-volume" rel="nofollow noreferrer">emptyDir volumes</a>. If you are using GKE with Standard clusters, you can attach local SSDs to nodes when creating node pools. This improves the performance of ephemeral storage for your workloads that use emptyDir volume.</p>
