理论:
1.grpc基于HTTP/2实现,HTTP2是长连接的,io多路复用,即在一条tcp连接上可以发起多个rpc请求, 请求通过流id 也就是streamID划分。
2.k8s是L4层负载均衡,也就是TCP那层,支持tcp的流量转发,如果是grpc服务部署在k8s,且通过k8s clusterIP访问 就会出现负载不均衡的情况;
3.istio-服务网络,支持7层代理,可以解决grpc服务容器化后负载不均的问题,实现L7的负载均衡;
部署istio
https://www.cnblogs.com/gdut17/p/15144052.html
istio配置镜像拉取策略
https://blog.youkuaiyun.com/weixin_60092693/article/details/124599364
命名空间自动注入
kubectl label namespace default istio-injection=enabled --overwrite
去掉自动注入标签
kubectl label ns default istio-injection-
手动注入
istioctl kube-inject -f helloworld_deploy.yaml | kubectl apply -f -
deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: helloworld
name: helloworld
spec:
replicas: 1
selector:
matchLabels:
app: helloworld
template:
metadata:
labels:
app: helloworld
spec:
containers:
- image: helloworld:1.0
imagePullPolicy: Never
name: service
command:
- /main
- --listen=:80
svc.yaml
[root@localhost grpc]# cat svc.yaml
apiVersion: v1
kind: Service
metadata:
labels:
app: helloworld
name: helloworld
spec:
selector:
app: helloworld
ports:
- name: http