kubeformation

Google Kubernetes Engine (GKE)

For GKE clusters, Kubeformation creates Google Cloud Deployment Manager templates (GCDM). These templates can be used with gcloud command line tool to create the Kubernetes cluster. Further edits to the templates can also be applied using gcloud cli. If volumes are present, a corresponding Kubernetes Persistent Volume and Claim objects are also created, along with underlying Persistent Disk.

The provider string is gke.

Pre-requisites

Step 0 - Write cluster.yaml

PS: This step can be skipped if kubeformation.sh is used. Jump right ahead to Step 1.

Here’s an example cluster.yaml:

version: v1
name: my-cluster
provider: gke
k8sVersion: 1.9
nodePools:
- name: pool-1
  type: n1-standard-1
  size: 2
  labels:
    app: my-app
volumes:
- name: my-vol
  size: 10

Step 1 - Generate GCDM template

Download the template from kubeformation.sh

or

Generate the template using CLI:

$ mkdir templates
$ kubeformation -f cluster.yaml -o templates

This will give us the following files:

Step 2 - Add parameters

The following parameters which are provider specific need to be added:

Open gke-cluster.yaml file and add the required GCP zone and project name by replacing ZONE and PROJECT:

imports:
- path: gke-cluster.jinja

resources:
- name:  my-cluster
  type: gke-cluster.jinja
  properties:
    name: my-cluster
    project: PROJECT
    zone: ZONE

Step 3 - Create the cluster

Create the cluster (and any disks) as defined by gke-cluster.yaml:

$ gcloud deployment-manager deployments create my-cluster --config gke-cluster.yaml

That’s it! The GKE cluster will be created.

Get kubectl context to connect to the cluster:

$ gcloud container clusters get-credentials my-cluster --zone <zone> --project <project>

Step 4 - Create K8s Persistent Volumes

If the cluster spec also contains volumes, along with underlying disks, the Kubernetes PV & PVC objects also have to be created, so that the disks can be used by other k8s deployments etc.

$ kubectl create -f k8s-volumes.yaml

Tearing down

Delete the deployment to tear down the cluster (and disks):

$ gcloud deployment-manager deployments delete my-cluster