ToB企服应用市场:ToB评测及商务社交产业平台

标题: 基于istio实现单集群地域故障转移 [打印本页]

作者: 农民    时间: 2024-5-16 23:14
标题: 基于istio实现单集群地域故障转移
本文分享自华为云社区《基于istio实现单集群地域故障转移》,作者:可以交个朋侪。
一 背景

随着应用步伐的增长并变得更加复杂,微服务的数目也会增加,失败的可能性也会增加。微服务的故障可能多种原因造成,例如硬件题目、网络延迟、软件错误,乃至人为错误。故障转移Failover 是体系韧性设计中的一个基础能力,它们可以确保体系在出现故障时能够继续运行,并且能够在最小化的影响下举行恢复,减少或者消除对使用方或终极用户的影响,从而提高整个体系对外的可用性。
二 简介

云原生K8s、istio默认使用node上特定label作为地域信息:
kubectl describe node xxx |grep topo

如下图所示演示环境,helloworld作为服务端有多个实例分别部署在不同zone中(不同zone节点topology.kubernetes.io/zone的label不同)。通过istio的destinationrule中localityLbSetting.failover(故障转移策略)和outlierDetection(故障异常点检测),可以实现客户端业务访问helloworld服务时候,优先访问与客户端同可用区的服务端,当同可用区的helloworld服务端全部故障后,再访问指定可用区的服务端,实现故障转移。

三 实战演练

事先准备好kubernetes+istio作为操纵环境。可用华为云CCE和ASM服务举行操纵。
3.1 部署服务端

1.创建sample 命名空间,并设置istio-proxy sidecar自动注入
  1. apiVersion: v1
  2. kind: Namespace
  3. metadata:
  4.   name: sample
  5.   labels:
  6.     istio-injection: enabled
复制代码
2.部署helloworld服务 作为服务端
将根据以下脚本天生对yaml配置清单
[code]#!/bin/bashset -euo pipefaildisplay_usage() {    echo    echo "USAGE: ./gen-helloworld.sh [--version] [--includeService value] [--includeDeployment value]"    echo "    -h|--help: Prints usage information"    echo "    --version: Specifies the version that will be returned by the helloworld service, default: 'v1'"    echo "    --includeService: If 'true' the service will be included in the YAML, default: 'true'"    echo "    --includeDeployment: If 'true' the deployment will be included in the YAML, default: 'true'"}INCLUDE_SERVICE=${INCLUDE_SERVICE:-"true"}INCLUDE_DEPLOYMENT=${INCLUDE_DEPLOYMENT:-"true"}SERVICE_VERSION=${SERVICE_VERSION:-"v1"}while (( "$#" )); do  case "$1" in    -h|--help)      display_usage      exit 0      ;;    --version)      SERVICE_VERSION=$2      shift 2      ;;    --includeService)      INCLUDE_SERVICE=$2      shift 2      ;;    --includeDeployment)      INCLUDE_DEPLOYMENT=$2      shift 2      ;;    *)      echo "Error: Unsupported flag $1" >&2      display_usage      exit 1      ;;  esacdoneSERVICE_YAML=$(cat




欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) Powered by Discuz! X3.4