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
.
gcloud
CLIkubeformation
CLI (optional)- A project on Google Cloud (check this link to create one)
kubectl
CLI
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
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:
gke-cluster.yaml
gke-cluster.jinja
k8s-volumes.yaml
(only ifvolumes
are present in the spec)
The following parameters which are provider specific need to be added:
ZONE
- GCP zone where the cluster has to be createdPROJECT
- GCP project
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
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>
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
Delete the deployment to tear down the cluster (and disks):
$ gcloud deployment-manager deployments delete my-cluster