search
HomeBackend DevelopmentGolangAnalyzing Kubernetes gRPC load balancing (L4 vs L7)

This article is introduced by the go language tutorial column to introduce gRPC load balancing in Kubernetes. I hope it will be helpful to friends in need!

Installation environment dependencies

  • docker-desktop >= 4.1.1
  • kubernetes >= 1.21.5
  • go >= 1.17
  • protobuf >= 3.17.3
  • istioctl >= 1.11.4

Download and install Docker Desktop and start the built-in Kubernetes cluster.

# 安装 Gobrew install go# 安装 Protobufbrew install protobuf# 安装 Istiobrew install istioctl
kubectl config use-context docker-desktop
istioctl install -y

Project address

github.com/jxlwqq/grpc-lb

Pull code:

git clone git@github.com:jxlwqq/grpc-lb.gitcd grpc-lb

Makefile Introduction

Install protoc-gen-go and protoc-gen-grpcBased on proto File, generate *_pb.go and *_grpc.pb.goBuild docker imageDeploy services in the cluster##make kube-deletemake istio-injectFor specific logic, please check the Makefile.
Command Description
##make init
make protoc
make docker-build
make kube-deploy
Delete service
Inject Istio sidecar

Envoy (Istio) is more versatile and supports all HTTP/2 functions requested and responded by gRPC as the underlying routing and load balancing.

cmd/server/main.go: Server, providing both HTTP and RPC services. The response data is the Pod name where the server container is located (based on Downward API).
  • cmd/client-http/main.go: HTTP client, through HTTP mode, calls the server interface cyclically and prints the return value.
  • cmd/client-grpc/main.go: The gRPC client, through RPC, calls the server method remotely in a loop and prints the return value.

make docker-build # 构建镜像(构建好的镜像,不 push 到远程仓库中)

View the image:

docker images ls

Return:

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

Deployment Go to the cluster:

make kube-deploy  # 在集群中部署服务

View Pod:

kubectl get pods

Return:

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

View the log of client-http Pod:

export CLIENT_HTTP_POD=$(kubectl get pod -l app=client-http -o jsonpath={.items..metadata.name})kubectl logs "${CLIENT_HTTP_POD}"

Return:

#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

View the log of client-grpc Pod:

export CLIENT_GRPC_POD=$(kubectl get pod -l app=client-grpc -o jsonpath={.items..metadata.name})kubectl logs "${CLIENT_GRPC_POD}"

Return:

#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

It can be seen that the HTTP request is carrying a payload, while the RPC request is carrying an invalid load.

Manual injection:

make istio-inject # 注入 Istio 边车

View Pod:

kubectl get pods

Return:

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

View the log of client-http Pod:

export CLIENT_HTTP_POD=$(kubectl get pod -l app=client-http -o jsonpath={.items..metadata.name})kubectl logs "${CLIENT_HTTP_POD}"

Return:

#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

View the log of client-grpc Pod:

export CLIENT_GRPC_POD=$(kubectl get pod -l app=client-grpc -o jsonpath={.items..metadata.name})kubectl logs "${CLIENT_GRPC_POD}"

Return:

#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

It can be seen that both HTTP requests and RPC requests are carrying payloads.

Cleanup
make kube-delete
istioctl experimental uninstall --purge

The above is the detailed content of Analyzing Kubernetes gRPC load balancing (L4 vs L7). For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:learnku. If there is any infringement, please contact admin@php.cn delete
go-zero与Kubernetes的实践:构建高可用性、高性能、高扩展性的容器化微服务架构go-zero与Kubernetes的实践:构建高可用性、高性能、高扩展性的容器化微服务架构Jun 22, 2023 am 09:26 AM

随着互联网规模的不断扩大以及用户需求的不断增加,微服务架构的优势越来越受到重视。随之而来的是,容器化的微服务架构也变得尤为重要,它可以更好地满足高可用性、高性能、高扩展性等方面的需求。而在这个趋势下,go-zero和Kubernetes成为了最受欢迎的容器化微服务框架。本文将介绍如何使用go-zero框架和Kubernetes容器编排工具构建高可用性、高性能

