注意:此文档描述的内容正在建设中或处于功能早期阶段,请持续关注文档更新!
目前 Dubbo 仅支持在 Kubernetes 环境下的 Mesh 部署,所以在运行启动本示例前需要先搭Kubernetes 环境。(建议采用docker desktop进行搭建,直接就可以运行一个kubernetes环境) https://docs.docker.com/desktop/install/mac-install/
搭建 Istio 环境参考文档: Istio 安装文档(https://istio.io/latest/docs/setup/getting-started/) 注:安装 Istio 的时候需要开启 first-party-jwt 支持(使用 istioctl 工具安装的时候加上 –set values.global.jwtPolicy=first-party-jwt 参数),否则将导致客户端认证失败的问题。 附安装命令参考:
curl -L https://istio.io/downloadIstio | sh -
cd istio-1.xx.x
export PATH=$PWD/bin:$PATH
istioctl install --set profile=demo --set values.global.jwtPolicy=first-party-jwt -y
进入dubbo-dependencies-bom,更改grpc版本为1.41.0
<grpc.version>1.41.0</grpc.version>
进入dubbo-samples-xds目录,新增配置:
dubbo.application.metadataServiceProtocol=dubbo
打包dubbo代码,切换到dubbo根目录,执行以下命令进行打包:
mvn clean package -DskipTests
切换到dubbo-samples代码,在dubbo-samples-xds的pom文件中引入刚打包好的dubbo代码。 接下来修改debug模式,以dubbo-xds-consumer为例: 更改dubbo-samples-consumer的docker file并更改调试模式为suspend=y, 更改后的docker file文件如下:
FROM openjdk:8-jdk
ADD ./target/dubbo-samples-xds-consumer-1.0-SNAPSHOT.jar dubbo-samples-xds-consumer-1.0-SNAPSHOT.jar
EXPOSE 31000
CMD java -jar -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=31000 /dubbo-samples-xds-consumer-1.0-SNAPSHOT.jar
随后执行以下命令进行打包:
cd dubbo-samples/dubbo-samples-xds
mvn clean package -DskipTests
cd ./dubbo-samples-xds-provider/
# dubbo-samples-xds/dubbo-samples-xds-provider/Dockerfile
docker build -t apache/dubbo-demo:dubbo-samples-xds-provider_0.0.1 .
cd ../dubbo-samples-xds-consumer/
# dubbo-samples-xds/dubbo-samples-xds-consumer/Dockerfile
docker build -t apache/dubbo-demo:dubbo-samples-xds-consumer_0.0.1 .
cd ../
# 初始化命名空间
kubectl apply -f https://raw.githubusercontent.com/apache/dubbo-samples/master/dubbo-samples-xds/deploy/Namespace.yml
# 切换命名空间
kubens dubbo-demo
如果kubens切换不成功,安装下kubectl即可
cd ./dubbo-samples-xds-provider/src/main/resources/k8s
# dubbo-samples-xds/dubbo-samples-xds-provider/src/main/resources/k8s/Deployment.yml
# dubbo-samples-xds/dubbo-samples-xds-provider/src/main/resources/k8s/Service.yml
kubectl apply -f Deployment.yml
kubectl apply -f Service.yml
cd ../../../../../dubbo-samples-xds-consumer/src/main/resources/k8s
# dubbo-samples-xds/dubbo-samples-xds-consumer/src/main/resources/k8s/Deployment.yml
kubectl apply -f Deployment.yml
cd ../../../../../
成功执行上述命令后的docker desktop containers页面长这样,其中dubbo-samples一共出现数个containers,包含consumer和provider:
查看k8s_server_dubbo-samples-xds-provider-XXX日志,出现如下日志:
Dec 28, 2022 8:42:48 AM org.apache.dubbo.config.deploy.DefaultApplicationDeployer info
INFO: [DUBBO] Dubbo Application[1.1](dubbo-samples-xds-provider) is ready., dubbo version: 1.0-SNAPSHOT, current host: 10.1.5.64
Dec 28, 2022 8:42:49 AM org.apache.dubbo.registry.xds.util.protocol.AbstractProtocol info
INFO: [DUBBO] receive notification from xds server, type: type.googleapis.com/envoy.config.listener.v3.Listener, dubbo version: 1.0-SNAPSHOT, current host: 10.1.5.64
Dec 28, 2022 8:42:53 AM org.apache.dubbo.registry.xds.util.protocol.AbstractProtocol info
INFO: [DUBBO] receive notification from xds server, type: type.googleapis.com/envoy.config.listener.v3.Listener, dubbo version: 1.0-SNAPSHOT, current host: 10.1.5.64
dubbo service started
查看k8s_server_dubbo-samples-xds-consumer-XXX日志,发现其正等待debug连接: 打开命令终端,输入命令查看可用并处于Running状态的pods:
kubectl get pods
输入以下命令将pods的端口映射到本地:
kubectl port-forward dubbo-samples-xds-consumer-64c6c6f444-kk2vr 31000:31000
切换到idea,edit configuration,debugger mode选择attach to remote JVM,port选择上面docker file expose的端口,module classpath选择dubbo-samples-xds-consumer,并点击debug,即可成功连接
可以看到断点已经成功进来了: 此时查看k8s_server_dubbo-samples-xds-consumer-XXX的日志可以看到已经成功在运行: