Sorry if the question is a bit abstract but I am currently getting into GCP.
First of all my goal - I want to set up automatic creation of kubernetes cluster with a number of pods.
What I have so far - I have past few days looking in the GCP and Kubernetes documentation as well as some examples. I have two working bits:
I have created a cluster config with yaml and jinja files and I can use deployment manager to set them up.
gcloud deployment-manager deployments create my-config --config my-config.yaml
I have created another configuration yaml file which uses a docker image stored in the GCP Container Registry to start some pods on the cluster above (which again works fine)
kubectl apply -f image-config.yaml --record
My question is is it possible to combine somehow the above into a single config file and start everything up with a single command? Or if you can point me in the direction of some appropriate example.
Yes that is entirely possible. You should combine the two config files in a multi-document YAML file, the first of which contains a sequence of commands to be executed on document two and following.
---
- gcloud deployment-manager deployments create my-config --config $doc2:my-config.yaml
- kubectl apply -f $doc3:image-config.yaml --record
---
<insert contents of my-config.yaml here>
---
<insert contents of image-config.yaml here>
A small program can load the documents, parse the sequence in the first doc, extract the name of the temporary file to write, dump the appropriate doc to that file, execute the command (removing $docN:
), remove the temporary file. My guess is that should be doable in about 15 lines of code.
The Agones project accomplishes this task using a combination of Terraform and Helm as described in the Install with Terraform documentation. There is a single command which builds a GKE cluster and also installs an application into the cluster (e.g. runs some pods).
If you don't want to use Helm and build a full installer for your pods, you can also look at using the Kubernetes Provider to run some simple applications once the cluster has been deployed (check out the google_container_cluster configuration in the GCP provider).