负载均衡
更新时间:2022-08-15
创建Blb负载均衡
以下代码可以创建Blb负载均衡:
public void createBecBlb(BecClient client) {
CreateBecBlbRequest request = CreateBecBlbRequest.builder()
// 负载均衡类型,支持容器与虚机两种,分别对应"container"、"vm"
.lbType("vm")
// 付费方式,目前仅支持后付费方式("postpay")
.paymentMethod("postpay")
// 区域选择
.regionSelection("regional")
// 负载均衡所在区域信息
.region("EAST_CHINA")
// 负载均衡所在城市信息
.city("HANGZHOU")
// 负载均衡所属运营商信息
.serviceProvider("CHINA_MOBILE")
// 负载均衡名称
.blbName("bec-test")
// 是否需要公网ip
.needPublicIp(true)
// 负载均衡最大带宽限制,单位Mbps
.bandwidthInMbpsLimit(100)
.build();
CreateBecBlbResponse response = client.createBecBlb(request);
}
说明:创建负载均衡详情可参照API参考文档
获取Blb负载均衡列表
使用以下代码可以获取Blb负载均衡列表:
public void getBecBlbs(BecClient client) {
GetBecBlbsRequest request = new GetBecBlbsRequest();
// 负载均衡类型,支持"container"与"vm"两种类型,默认为"container"
request.setLbType("vm");
// 页码,默认单页显示
request.setPageNo(1);
// 单页结果数,默认值1000
request.setPageSize(10);
GetBecBlbsResponse response = client.getBecBlbs(request);
}
获取Blb详情
使用以下代码可以启动指定BCC虚机实例:
public void getBecBlb(BecClient client) {
GetBecBlbInstanceRequest request = new GetBecBlbInstanceRequest();
// 负载均衡Id
request.setBlbId("blbId");
GetBecBlbInstanceResponse response = client.getBecBlb(request);
}
删除指定的Blb
使用以下代码可以删除指定的Blb:
public void deleteBecBlb(BecClient client) {
DeleteBecBlbRequest request = new DeleteBecBlbRequest();
// 负载均衡Id
request.setBlbId("blbId");
DeleteBecBlbResponse response = client.deleteBecBlb(request);
}
更新指定的Blb
使用以下代码可以更新指定的Blb:
public void updateBecBlb(BecClient client) {
UpdateBecBlbRequest request = new UpdateBecBlbRequest();
// 负载均衡Id
request.setBlbId("blbId");
// 负载均衡名称
request.setBlbName("bec-blb-name");
UpdateBecBlbResponse response = client.updateBecBlb(request);
}
创建BLB监听设置
使用以下代码可以创建BLB监听设置:
public void createBecBlbMonitorPort(BecClient client) {
CreateBecBlbMonitorPortRequest request = new CreateBecBlbMonitorPortRequest();
Port frontendPort = new Port();
// 端口号
frontendPort.setPort(8083);
// 使用协议名称
frontendPort.setProtocol("TCP");
HealthCheck healthCheck = new HealthCheck();
// UDP检查字符串
healthCheck.setHealthCheckString("udp");
// 健康阈值
healthCheck.setHealthyThreshold(3);
// 健康检查时间
healthCheck.setIntervalInSeconds(1);
// 响应超时时间
healthCheck.setTimeoutInSeconds(1);
// 不健康阈值
healthCheck.setUnhealthyThreshold(3);
// 负载均衡Id
request.setBlbId("blbId");
// 后端端口
request.setBackendPort(80);
// 负载均衡端口
request.setFrontendPort(frontendPort);
// 健康检查设置
request.setHealthCheck(healthCheck);
// 转发规则
request.setLbMode("wrr");
CreateBecBlbMonitorPortResponse response = client.createBecBlbMonitorPort(request);
}
获取BLB监听设备列表
使用以下代码可以获取BLB监听设备列表:
public void getBlbMonitorPortList(BecClient client) {
GetBecBlbMonitorPortListRequest request = new GetBecBlbMonitorPortListRequest();
// 负载均衡Id
request.setBlbId("blbId");
GetBecBlbMonitorPortListResponse response = client.getBlbMonitorPortList(request);
}
获取指定BLB指定监听端口的详情
使用以下代码可以获取指定BLB指定监听端口的详情:
public void getBecBlbMonitorPortDetails(BecClient client) {
GetBecBlbMonitorPortDetailsRequest request = new GetBecBlbMonitorPortDetailsRequest();
// 负载均衡Id
request.setBlbId("blbId");
// 负载均衡端
request.setPort(8083);
// 负载均衡协议
request.setProtocol("TCP");
GetBecBlbMonitorPortDetailsResponse response = client.getBecBlbMonitorPortDetails(request);
}
修改BLB监听端口设置
使用以下代码可以修改BLB监听端口设置:
public void updateBecBlbMonitorPort(BecClient client) {
UpdateBecBlbMonitorPortRequest request = new UpdateBecBlbMonitorPortRequest();
Port frontendPort = new Port();
// 使用协议名称
frontendPort.setProtocol("TCP");
// 端口号
frontendPort.setPort(8083);
HealthCheck healthCheck = new HealthCheck();
// 不健康阈值
healthCheck.setUnhealthyThreshold(3);
// 响应超时时间
healthCheck.setTimeoutInSeconds(1);
// 健康检查时间
healthCheck.setIntervalInSeconds(2);
// 健康阈值
healthCheck.setHealthyThreshold(4);
// UDP检查字符串
healthCheck.setHealthCheckString("wohao");
// 负载均衡Id
request.setBlbId("blbId");
// 健康检查设置
request.setHealthCheck(healthCheck);
// 后端端口
request.setBackendPort(8083);
// 负载均衡端口
request.setFrontendPort(frontendPort);
// 转发规则
request.setLbMode("wrr");
UpdateBecBlbMonitorPortResponse response = client.updateBecBlbMonitorPort(request);
}
获取指定BEC LB后端绑定Pod/VM列表
使用以下代码可以获取指定BEC LB后端绑定Pod/VM列表:
public void getBecBlbBackendPodList(BecClient client) {
GetBecBlbBackendPodListRequest request = new GetBecBlbBackendPodListRequest();
// 负载均衡Id
request.setBlbId("blbId");
GetBecBlbBackendPodListResponse response = client.getBecBlbBackendPodList(request);
}
获取指定BLB可绑定的部署StatefulSet/VmReplicas组
使用以下代码可以获取指定BLB可绑定的部署StatefulSet/VmReplicas组:
public void getBecBlbBackendBindingStsList(BecClient client) {
GetBecBlbBackendBindingStsListRequest request = new GetBecBlbBackendBindingStsListRequest();
// 负载均衡Id
request.setBlbId("blbId");
GetBecBlbBackendBindingStsListResponse response = client.getBecBlbBackendBindingStsList(request);
}
获取指定的StatefulSet/VmReplicas后端可绑定的Pod/Vm组
使用以下代码可以获取指定的StatefulSet/VmReplicas后端可绑定的Pod/Vm组:
public void getBecBlbBindingPodListWithSts(BecClient client) {
GetBecBlbBindingPodListWithStsRequest request = new GetBecBlbBindingPodListWithStsRequest();
// 负载均衡Id
request.setBlbId("blbId");
// 部署名称
request.setStsName("stsName");
GetBecBlbBindingPodListWithStsResponse response = client.getBecBlbBindingPodListWithSts(request);
}
为指定BLB绑定后端StatefulSet/VmReplicas
使用以下代码可以为指定BLB绑定后端StatefulSet/VmReplicas:
public void createBecBlbBinding(BecClient client) {
CreateBecBlbBindingRequest request = new CreateBecBlbBindingRequest();
// 负载均衡Id
request.setBlbId("blbId");
// 部署名称
request.setDeploymentId("deploymentId");
// 权重
request.setDefaultWeight(80);
// 容器组\虚机实例列表
List<Backends> podWeight = new LinkedList<Backends>();
Backends backends = new Backends();
// 容器组\虚机实例名称
backends.setName("name");
// 容器组\虚机实例权重
backends.setWeight(20);
// 容器组\虚机实例
podWeight.add(backends);
// 容器组\虚机实例列表
request.setPodWeight(podWeight);
CreateBecBlbBindingResponse response = client.createBecBlbBinding(request);
}
修改指定BLB后端绑定容器组Pod/虚机组Vm的权重
使用以下代码可以修改指定BLB后端绑定容器组Pod/虚机组Vm的权重:
public void updateBecBlbBindPodWeight(BecClient client) {
UpdateBecBlbBindPodWeightRequest request = new UpdateBecBlbBindPodWeightRequest();
// 后端服务器信息
List<Backends> podWeightList = new ArrayList<Backends>();
Backends backends = new Backends();
// 后端服务器权重
backends.setWeight(100);
// 后端服务器名称
backends.setName("name");
podWeightList.add(backends);
// 负载均衡Id
request.setBlbId("blbId");
request.setPodWeightList(podWeightList);
UpdateBecBlbBindPodWeightResponse response = client.updateBecBlbBindPodWeight(request);
}
获取BEC BLB 监控
使用以下代码可以获取BEC BLB 监控:
public void getBecBlbResourceMetrics(BecClient client) {
GetBecBlbResourceMetricsRequest request = new GetBecBlbResourceMetricsRequest();
// 负载均衡Id
request.setBlbId("blbId");
// 监控指标类型,支持bandwidth_receive(入网带宽)、bandwidth_transmit(出网带宽)、traffic_receive(入网流量)、traffic_transmit(出网流量)
request.setType("bandwidth_receive");
// 支持"extranet"、"intranet",分别对应公网、内网
request.setIpType("extranet");
// 偏移时间
request.setOffsetInSeconds(3600);
// 数据点间隔(单位:分钟)
request.setStepInMin(5);
GetBecBlbResourceMetricsResponse response = client.getBecBlbResourceMetrics(request);
}