我正在尝试在Kubernetes https://github.com/micro/examples/tree/master/greeter
上使用此微型导航器示例我可以在docker fine中在本地运行它。但是,当我尝试通过Kubernetes(http://{{external-ip}}/greeter/say/hello
)访问greeter api服务时,出现错误:
{“ id”:“ go.micro.api”,“ code”:500,“ detail”:“ not 找到”,“状态”:“内部服务器错误”}
为了进行故障排除,我简化了场景,我只是希望能够通过Micro api调用go-micro api服务。下面是我的设置:
微型api调用greeter-web成功,但是greeter-web调用greeter-srv错误。
{ “ id”:“ go.micro.client”, “代码”:500, “ detail”:“错误选择迎宾节点:未找到”, “ status”:“内部服务器错误”}
我的Yaml在这里:
package main
import (
"fmt"
"log"
"net/http"
hello "github.com/micro/examples/greeter/srv/proto/hello"
"github.com/micro/go-micro/client"
"github.com/micro/go-web"
k8s "github.com/micro/kubernetes/go/web"
"context"
)
func main() {
service := k8s.NewService(
web.Name("go.micro.web.greeter"),
)
service.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
if r.Method == "POST" {
r.ParseForm()
name := r.Form.Get("name")
if len(name) == 0 {
name = "World"
}
cl := hello.NewSayService("greeter", client.DefaultClient)
rsp, err := cl.Hello(context.Background(), &hello.Request{
Name: name,
})
if err != nil {
http.Error(w, err.Error(), 500)
return
}
w.Write([]byte(`<html><body><h1>` + rsp.Msg + `</h1></body></html>`))
return
}
fmt.Fprint(w, `<html><body><h1>Enter Name<h1><form method=post><input name=name type=text /></form></body></html>`)
})
if err := service.Init(); err != nil {
log.Fatal(err)
}
if err := service.Run(); err != nil {
log.Fatal(err)
}
}
package main
import (
"log"
"time"
hello "github.com/micro/examples/greeter/srv/proto/hello"
"github.com/micro/go-micro"
k8s "github.com/micro/kubernetes/go/micro"
"context"
)
type Say struct{}
func (s *Say) Hello(ctx context.Context, req *hello.Request, rsp *hello.Response) error {
log.Print("Received Say.Hello request")
rsp.Msg = "Hello " + req.Name
return nil
}
func main() {
service := k8s.NewService(
micro.Name("greeter"),
micro.RegisterTTL(time.Second*30),
micro.RegisterInterval(time.Second*10),
)
// optionally setup command line usage
service.Init()
// Register Handlers
hello.RegisterSayHandler(service.Server(), new(Say))
// Run server
if err := service.Run(); err != nil {
log.Fatal(err)
}
}
apiVersion: v1
kind: Service
metadata:
name: greeter
namespace: micro
labels:
app: greeter
spec:
ports:
- port: 8080
protocol: TCP
selector:
name: greeter-srv
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: micro
name: greeter
spec:
replicas: 1
selector:
matchLabels:
name: greeter-srv
template:
metadata:
labels:
name: greeter-srv
spec:
containers:
- name: greeter
command: [
"/greeter-srv",
"--selector=static",
"--server_address=0.0.0.0:8080",
"--broker_address=0.0.0.0:10001"
]
image: harbor.my.work.com/micro-test/greeter-srv:latest
imagePullPolicy: Always
ports:
- containerPort: 8080
name: greeter-port
- name: health
command: [
"/health",
"--health_address=0.0.0.0:8081",
"--server_name=greeter",
"--server_address=0.0.0.0:8080"
]
image: harbor.my.work.com/micro-test/health:latest
imagePullPolicy: Always
livenessProbe:
httpGet:
path: /health
port: 8081
initialDelaySeconds: 3
periodSeconds: 3
答案 0 :(得分:0)
[root@k8s-deploy services]# kubectl get pods,svc,ep --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system pod/calico-kube-controllers-7fd84c849f-vwxgk 1/1 Running 0 40m
kube-system pod/calico-node-cdbkr 1/1 Running 8 12d
kube-system pod/calico-node-l2kh2 1/1 Running 9 12d
kube-system pod/calico-node-xr2cd 1/1 Running 8 12d
kube-system pod/calico-node-xwbmk 1/1 Running 8 12d
kube-system pod/coredns-55f46dd959-hft6f 1/1 Running 0 40m
kube-system pod/coredns-55f46dd959-nx6qx 1/1 Running 8 12d
kube-system pod/heapster-fdb7596d6-7l97g 1/1 Running 8 12d
kube-system pod/kubernetes-dashboard-68ddcc97fc-kvxfw 1/1 Running 2 40m
kube-system pod/metrics-server-6c898b5b8b-bk7cz 1/1 Running 16 12d
micro pod/greeter-79cf6cd6bb-rh47x 2/2 Running 0 9m25s
micro pod/greeter-web-77b96d849-fc7n8 1/1 Running 0 23m
micro pod/micro-web-5cb474c8cc-n42gq 1/1 Running 0 23m
NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
default service/kubernetes ClusterIP 10.68.0.1 <none> 443/TCP 12d
kube-system service/heapster ClusterIP 10.68.240.195 <none> 80/TCP 12d
kube-system service/kube-dns ClusterIP 10.68.0.2 <none> 53/UDP,53/TCP,9153/TCP 12d
kube-system service/kubernetes-dashboard NodePort 10.68.40.70 <none> 443:29495/TCP 12d
kube-system service/metrics-server ClusterIP 10.68.91.180 <none> 443/TCP 12d
micro service/greeter ClusterIP 10.68.157.133 <none> 8080/TCP 9m4s
micro service/greeter-web NodePort 10.68.63.126 <none> 8688:20003/TCP 27h
micro service/micro-web NodePort 10.68.108.247 <none> 8086:20002/TCP 26h
NAMESPACE NAME ENDPOINTS AGE
default endpoints/kubernetes 192.168.0.220:6443,192.168.0.221:6443 12d
kube-system endpoints/heapster 176.26.169.159:8082 12d
kube-system endpoints/kube-controller-manager <none> 12d
kube-system endpoints/kube-dns 176.26.169.161:53,176.26.169.162:53,176.26.169.161:53 + 3 more... 12d
kube-system endpoints/kube-scheduler <none> 12d
kube-system endpoints/kubernetes-dashboard 176.26.169.146:8443 12d
kube-system endpoints/metrics-server 176.26.169.141:443 12d
micro endpoints/greeter 176.26.169.171:8080 9m4s
micro endpoints/greeter-web 176.26.107.200:8688 27h
micro endpoints/micro-web 176.26.107.201:8082 26h
[root@k8s-deploy services]# kubectl get pods -n micro
NAME READY STATUS RESTARTS AGE
greeter-79cf6cd6bb-rh47x 2/2 Running 0 16m
greeter-web-77b96d849-fc7n8 1/1 Running 0 30m
micro-web-5cb474c8cc-n42gq 1/1 Running 0 30m
[root@k8s-deploy services]# kubectl logs greeter-79cf6cd6bb-rh47x greeter -n micro
2019/06/06 17:04:07 Listening on [::]:8080
2019/06/06 17:04:07 Broker Listening on [::]:10001
2019/06/06 17:04:07 Broker [grpc] Listening on [::]:10001
2019/06/06 17:04:07 Registering node: greeter-a54b5993-3422-410d-b548-e1bc629ce182
[root@k8s-deploy services]# kubectl logs greeter-79cf6cd6bb-rh47x health -n micro
[root@k8s-deploy services]#
[root@k8s-deploy services]# kubectl logs greeter-79cf6cd6bb-rh47x health -n micro
[root@k8s-deploy services]# kubectl logs greeter-web-77b96d849-fc7n8 -n micro
2019/06/06 16:50:02 Listening on [::]:8688
[root@k8s-deploy services]#
[root@k8s-deploy services]# kubectl logs micro-web-5cb474c8cc-n42gq -n micro
2019/06/06 16:50:13 HTTP API Listening on [::]:8082
2019/06/06 16:50:13 Listening on [::]:35315
2019/06/06 16:50:13 Broker Listening on [::]:36389
2019/06/06 16:50:13 Broker [grpc] Listening on [::]:36389
2019/06/06 16:50:13 Registering node: go.micro.web-65751383-2126-4df0-8059-7ea14094f7de
176.26.114.128 - - [06/Jun/2019:16:50:34 +0000] "GET /greeter HTTP/1.1" 200 98 "" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36"
176.26.114.128 - - [06/Jun/2019:16:50:34 +0000] "GET /favicon.ico HTTP/1.1" 200 0 "http://192.168.0.220:20002/greeter" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36"
176.26.114.128 - - [06/Jun/2019:16:50:36 +0000] "POST /greeter HTTP/1.1" 500 120 "http://192.168.0.220:20002/greeter" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36"