快速搭建开发环境 - Istio(最新版本)
关键词:istio、istio基础、快速搭建istio环境
前言
一、Istio 概述
Istio是一个开放平台,用于提供一种统一的方式来集成微服务、管理跨微服务的流量、执行策略和聚合遥测数据。Istio 的控制平面在底层集群管理平台(如 Kubernetes)上提供了一个抽象层。
Istio 由以下组件组成:
-
Envoy - 每个微服务的 Sidecar 代理,用于处理集群中服务之间以及从服务到外部服务的入口/出口流量。代理形成了一个*安全的微服务网格,*提供了一组丰富的功能,如发现、丰富的第 7 层路由、断路器、策略执行和遥测记录/报告功能。
注意:服务网格不是覆盖网络。它简化并增强了应用程序中的微服务通过底层平台提供的网络相互通信的方式。
-
Istiod - Istio 控制平面。它提供服务发现、配置和证书管理。它由以下子组件组成:
- Pilot - 负责在运行时配置代理。
- Citadel - 负责证书的颁发和轮换。
- Galley - 负责在 Istio 中验证、摄取、聚合、转换和分发配置。
-
Operator - 该组件提供用户友好的选项来操作 Istio 服务网格。
二、Istio 优势
三、搭建 Istio 环境
准备工作
硬件环境
Resource | Minimum | Recommended |
---|---|---|
CPU | 2 CPU | 4 CPU |
Mem | 4 GB | 8 GB |
Disk | 40 GB | 160 GB |
软件环境
Software | Version | Description |
---|---|---|
Kubernetes | v1.21.2 | 最新版本 |
注:istio 运行依赖上述环境
离线搭建 istio
-
第一步 下载安装包
istio-1.11.0-linux-amd64.tar.gz
-
第二步 解压
$ tar zxf istio-1.11.0-linux-amd64.tar.gz
我们看下解压后的目录
$ ll istio-1.11.0 total 28 drwxr-x---. 2 root root 22 Aug 12 16:17 bin -rw-r--r--. 1 root root 11348 Aug 12 16:17 LICENSE drwxr-xr-x. 5 root root 52 Aug 12 16:17 manifests -rw-r-----. 1 root root 854 Aug 12 16:17 manifest.yaml -rw-r--r--. 1 root root 5866 Aug 12 16:17 README.md drwxr-xr-x. 20 root root 4096 Aug 12 16:17 samples drwxr-xr-x. 3 root root 57 Aug 12 16:17 tools
istio-1.11.0/bin
目录$ ll istio-1.11.0/bin/ total 89920 -rwxr-xr-x. 1 root root 92078080 Aug 12 16:17 istioctl
istio-1.11.0/tools
目录$ ll istio-1.11.0/tools/ total 20 drwxr-xr-x. 2 root root 93 Aug 12 16:17 certs -rw-r--r--. 1 root root 6453 Aug 12 16:17 _istioctl -rw-r--r--. 1 root root 8808 Aug 12 16:17 istioctl.bash
istio-1.11.0/samples
目录可以看到
samples
目录有很多案例,我们搭好istio环境后,可以运行这些案例。$ istio-1.11.0/samples/ total 8 drwxr-xr-x. 3 root root 117 Aug 12 16:17 addons drwxr-xr-x. 6 root root 137 Aug 12 16:17 bookinfo drwxr-xr-x. 2 root root 4096 Aug 12 16:17 certs drwxr-xr-x. 2 root root 76 Aug 12 16:17 custom-bootstrap drwxr-xr-x. 3 root root 84 Aug 12 16:17 extauthz drwxr-xr-x. 2 root root 78 Aug 12 16:17 external drwxr-xr-x. 2 root root 71 Aug 12 16:17 health-check drwxr-xr-x. 3 root root 131 Aug 12 16:17 helloworld drwxr-xr-x. 3 root root 147 Aug 12 16:17 httpbin drwxr-xr-x. 3 root root 40 Aug 12 16:17 jwt-server drwxr-xr-x. 2 root root 91 Aug 12 16:17 kubernetes-blog drwxr-xr-x. 2 root root 140 Aug 12 16:17 multicluster drwxr-xr-x. 2 root root 162 Aug 12 16:17 operator drwxr-xr-x. 2 root root 37 Aug 12 16:17 ratelimit -rw-r--r--. 1 root root 98 Aug 12 16:17 README.md drwxr-xr-x. 3 root root 17 Aug 12 16:17 security drwxr-xr-x. 2 root root 65 Aug 12 16:17 sleep drwxr-xr-x. 3 root root 140 Aug 12 16:17 tcp-echo drwxr-xr-x. 2 root root 57 Aug 12 16:17 websockets
-
第三步 配置 istioctl 客户端
将istioctl添加到
PATH
下$ export PATH=$PATH:$(pwd)/istio-1.11.0/bin
验证
$ istioctl version no running Istio pods in "istio-system" 1.11.0
-
使用 Istioctl 客户端安装 Istio
$ istioctl install --set profile=demo $ istioctl manifest apply --set profile=demo
-
在默认命名空间开启自动注入 Envoy Sidecar
$ kubectl label namespace default istio-injection=enabled
通过上述操作,Istio 的环境就安装好了,你可以通过下面的命令查看 Istio 组件:
$ kubectl get svc -n istio-system NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE istio-egressgateway ClusterIP 10.99.80.130 <none> 80/TCP,443/TCP istio-ingressgateway LoadBalancer 10.111.68.181 <pending> 15021:31419/TCP,80:30581/TCP,443:30351/TCP,31400:30839/TCP,15443:30720/TCP 21m istiod ClusterIP 10.101.204.69 <none> 15010/TCP,15012/TCP,443/TCP,15014/TCP 22m
$ kubectl get pods -n istio-system NAME READY STATUS RESTARTS AGE istio-egressgateway-9dc6cbc49-2gp5j 1/1 Running 0 23m istio-ingressgateway-7975cdb749-v9m9j 1/1 Running 0 23m istiod-77b4d7b55d-zxj76 1/1 Running 0 24m
现在 Istio 以一个服务的形式部署在 Kubernetes 集群中。
-
第四步 安装插件
-
第五步 运行bookinfo案例
$ kubectl apply -f G:\istio-1.11.0-win\istio-1.11.0\samples\bookinfo\platform\kube\bookinfo.yaml service/details created serviceaccount/bookinfo-details created deployment.apps/details-v1 created service/ratings created serviceaccount/bookinfo-ratings created deployment.apps/ratings-v1 created service/reviews created serviceaccount/bookinfo-reviews created deployment.apps/reviews-v1 created deployment.apps/reviews-v2 created deployment.apps/reviews-v3 created service/productpage created serviceaccount/bookinfo-productpage created deployment.apps/productpage-v1 created $ kubectl get pods NAME READY STATUS RESTARTS AGE details-v1-79f774bdb9-4zlvm 0/1 ContainerCreating 0 19s productpage-v1-6b746f74dc-h6fbs 0/1 ContainerCreating 0 19s ratings-v1-b6994bb9-9zf6r 0/1 ContainerCreating 0 19s reviews-v1-545db77b95-dp4w4 0/1 ContainerCreating 0 19s reviews-v2-7bf8c9648f-rz6tz 0/1 ContainerCreating 0 19s reviews-v3-84779c7bbc-4j2jh 0/1 ContainerCreating 0 19s $ kubectl apply -f G:\istio-1.11.0-win\istio-1.11.0\samples\bookinfo\networking\bookinfo-gateway.yaml gateway.networking.istio.io/bookinfo-gateway created virtualservice.networking.istio.io/bookinfo created