Istio就是Service Mesh的落地实现.

1. Istio的功能

  1. 负载均衡,服务发现
  2. 故障恢复,指标收集和监控
  3. A/B测试,灰度发布
  4. 限流,访问控制和端到端认证

2. Istio的架构

架构图:
在这里插入图片描述

  1. 数据平面: 数据平面由一组sidecar方式部署的智能代理(Envoy)节点组成,与每一个微服务节点共存,只负责工作
    1. 可以看到架构图上是Proxy,并不是Envoy, 其实Proxy是在Envoy的基础上包裹了一层的代理层,因为Envoy是使用C++编写的代理,但是Istio大部分都是使用Go编写的,不同语言通信上可能存在问题,所以在Envoy的基础上包裹一层.
  2. 控制平面: 相当于一个控制台的作用,单独部署于微服务集群之外,用于控制/配置数据平面
    1. Mixer:
      1. 实施控制平面的策略,并收集遥测数据;
      2. Istio独有的架构.
    2. Pilot:
      1. 提供服务发现功能
      2. 流量管理(超时/重试/熔断)
      3. 转换路由规则(将高级流控路由规则转换为Envoy可以识别的配置)
    3. Citadel:
      1. 身份和凭证管理
      2. 微服务和最终用户身份验证,认证为双向认证,不光是客户端到服务端的认证,也提供服务端到客户端的认证.
      3. 对未加密流量进行加密
      4. 基于角色的访问控制(RABC)
    4. Galley
      1. Istio的API server
      2. 验证用户编写的API配置
      3. 将接管Istio,获取配置,处理和分配组件.

3. Istio代码结构

github地址: https://github.com/istio/istio

The Istio project is divided across a few GitHub repositories:

  • istio/api. This repository defines component-level APIs and common configuration formats for the Istio platform.
  • istio/community. This repository contains information on the Istio community, including the various documents that govern the Istio open source project.
  • istio/istio. This is the main code repository. It hosts Istio’s core components, install artifacts, and sample programs. It includes:
    • istioctl. This directory contains code for the istioctl command line utility.
    • operator. This directory contains code for the Istio Operator.
    • pilot. This directory contains platform-specific code to populate the abstract service model, dynamically reconfigure the proxies when the application topology changes, as well as translate routing rules into proxy specific configuration.
    • security. This directory contains security related code, including Citadel (acting as Certificate Authority), citadel agent, etc.
  • istio/proxy. The Istio proxy contains extensions to the Envoy proxy (in the form of Envoy filters) that support authentication, authorization, and telemetry collection.

istio除了主库之外,还分散有其他库,比如架构中说到的proxy,就是最后一个库

可以看到istio的代码都是由Go编写的.

4. 基于ACK安装Istio

基于阿里云的容器服务k8s简称ACK,安装Istio,记录安装全过程
首先,需要登陆阿里云账号,找到ACK产品开通该服务,开通是免费的

4.1 创建ACK集群

其实就是创建k8s集群,阿里云提供了一键式创建K8s集群的能力
总结下来就是 买买买!!!
image.png
最低配置如上
注意: 开放公网ip

4.2 搭建bookinfo服务

Istio提供了示例程序,我们就用示例程序之一bookinfo来做应用部署
架构图:
image.png

4.2.1 下载示例程序

地址: https://github.com/zhangyao-zy/istio/tree/master/samples/bookinfo

4.2.2 安装示例程序镜像

我们要安装的配置文件有两个:

  1. bookinfo.yml 位于bookinfo/platform/kube/下
  2. bookinfo-gateway.yaml 位于 bookinfo/networking/下
4.2.2.1 配置namespace自动加注istio
kubectl label namespace default istio-injection=enabled

其实istio默认每个命名空间都会设置该参数
该参数的含义在于将会设置namespace下的所有pod都会自动注入sidecar

4.2.2.2 安装 bookinfo.yml

kube安装bookinfo.yml

kubectl apply -f bookinfo.yml

等待安装完成

# 查看pod/svc安装进度
kubectl get pod/svc -A

安装完成后可以找一个pod看下,会发现每一个pod里都多部署了一个容器,那就是网络代理

kubectl describe pod [pod名]
4.2.2.3 测试k8s内部调用

测试在pod内部调用微服务接口,看能否调用成功

kubeclt exec -it $(kubectl get pod -l app=ratings -o jsonpath='{.items[0].metadata.name}') -c ratings --curl productpage:9080/productpage | grep -o "<title>.*</title>"

进入ratings的容器,调用api,看是否能成功获取productpage页面.

4.2.2.4 安装bookinfo-gateway.yml
kubectl apply -f bookinfo-gateway.yml

安装完成后就可以通过公网访问bookinfo服务了
gateway其实就是k8s的ingress,底层是一个nginx,提供了k8s对外访问的能力

4.2.2.5 测试公网访问
# 获取gateway的对外暴露ip和端口 -n指定命名空间
kubectl get svc istio-ingressgateway -n instio-system

拿到ip端口后就可以通过公网ip和端口访问了

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