1

我正在尝试让这个 go-micro greeter 示例在 Kubernetes 上运行https://github.com/micro/examples/tree/master/greeter

我可以在 docker 本地运行它。但是,当我尝试通过 Kubernetes (http://{{external-ip}}/greeter/say/hello) 访问 greeter api 服务时,我收到错误:{"id":"go.micro.api", "code":500,"detail":"not found","status":"Internal Server Error"}

为了排除故障,我简化了场景,我只是希望能够通过 micro api 调用 go-micro api 服务。以下是我的设置:

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)
    }
}

微 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

微 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

问候部署.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

问候-svc.yml

apiVersion: v1
kind: Service
metadata:
  name: greet
  labels:
    app: greet
spec:
  ports:
  - port: 8080
    protocol: TCP
  selector:
    app: greet
4

1 回答 1

1

你的配置一切都很好。

http://{{external-ip}}/greeter/say/hello),我得到错误:{"id":"go.micro.api","code":500,"detail":"not found ","status":"内部服务器错误"}

您错过了请求中的端口号 8080 并尝试调用 rpc 服务而不是greeter-api.

于 2018-04-20T15:50:41.243 回答