콘텐츠로 이동

서비스 디스커버리

추가 Etcd block 로 RPC 서버 설정 — 없음 code changes needed:

etc/order-rpc.yaml
Name: order.rpc
ListenOn: 0.0.0.0:8080
Etcd:
Hosts:
- 127.0.0.1:2379
Key: order.rpc # 예시입니다

Point 클라이언트 설정 at same etcd cluster과 key:

etc/user-api.yaml
OrderRpc:
Etcd:
Hosts:
- 127.0.0.1:2379
Key: order.rpc
Timeout: 2000
internal/svc/servicecontext.go
orderConn := zrpc.MustNewClient(c.OrderRpc)
svc.OrderRpc = order.NewOrderClient(orderConn.Conn())

위한 높은 availability 사용 three 또는 five nodes:

Etcd:
Hosts:
- etcd1.infra:2379
- etcd2.infra:2379
- etcd3.infra:2379
Key: order.rpc
OrderRpc:
Target: dns:///order-rpc-svc.default.svc.cluster.local:8080

또는 사용 list 의 pod 엔드포인트 directly (useful 사용하여 StatefulSets):

OrderRpc:
Endpoints:
- order-rpc-0.order-rpc-svc.default:8080
- order-rpc-1.order-rpc-svc.default:8080

위한 로컬 개발 또는 integration 테스트, skip etcd entirely:

OrderRpc:
Endpoints:
- 127.0.0.1:8080
Convention예제Notes
<name>.rpcorder.rpc표준; matches Name 필드
<env>/<name>.rpcprod/order.rpcMulti-environment 공유 etcd
<ns>.<name>.rpcpayment.order.rpcDomain namespacing

사용 same string 에서 서버’s Etcd.Key과 클라이언트’s Etcd.Key.

k8s/order-rpc.yaml
livenessProbe:
exec:
command: ["/bin/grpc_health_probe", "-addr=:8080"]
initialDelaySeconds: 5
periodSeconds: 10
readinessProbe:
exec:
command: ["/bin/grpc_health_probe", "-addr=:8080"]
initialDelaySeconds: 3
periodSeconds: 5