GKE: running microservices in Go
Since running applications inside containers and abstracting away infrastructure provisioning from application development process has become way too complex, I am spicing up a guide to ease this experience for you.
We’ll be using docker for infrastructure provisioning, kubernetes for container management, Go for backend development and GKE as a cloud kubernetes service
Google Kubernetes Engine a.k.a GKE
GKE is a full-fledged service that allows deploying docker images to kubernetes engine that can scale and managed with easy.
Our Dockerfile will look like the above:
From could use — platform flag to specify the platform of the image
And a basic http service will be written as follow:
Artifact registry
We need a way to store our binary images in a way to make it easy to deploy to a Cloud platform. GCP provide artifact registry that replaces Container registry.
The reason behind building and pushing to artifact registry all in the same command is that, if you do not supply — push parameter, docker will not attempt to generate the manifest and push it to a docker registry. On the other hand, a local docker repository can’t serve multi-arch images behind one manifest. Therefore, the built result will be simply discarded.
BUT life is not easy, you know? and developing this microservice was not the exception
Leverage multi-CPU architecture support
Written this tiny service points me to a interesting problem, building the Image into my local machine that has different kernel architecture as in the cloud platform virtual machine instance.
In general, you can’t run docker images that target a different processor architecture than your hose system. However, you can run Linux architectures like ARM64 on Windows using Docker Desktop. Docker Desktop uses the qemu-static emulator to make this cross-architecture emulation completely seamless!
So it come to my existence buildx. A tool for multi-architecture support.