Creating Your First Service
When you create a new service, you'll need to create a new Pulumi project for that service. This pulumi project will import helper functions from libs/infrastructure-components
.
To create a new Pulumi project, run:
Create a new directory in your service's directory
$ mkdir infrastructure && cd infrastructure
$ pulumi new
Select
kubernetes-go
, although this doesn't matter too much.Enter a name for your infrastructure project, preferably matching the directory for your service, for example:
auth-service
.Enter a stack name for your service, for instance
auth-service
again is good enough.
You should now see a main.go
file and a Pulumi.yaml
file.
The Pulumi.yaml file we can ignore, this is just the information you've already entered for future reference.
The main.go
file is where most of the magic happens.
For a ready-to-go microservice set-up, using the libs/infrastructure-components
library, replace the main.go files's contents with the following:
package main
import (
"github.com/pingponglabs/mediamagic-platform/libs/infrastructure-components/scaffold"
)
func main() {
scaffold.Run("./service.yaml")
}
Scaffold is a useful package, which converts a minimal YAML file into all the components needed to run and expose a docker container within the Kubernetes cluster.
You might be thinking 'yaml? Haven't we gone full circle?' well, yes... kind of. But if you compare the yaml for this service, v.s. the yaml for a regular kubernetes config, you'll see the difference.
Now create a config file: $ touch service.yaml
.
- dockerpath: "../"
name: "deployment-service"
namespace: "mediamagic-dev"
project: "mediamagic-core-ewanv"
type: "grpc"
env:
MEDIA_GRPC_ADDR: "upload-service:9000"
command:
- "./service"
- "service"
ports:
grpc: 9000
database: "deployment_service"
This example creates:
A Deployment with sensible default, such as three containers running for redundancy, for example.
A Docker image which is built from your local path (see
dockerpath
), which is automatically built, pushed to Google Container Registry and attached to the deployment.A Service, which is automatically configured to use the ports set to match your deployment.
Configuration to access and expose the database connection to your service, as well as Redis.
Using Terraform, or Kubernetes Yaml specs, this would be incredibly repetative and verbose. Using Pulumi reduces this down to our own much simpler config file, which builds and creates not just the Kubernetes resources, but also manages the docker image building and pushing process.
Last updated