组件管理
更新时间:2024-09-04
概述
本节介绍服务网格CSM提供支持注册中心(consul)等组件管理功能(只有独立网格有此功能,托管网格没有)。
创建实例
按以下步骤在控制台上创建独立网格实例。
- 登录百度智能云控制台,选择“产品服务 > 云原生 > 服务网格 CSM”;
- 在全局概览页面通过“创建实例”按钮进入实例创建页面;
- 在创建服务网格页面,完成基础配置;
- 查看网络实例组件详情,如下所示:
部署consul
在CCE集群部署consul服务。
测试的consul的Yaml文件如下所示:
apiVersion: v1
kind: ConfigMap
metadata:
name: consul
data:
k8s-consul-config.json: |
{
"skip_leave_on_interrupt": true,
"acl": {
"enabled": true,
"default_policy": "deny",
"down_policy": "extend-cache",
"tokens": {
"master": "14d54c5e-24ca-41cc-8c9e-987ba7a96ffv"
}
}
}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: consul
labels:
app: consul
spec:
selector:
matchLabels:
app: consul
replicas: 1
template:
metadata:
annotations:
sidecar.istio.io/inject: "false"
labels:
app: consul
spec:
containers:
- name: consul
image: registry.baidubce.com/csm-offline/consul:1.9.17
args:
- "agent"
- "-server"
- "-bootstrap-expect=1"
- "-ui"
- "-node=server1"
- "-data-dir=/consul/data"
- "-config-file=/etc/consul/config/k8s-consul-config.json"
- "-bind=0.0.0.0"
- "-client=0.0.0.0"
- "-datacenter=dc1"
- "-enable-script-checks=true"
ports:
- containerPort: 8500
volumeMounts:
- name: data
mountPath: /consul/data
- name: config
mountPath: /etc/consul/config
volumes:
- name: data
emptyDir: {}
- name: config
configMap:
name: consul
---
apiVersion: v1
kind: Service
metadata:
name: consul
spec:
type: LoadBalancer
selector:
app: consul
ports:
- name: tcp
port: 8500
protocol: TCP
targetPort: 8500
安装registry2istio组件
- 点击服务网格实例,在组件管理处点击安装registry2istio,填写consul地址与acl token(看consul集群是否开启acl token认证)。
- consul信息填写如下所示:
- 安装成功,如下所示:
部署应用
在CCE集群部署应用:
- 在CSM注入配置处,给default命名空间开启自动注入;
- 通过CSM页面跳转到CCE集群,部署应用;
- 在工作负载/无状态部署新建测试应用;
测试Yaml文件如下所示:
apiVersion: apps/v1
kind: Deployment
metadata:
name: provider-demo-v1
labels:
app: provider-demo
spec:
selector:
matchLabels:
app: provider-demo
replicas: 1
template:
metadata:
labels:
app: provider-demo
version: v1
spec:
containers:
- name: provider-demo
image: registry.baidubce.com/csm-offline/csm-consul-mesh-provider:dev-consul-acl-token
imagePullPolicy: Always
ports:
- containerPort: 10001
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: consumer-demo
labels:
app: consumer-demo
spec:
selector:
matchLabels:
app: consumer-demo
replicas: 1
template:
metadata:
labels:
app: consumer-demo
spec:
containers:
- name: consumer-demo
image: registry.baidubce.com/csm-offline/csm-consul-mesh-consumer:dev-consul-acl-token
imagePullPolicy: Always
ports:
- containerPort: 9999
- 工作负载如下所示:
流量验证
- 通过CCE集群中的工作负载consumer-demo访问provider-demo,测试流量是否能够正常通信;
➜ registry2istio git:(master) kubectl exec -it consumer-demo-8696cd6b8c-l8dr4 -- curl 10.0.1.167:9999/echo-rest/aaaaaaaaaaa
echo() -> ip [ 10.0.0.84 ] param [ aaaaaaaaaaa ] %
➜ registry2istio git:(master) kubectl exec -it consumer-demo-8696cd6b8c-l8dr4 -- curl 10.0.1.167:9999/echo-rest/aaaaaaaaaaa
echo() -> ip [ 10.0.0.84 ] param [ aaaaaaaaaaa ] %
- 测试结果如下所示:
- consul中的consumer-demo与provider-demo服务成功被istiod管理,流量请求成功。