<p>Currently we have our kubernetes cluster master set to zonal, and require it to be regional. My idea is to convert the existing cluster and all workloads/nodes/resources to some infrastructure-as-code - preferably terraform (but could be as simple as a set of <code>gcloud</code> commands).</p>

<p>I know with GCP I can generate raw command lines for commands I'm about to run, but I don't know how (or if I even can) to convert existing infrastructure to the same.</p>

<p>Based on my research, it looks like it isn't exactly possible to do what I'm trying to do [in a straight-forward fashion]. So I'm looking for any advice, even if it's just to read some other documentation (for a tool I'm not familiar with maybe).</p>

<p>TL;DR: I'm looking to take my existing Google Cloud Platform Kubernetes cluster and rebuild it in order to change the location type from zonal to master - I don't actually care how this is done. What is a currently accepted best-practice way of doing this? If there isn't one, what is a quick and dirty way of doing this?</p>

<p>If you require me to specify further, I will - I have intentionally left out linking to specific research I've done.</p>

<p>Creating a Kubernetes cluster with terraform is very straightforward because ultimately making a Kubernetes cluster in GKE is straightforward, you'd just use the <code>google_container_cluster</code> and <code>google_container_node_pool</code> resources, like so:</p>

<pre><code>resource "google_container_cluster" "primary" {
  name               = "${var.name}"
  region             = "${var.region}"
  project            = "${var.project_id}"
  min_master_version = "${var.version}"

  addons_config {
    kubernetes_dashboard {
      disabled = true
    }
  }

  maintenance_policy {
    daily_maintenance_window {
      start_time = "03:00"
    }
  }

  lifecycle {
    ignore_changes = ["node_pool"]
  }

  node_pool {
    name = "default-pool"
  }
}

resource "google_container_node_pool" "default" {
  name    = "default"
  project = "${var.project_id}"
  region  = "${var.region}"
  cluster = "${google_container_cluster.primary.name}"

  autoscaling {
    min_node_count = "${var.node_pool_min_size}"
    max_node_count = "${var.node_pool_max_size}"
  }

  management {
    auto_repair  = "${var.node_auto_repair}"
    auto_upgrade = "${var.node_auto_upgrade}"
  }

  lifecycle {
    ignore_changes = ["initial_node_count"]
  }

  node_config {
    machine_type = "${var.node_machine_type}"

    oauth_scopes = [
      "https://www.googleapis.com/auth/cloud-platform",
    ]
  }

  depends_on = ["google_container_cluster.primary"]
}
</code></pre>

<p>For a more fully featured experience, there are terraform modules available like <a href="https://github.com/google-terraform-modules/terraform-google-kubernetes-engine" rel="nofollow noreferrer">this one</a></p>

<p>Converting an existing cluster is considerably more fraught. If you want to use <code>terraform import</code></p>

<pre><code>terraform import google_container_cluster.mycluster us-east1-a/my-cluster
</code></pre>

<p>However, in your comment , you mentioned wanting to convert a zonal cluster to a regional cluster. Unfortunately, <a href="https://cloud.google.com/kubernetes-engine/docs/concepts/regional-clusters" rel="nofollow noreferrer">that's not possible</a> at this time</p>

<blockquote>
  <p>You decide whether your cluster is zonal or regional when you create
  it. You cannot convert an existing zonal cluster to regional, or vice
  versa.</p>
</blockquote>

<p>Your best bet, in my opinion, is to:</p>

<ul>
<li>Create a regional cluster with terraform, giving the cluster a new name</li>
<li>Backup your existing zonal cluster, either using an etcd backup, or a more sophisticated backup using <a href="https://github.com/heptio/ark" rel="nofollow noreferrer">heptio-ark</a></li>
<li>Restore that backup to your regional cluster</li>
</ul>
