本文由go語言教學專欄為大家介紹Kubernetes中的gRPC負載平衡 ,希望對需要的朋友有幫助!
下載安裝Docker Desktop ,並啟動內建的Kubernetes 叢集。
# 安装 Gobrew install go# 安装 Protobufbrew install protobuf# 安装 Istiobrew install istioctl kubectl config use-context docker-desktop istioctl install -y
github.com/jxlwqq/grpc-lb
拉取程式碼:
git clone git@github.com:jxlwqq/grpc-lb.gitcd grpc-lb
指令 | 說明 |
---|---|
##make init
| 安裝protoc-gen-go 和protoc-gen-grpc|
make protoc
| 基於proto文件,產生*_pb.go 和*_grpc.pb.go|
#make docker-build
| 建構docker 映像|
make kube-deploy
| 在叢集中部署服務|
make kube-delete
| #刪除服務|
make istio-inject
| #注入Istio 邊車
make docker-build # 构建镜像(构建好的镜像,不 push 到远程仓库中)檢視鏡像:
docker images ls返回:
REPOSITORY TAG IMAGE ID CREATED SIZE grpc-lb/client-grpc latest 95d32ead8d9b 12 seconds ago 16.6MB grpc-lb/client-http latest dbf0341206f6 22 seconds ago 11.5MB grpc-lb/server latest 1ef346785b2a 29 seconds ago 18.2MB部署到叢集中:
make kube-deploy # 在集群中部署服务查看Pod:
kubectl get pods返回:
NAME READY STATUS RESTARTS AGE client-grpc-6c565594f4-tdf75 1/1 Running 0 2m48s client-http-55d95c744d-f7nx4 1/1 Running 0 2m49s server-7c4bfd74d-29c69 1/1 Running 0 2m51s server-7c4bfd74d-4btvw 1/1 Running 0 2m51s server-7c4bfd74d-fk8zf 1/1 Running 0 2m51s查看client-http Pod 的日誌:
export CLIENT_HTTP_POD=$(kubectl get pod -l app=client-http -o jsonpath={.items..metadata.name})kubectl logs "${CLIENT_HTTP_POD}"傳回:
#1: server-7c4bfd74d-4btvw#2: server-7c4bfd74d-4btvw#3: server-7c4bfd74d-29c69#4: server-7c4bfd74d-fk8zf#5: server-7c4bfd74d-fk8zf#6: server-7c4bfd74d-29c69#7: server-7c4bfd74d-fk8zf#8: server-7c4bfd74d-4btvw#9: server-7c4bfd74d-fk8zf查看client-grpc Pod 的日誌:
export CLIENT_GRPC_POD=$(kubectl get pod -l app=client-grpc -o jsonpath={.items..metadata.name})kubectl logs "${CLIENT_GRPC_POD}"返回:
#1: server-7c4bfd74d-fk8zf#2: server-7c4bfd74d-fk8zf#3: server-7c4bfd74d-fk8zf#4: server-7c4bfd74d-fk8zf#5: server-7c4bfd74d-fk8zf#6: server-7c4bfd74d-fk8zf#7: server-7c4bfd74d-fk8zf#8: server-7c4bfd74d-fk8zf#9: server-7c4bfd74d-fk8zf可以看出,HTTP 請求在進行有效負載,而RPC 請求在進行無效負載。
make istio-inject # 注入 Istio 边车查看Pod:
kubectl get pods返回:
NAME READY STATUS RESTARTS AGE client-grpc-7864f57779-f6blx 2/2 Running 0 17s client-http-f8964854c-jclkd 2/2 Running 0 21s server-7846bd6bb4-bcfws 2/2 Running 0 27s server-7846bd6bb4-fv29s 2/2 Running 0 40s server-7846bd6bb4-hzqj6 2/2 Running 0 34s查看client-http Pod 的日誌:
export CLIENT_HTTP_POD=$(kubectl get pod -l app=client-http -o jsonpath={.items..metadata.name})kubectl logs "${CLIENT_HTTP_POD}"返回:
#1: server-7846bd6bb4-hzqj6#2: server-7846bd6bb4-fv29s#3: server-7846bd6bb4-hzqj6#4: server-7846bd6bb4-hzqj6#5: server-7846bd6bb4-hzqj6#6: server-7846bd6bb4-hzqj6#7: server-7846bd6bb4-hzqj6#8: server-7846bd6bb4-bcfws#9: server-7846bd6bb4-fv29s查看client-grpc Pod 的日誌:
export CLIENT_GRPC_POD=$(kubectl get pod -l app=client-grpc -o jsonpath={.items..metadata.name})kubectl logs "${CLIENT_GRPC_POD}"返回:
#1: server-7846bd6bb4-fv29s#2: server-7846bd6bb4-hzqj6#3: server-7846bd6bb4-fv29s#4: server-7846bd6bb4-bcfws#5: server-7846bd6bb4-fv29s#6: server-7846bd6bb4-hzqj6#7: server-7846bd6bb4-fv29s#8: server-7846bd6bb4-bcfws#9: server-7846bd6bb4-fv29s可以看出,HTTP 請求和RPC 請求都在進行有效負載。
make kube-delete istioctl experimental uninstall --purge
以上是分析Kubernetes gRPC負載平衡(L4 vs L7 )的詳細內容。更多資訊請關注PHP中文網其他相關文章!