让我们在笔记本电脑上探索由 Go、gRPC、Kubernetes 和 Istio 组成的 Mercari-ish 微服务!
您可以在/services
目录下找到每个微服务的实现和 gRPC API 定义。
make cluster
该 make 目标执行以下任务:
/services
目录下的所有微服务的 Docker 镜像。完成此 make 目标后,您可以使用./script/kubectl
检查微服务的状态,它只是kubectl
的一个小包装,如下所示:
./script/kubectl get pods --all-namespaces | grep -E '^(gateway|authority|catalog|customer|item)'
authority app-7b559dfd9f-dcr2v 2/2 Running 0 44s
authority app-7b559dfd9f-z8c54 2/2 Running 0 44s
catalog app-67cc897d9c-dhcv7 2/2 Running 0 36s
catalog app-67cc897d9c-nfk7x 2/2 Running 0 36s
customer app-565bfc5884-bgb8r 2/2 Running 0 28s
customer app-565bfc5884-lt6q2 2/2 Running 0 28s
gateway app-cc456cf4d-nsghg 2/2 Running 0 51s
gateway app-cc456cf4d-wq47s 2/2 Running 0 51s
item app-84db48bdf-h7q7b 2/2 Running 0 19s
item app-84db48bdf-l5mnl 2/2 Running 0 19s
现在,Mercari-ish 服务正在侦听端口30000
,您可以像下面这样探索它!
curl -s -XPOST -d '{"name":"gopher"}' localhost:30000/auth/signup | jq .
{
"customer" : {
"id" : " ec1fcc77-b565-4477-b609-62bf0c403903 " ,
"name" : " gopher "
}
}
TOKEN=$(curl -s -XPOST -d '{"name":"gopher"}' localhost:30000/auth/signin | jq .access_token -r)
curl -s -XPOST -d '{"title":"Keyboard","price":30000}' -H "authorization: bearer $TOKEN" localhost:30000/catalog/items | jq .
{
"item" : {
"id" : " bda92da6-3270-4255-a756-dbe7d0aa333e " ,
"customer_id" : " ec1fcc77-b565-4477-b609-62bf0c403903 " ,
"title" : " Keyboard " ,
"price" : " 30000 "
}
}
curl -s -XGET -H "authorization: bearer $TOKEN" localhost:30000/catalog/items | jq .
{
"items" : [
{
"id" : " 3c287306-6753-4ab6-acde-d17297e2939e " ,
"title" : " Keyboard " ,
"price" : " 30000 "
},
{
"id" : " e0e58243-4138-48e5-8aba-448a8888e2ff " ,
"title" : " Mobile Phone " ,
"price" : " 10000 "
},
{
"id" : " 0b185d96-d6fa-4eaf-97f6-3f6d2c1649b6 " ,
"title" : " Laptop " ,
"price" : " 20000 "
}
]
}
curl -s -XGET -H "authorization: bearer $TOKEN" localhost:30000/catalog/items/e0e58243-4138-48e5-8aba-448a8888e2ff | jq .
{
"item" : {
"id" : " e0e58243-4138-48e5-8aba-448a8888e2ff " ,
"customer_id" : " 7c0cde05-4df0-47f4-94c4-978dd9f56e5c " ,
"customer_name" : " goldie " ,
"title" : " Mobile Phone " ,
"price" : " 10000 "
}
}
make clean