Golang中使用gRPC实现并发数据传输的最佳实践Golang中使用gRPC实现并发数据传输的最佳实践Jul 18, 2023 pm 10:17 PM

Golang中使用gRPC实现并发数据传输的最佳实践引言:随着云计算和大数据技术的发展,数据传输的需求越来越迫切。而gRPC作为谷歌开源的高性能远程过程调用框架,以其高效、灵活和跨语言的特性,成为了很多开发者选择的首选。本文将介绍如何在Golang中使用gRPC实现并发数据传输的最佳实践,包括工程结构的搭建、连接池的使用和错误处理等。一、搭建工程结构在开始使

在Beego中使用Docker和Kubernetes进行生产部署和管理在Beego中使用Docker和Kubernetes进行生产部署和管理Jun 23, 2023 am 08:58 AM

随着互联网的快速发展,越来越多的企业开始将其应用程序迁移到云平台上。而在云平台上进行应用的部署和管理,Docker和Kubernetes已经成为了两种非常流行和强大的工具。Beego是一个使用Golang开发的Web框架,它提供了诸如HTTP路由、MVC分层、日志记录、配置管理、Session管理等丰富的功能。在本文中,我们将介绍如何使用Docker和Kub

如何在PHP中使用gRPC处理高并发API如何在PHP中使用gRPC处理高并发APIJun 17, 2023 pm 04:46 PM

在现代的网络应用程序中,处理高并发是一个非常重要的问题。在这个过程中,使用gRPC可以是一种很好的方式,可以通过远程过程调用(RPC)来实现客户端-服务器之间高效的通信。在PHP应用程序中,我们可以使用gRPC来处理高并发API请求。本文将介绍如何在PHP中使用gRPC处理高并发API。什么是gRPC?gRPC是一个高性能的RPC框架,由Google开发。它

如何使用Java开发一个基于Spring Cloud Kubernetes的容器编排应用如何使用Java开发一个基于Spring Cloud Kubernetes的容器编排应用Sep 20, 2023 am 11:15 AM

如何使用Java开发一个基于SpringCloudKubernetes的容器编排应用随着容器技术的发展和广泛应用,容器编排工具也成为了开发人员不可或缺的一部分。Kubernetes作为目前最流行的容器编排工具之一,已经成为了业界的标准。在此背景下,结合SpringCloud和Kubernetes,我们可以很方便地开发出基于容器编排的应用。本文将详细介绍

在Go语言中使用Google Kubernetes Engine(GKE):完整指南在Go语言中使用Google Kubernetes Engine(GKE):完整指南Jun 17, 2023 pm 01:25 PM

近年来,Kubernetes已经成为了容器编排平台的事实标准,而GoogleKubernetesEngine(GKE)则是Google云平台上提供的一种全托管的Kubernetes引擎。它不仅提供了自动化的容器编排、可扩展性和高可用性,还能够快速启动和调整,将代码部署变得更加简单。本文将为大家介绍如何在Go语言中使用GKE,希望本文可以成为使用GKE的完

Redis在Kubernetes的应用详解Redis在Kubernetes的应用详解Jun 20, 2023 am 11:17 AM

Kubernetes是一个现代化的容器编排系统,其强大的伸缩性和可靠性对于开发和运维人员来说无疑是非常重要的。其中的一个关键应用就是Redis,作为一个高性能缓存和数据库的组合,Redis在Kubernetes的应用也越来越受到关注。本文将详细介绍Redis在Kubernetes中的应用,通过实际案例来说明如何在Kubernetes平台上部署、管理、监控Re

PHP中如何进行Kubernetes技术的应用?PHP中如何进行Kubernetes技术的应用?May 13, 2023 am 08:09 AM

随着云计算和容器化技术的飞速发展,Kubernetes已成为当今最主流的云原生应用程序管理平台。在Kubernetes的世界里,PHP这样的Web编程语言也能够轻松地进行应用。本文将介绍如何在PHP应用中使用Kubernetes技术,让你更好地利用Kubernetes的特性,来加速应用的开发和部署。一、什么是KubernetesKubernetes是一个开源

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!