Use Cloud Deployment Manager to define a Container-Optimized OS instance template

6/19/2017

I use google deployment manager to create:

  • an instance template
  • an instance group manager
  • an autoscaler

This works like a charm (I used this tutorial). However, I fail to define an instance template that runs a docker container (fwiw: the google cloud web console looks as that when one creates such an instance template).

I tried several things (some might be dumb):

  1. Take a look at the description of the working instance template and try to reproduce it.

    • use command gcloud compute instance-templates describe <working-template> to get an extensive definition of the working instance template
    • Define an instance template that matches the working instance template
    • Do a test deploy
    • SSH into spawned instance, confirm that target image is not pulled
  2. Do not use Container-Optimized OS (aka. copy this example )

    • In the yaml replace spec containers image by my gcr.io hosted docker image.
    • Do a test deploy.
    • SSH into spawned instance, confirm that target image is not pulled.
  3. Confirm that something is wrong with previous approaches: get the gcloud console util command, duplicate the working instance template. Update the deployment so that the instance group uses this manually copied instance template.

    • Do a test deploy.
    • SSH into spawned instance, confirm that target image is not pulled.
  4. Confirm that the google deployment manager is not messing around.

    • Update the deployment so that the instance group uses the working instance template.
    • Do a test deploy.
    • SSH into spawned instance, confirm all works as expected.

Am I going in the wrong direction here ?

-- François Kawala
google-cloud-platform
google-deployment-manager
google-kubernetes-engine

1 Answer

6/20/2017

To make it work with Container-Optimized OS I defined a template with a metadata "user-data" that contains a "cloud-config" file that creates a systemd service that runs the expected container.

I published the result on gist, to make it work you'll have to (a) specify the dockerImage in the deploy.yaml file and (b) if you need special scopes update set them in instance_template.py along with your developer.gserviceaccount.com account.

Hope it helps.

-- François Kawala
Source: StackOverflow