This repo provides pre-initialised versions of go-micro and the micro toolkit for kubernetes.
Services make use of the kubernetes registry plugin so there's zero external dependency for service discovery and the grpc plugins to make use of gRPC for communication.
Toolkit, go-micro initialisers and healthchecking sidecar:
- cmd/micro - a preinitialised version of the micro toolkit with the kubernetes registry
- go get github.com/micro/kubernetes/cmd/micro
- cmd/health - a healthchecking sidecar for kubernetes
- run in the pod and set a http healthcheck which calls your rpc service
- exposes /health http endpoint
- go/micro - a pre-initialiser for a go-micro service with k8s registry and grpc transport
- service := micro.NewService()
Example configs:
- config/micro - API, Web UI and Sidecar (spins up GCE Load Balancers)
- config/services - Some example micro services
Here's the steps I took to get started.
GKE is the easiest way to run a managed kubernetes cluster. What's even better? $300 free credit for 60 days.
- Get yourself a Free Trial of Google Container Engine
- Visit the Quickstart guide to create a cluster
We provide some predefined k8s configs with prebuilt micro images.
Make sure kubectl is in your path
./run.sh start
Write a service as you would any other go-micro service.
import (
"github.com/micro/go-micro"
k8s "github.com/micro/kubernetes/go/micro"
)
func main() {
service := k8s.NewService(
micro.Name("my.service")
)
service.Init()
service.Run()
}
Get a preinitialised version of the micro toolkit with the kubernetes registry
go get github.com/micro/kubernetes/cmd/micro
go get github.com/micro/micro
Create a plugins.go file
package main
import _ "github.com/micro/go-plugins/registry/kubernetes"
Build binary
// For local use
go build -i -o micro ./main.go ./plugins.go
Flag usage of plugins
micro --registry=kubernetes
Use the plugin with go-micro
package main
import (
_ "github.com/micro/go-plugins/registry/kubernetes"
"github.com/micro/go-micro"
)
func main() {
service := micro.NewService(
micro.Name("my.service"),
)
service.Init()
service.Run()
}
go run main.go --registry=kubernetes