go-micro kubernetes greeter example - unable to reach greeter api service

4/20/2018

I'm trying to get this go-micro greeter example working on Kubernetes https://github.com/micro/examples/tree/master/greeter

I can run this locally in docker fine. However when I attempt to access the greeter api service via Kubernetes (http://{{external-ip}}/greeter/say/hello), I get the error: {"id":"go.micro.api","code":500,"detail":"not found","status":"Internal Server Error"}

For the sake of troubleshooting I've simplified the scenario, I simply want to be able to make a call via the micro api to a go-micro api service. Below is my setup:

api.go

package main

import (
    "github.com/micro/go-micro"
    api "github.com/micro/micro/api/proto"
    "log"
    k8s "github.com/micro/kubernetes/go/micro"

    "context"
)

type Say struct {
}

//I just want to access this via the micro api on k8s via services external ip
func (s *Say) Hello(ctx context.Context, req *api.Request, rsp *api.Response) error {
    rsp.StatusCode = 200
    rsp.Body = "Hello"
    return nil
}

func main() {
    service := k8s.NewService(
        micro.Name("default.greeter-api"),
    )

    service.Init()

    service.Server().Handle(
        service.Server().NewHandler(
            &Say{},
        ),
    )

    if err := service.Run(); err != nil {
        log.Fatal(err)
    }
}

micro-api-deployment.yml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: micro
spec:
  replicas: 1
  selector:
    matchLabels:
      app: micro
  template:
    metadata:
      labels:
        app: micro
    spec:
        containers:
        - name: micro
          image: microhq/micro:kubernetes
          args:
            - "api"
            - "--handler=rpc"
            - "--namespace=default"
          env:
          - name: MICRO_API_ADDRESS
            value: ":80"
          ports:
          - containerPort: 80
            name: api-port

micro-api-svc.yml

apiVersion: v1
kind: Service
metadata:
  name: micro
spec:
  type: LoadBalancer
  ports:
  - name: api-http
    port: 80
    targetPort: "api-port"
    protocol: TCP
  selector:
    app: micro

greet-deployment.yml

apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: greeter-api
spec:
  replicas: 1
  selector:
    matchLabels:
      app: greeter-api
  template:
    metadata:
      labels:
        app: greeter-api
    spec:
        containers:
        - name: greeter-api-service
          image: greeter-api:latest
          imagePullPolicy: Always
          command: [
            "./greet",
            "--selector=static",
            "--server_address=:8080",
          ]
          ports:
          - containerPort: 8080
            name: greet-port

greet-svc.yml

apiVersion: v1
kind: Service
metadata:
  name: greet
  labels:
    app: greet
spec:
  ports:
  - port: 8080
    protocol: TCP
  selector:
    app: greet
-- Lee
go
go-micro
kubernetes
micro

1 Answer

4/20/2018

Everything is fine with your configs.

http://{{external-ip}}/greeter/say/hello), I get the error: {"id":"go.micro.api","code":500,"detail":"not found","status":"Internal Server Error"}

You missed just the port number 8080 in your request and tried to call rpc service instead of greeter-api .

-- Nick Rak
Source: StackOverflow