1
votes

My high-level architecture is described in Cloud Endpoints for gRPC.

The Server below is a Compute Engine instance with Docker installed, running two containers (the ESP, and my server):

enter image description here

As per Getting started with gRPC on Compute Engine, I SSH into the VM and install Docker on the instance (see Install Docker on the VM instance). Finally I pull down the two Docker Containers (ESP and my server) and run them.

I've been reading around Container-Optimized OS from Google.

Rather than provisioning an instance with an OS and then installing Docker, I could just provision the OS with a Container-Optimized OS, and then pull-down my containers and run them.

However the only gRPC tutorials are for gRPC on Kubernetes Engine, gRPC on Kubernetes, and gRPC on Compute Engine. There is no mention of Container OS.

Has anyone used Container OS with gRPC, or can anyone see why this wouldn't work?

Creating an instance for advanced scenarios looks relevant because it states:

Use this method to [...] deploy multiple containers, and to use cloud-init for advanced configuration.

For context, I'm trying to move to CI/CD in Google Cloud, and removing the need to install Docker would be a step in that direction.

1

1 Answers

0
votes

You can basically follow almost the same instructions in the Getting started with gRPC on Compute Engine guide to deploy your gRPC server with the ESP on Container-Optimized OS. In your case, just see Container-Optimized OS as an OS with pre-installed Docker (there are more features but, in your case, only this one is interesting).

It is possible to use cloud-init if you want to automate the startup of your Docker containers (gRPC server + ESP) when the VM instance starts. The following cloud-init.cfg file automates the startup of the same containers presented in the documentation examples (with bookstore sample app). You can replace the Creating a Compute Engine instance part with two steps.

Create a cloud-init config file

Create cloud-init.cfg with the following content :

#cloud-config

runcmd:
- docker network create --driver bridge esp_net
- docker run 
    --detach
    --name=bookstore
    --net=esp_net
    gcr.io/endpointsv2/python-grpc-bookstore-server:1
- docker run
    --detach
    --name=esp
    --net=esp_net
    --publish=80:9000
    gcr.io/endpoints-release/endpoints-runtime:1
    --service=bookstore.endpoints.<YOUR_PROJECT_ID>.cloud.goog
    --rollout_strategy=managed
    --http2_port=9000
    --backend=grpc://bookstore:8000

Just after starting the instance, cloud-init will read this configuration and :

  • create a Docker network (esp_net)
  • run the bookstore container
  • run the ESP container. In this container startup command, replace <YOUR_PROJECT_ID> with your project ID (or replace the whole --service option depending on your service name)

Create a Compute Engine instance with Container-Optimized OS

You can create the instance from the Console, or via the command-line :

gcloud compute instances create instance-1 \
    --zone=us-east1-b \
    --machine-type=n1-standard-1 \
    --tags=http-server,https-server \
    --image=cos-73-11647-267-0 \
    --image-project=cos-cloud \
    --metadata-from-file user-data=cloud-init.cfg

The --metadata-from-file will populate user-data metadata with the contents of cloud-init.cfg. This cloud-init config will be taken into account when the instance will start.

You can validate this works by :

  • SSHing into instance-1, and running docker ps to see your running containers (gRPC server + ESP). You may experience some delay between the startup of your instance and the startup of both containers
  • calling your gRPC service with a client. For example (always with the bookstore application presented in the docs) :
INSTANCE_IP=$(gcloud compute instances describe instance-1 --zone us-east1-b --format="value(network_interfaces[0].accessConfigs.natIP)")
python bookstore_client.py --host $INSTANCE_IP --port 80 # returns a valid response

Note that you can also choose to not use cloud-init. You can directly run the docker run commands (the same as in cloud-init.cfg file) on your VM with Container-Optimized OS, exactly like you would do on any other OS.