多协议管理
更新时间:2024-09-04
概述
本节介绍服务网格CSM支持Dubbo、bRPC等私有协议的相关操作。
使用前提
创建独立网格实例,并且开启支持兼容三方协议按钮。
创建实例
按以下步骤在控制台上创建独立网格实例并且开启多协议支持:
- 登录百度智能云控制台,选择“产品服务 > 云原生 > 服务网格 CSM”;
- 在全局概览页面通过“创建实例”按钮进入实例创建页面;
- 在创建服务网格页面,完成基础配置;
- 查看网络列表,如下所示:
部署应用
按一下步骤在CCE集群部署应用:
- 在CSM/注入配置处,给default命名空间开启自动注入;
- 通过CSM页面跳转到CCE集群,部署应用;
- 在工作负载/无状态部署新建测试应用。
测试应用的Yaml文件如下所示:
apiVersion: v1
kind: ConfigMap
metadata:
name: dubbo-resolve-config
data:
dubbo-resolve.properties: |-
org.apache.dubbo.samples.basic.api.DemoService=dubbo://dubbo-sample-provider:20880
org.apache.dubbo.samples.basic.api.TestService=dubbo://dubbo-sample-provider:20880
org.apache.dubbo.samples.basic.api.ComplexService=dubbo://dubbo-sample-provider:20880
org.apache.dubbo.samples.basic.api.SecondService=dubbo://dubbo-sample-second-provider:20880
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: dubbo-sample-provider-v1
labels:
app: dubbo-sample-provider
spec:
selector:
matchLabels:
app: dubbo-sample-provider
replicas: 1
template:
metadata:
annotations:
sidecar.istio.io/bootstrapOverride: aeraki-bootstrap-config
labels:
app: dubbo-sample-provider
version: v1
service_group: user
spec:
containers:
- name: dubbo-sample-provider
image: registry.baidubce.com/csm/dubbo-sample-provider:latest
ports:
- containerPort: 20880
volumeMounts:
- name: dubbo-resolve-config
mountPath: /dubbo-resolve.properties
subPath: dubbo-resolve.properties
readOnly: true
volumes:
- name: dubbo-resolve-config
configMap:
name: dubbo-resolve-config
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: dubbo-sample-provider-v2
labels:
app: dubbo-sample-provider
spec:
selector:
matchLabels:
app: dubbo-sample-provider
replicas: 1
template:
metadata:
annotations:
sidecar.istio.io/bootstrapOverride: aeraki-bootstrap-config
labels:
app: dubbo-sample-provider
version: v2
service_group: batchjob
spec:
containers:
- name: dubbo-sample-provider
image: registry.baidubce.com/csm/dubbo-sample-provider:latest
ports:
- containerPort: 20880
volumeMounts:
- name: dubbo-resolve-config
mountPath: /dubbo-resolve.properties
subPath: dubbo-resolve.properties
readOnly: true
volumes:
- name: dubbo-resolve-config
configMap:
name: dubbo-resolve-config
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: dubbo-sample-second-provider
labels:
app: dubbo-sample-second-provider
spec:
selector:
matchLabels:
app: dubbo-sample-second-provider
replicas: 1
template:
metadata:
annotations:
sidecar.istio.io/bootstrapOverride: aeraki-bootstrap-config
labels:
app: dubbo-sample-second-provider
version: v2
service_group: batchjob
spec:
containers:
- name: dubbo-sample-second-provider
image: registry.baidubce.com/csm/dubbo-sample-second-provider
ports:
- containerPort: 20880
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: dubbo-sample-consumer
labels:
app: dubbo-sample-consumer
spec:
selector:
matchLabels:
app: dubbo-sample-consumer
replicas: 1
template:
metadata:
annotations:
sidecar.istio.io/bootstrapOverride: aeraki-bootstrap-config
labels:
app: dubbo-sample-consumer
spec:
containers:
- name: dubbo-sample-consumer
image: registry.baidubce.com/csm/dubbo-sample-consumer:latest
env:
- name: mode
value: demo
ports:
- containerPort: 9009
volumeMounts:
- name: dubbo-resolve-config
mountPath: /dubbo-resolve.properties
subPath: dubbo-resolve.properties
readOnly: true
volumes:
- name: dubbo-resolve-config
configMap:
name: dubbo-resolve-config
---
apiVersion: v1
kind: Service
metadata:
name: dubbo-sample-provider
spec:
selector:
app: dubbo-sample-provider
ports:
- name: tcp-metaprotocol-dubbo
protocol: TCP
port: 20880
targetPort: 20880
- 工作负载如下所示:
- 在CSM/Istio资源管理处下发destinationrule规则。 destinationrule的Yaml文件如下所示:
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
name: dubbo-sample-provider
spec:
host: dubbo-sample-provider.default.svc.cluster.local
subsets:
- name: v1
labels:
version: v1
- name: v2
labels:
version: v2
流量验证
- 通过CCE集群中的工作负载查看业务容器中的日志: 从日志中可以得知,consumer请求provider-demo,轮询调用v1与v2版本,符合预期。
- 从CSM/Istio资源管理处下发流量治理策略,全部访问v1版本。
apiVersion: metaprotocol.aeraki.io/v1alpha1
kind: MetaRouter
metadata:
name: test-metaprotocol-dubbo-route
spec:
hosts:
- dubbo-sample-provider.default.svc.cluster.local
routes:
- name: v1
match:
attributes:
interface:
exact: org.apache.dubbo.samples.basic.api.DemoService
method:
exact: sayHello
foo:
exact: bar
route:
- destination:
host: dubbo-sample-provider.default.svc.cluster.local
subset: v1
- 通过CCE集群中的工作负载在此查看业务容器中的日志: 从日志中可以得知,consumer请求provider-demo,全部调用v1版本,符合预期。