本文主要侧重于 Istio
安装的部分,不再对 Istio
反复解释它的作用,它能干什么使用 - 因为主要太多的地方已经做了相关作用解释;本文在开始编写的时候 Istio
最新的版本已经到了 v1.10.1
并且你看到本文的时候安装方式可能发生了些许改变,但大致的安装方式基本相同;可能有小朋友会说安装的话参考官网就够了 - 嗯,确实如此;本人的目的一方面是为了巩固自己的理解,而另一方面算是一种总结,希望本文能够帮助那些该帮助的人吧 :)
对于目前在 Kubernetes 平台上的各种组件系统的安装思想模式本人根据所见所闻的经验归纳为以下几项:
Kubernetes Yaml
- 原生的 Kubernetes Yaml 文件直接利用kubectl create -f file.yaml
进行创建安装Helm Chart
- 在原生的配置基础上打成制品库的方式进行安装管理,可以理解把各种 Yaml 配置打成一个压缩包统一安装 - 按单个服务或应用进行单包管理,利用helm install
进行安装Operator
- 更进一步进行封装,以Istio Operator
作为代表 - 依赖 Kubernetes 的CRD
机制通过编写 Golang 语言实现CRD Controller
进行自定义Yaml
格式规范进行安装,具体可以参考 Kuberenetes CRD 指南Cmd ctl
- 通过客户端命令行的方式生成 Kubernetes 的 Yaml 清单进行应用,以istioctl
作为代表 - 本质上与第一种差不多,只不过命令行封装的更方便了一些
针对以上这四种方式,大家刚接触 Istio 的话也猜出来了,Istio 官方文档默认第一给出的是第四种方式 istioctl 进行安装,除此之外还给出了 Operator 的安装方式(即第三种方式),本文主要围绕这两种方式进行安装说明,并分为
简单方式
与进阶方式
。
1. 环境准备
Docker Desktop for Mac
- 由于我在 Mac 电脑上操作的,所以大家根据自己的情况进行变通 - 记得提前把Kubernetes
打开Istio v1.9.1
- 所有的说明均针对此版本进行展开,大家可以利用下述命令分别下载Istio
与Istioctl
- 下载完毕之后把istioctl
放入/usr/local/bin
目录中:- wget https://github.com/istio/istio/releases/download/1.9.1/istio-1.9.1-osx-arm64.tar.gz
- wget https://github.com/istio/istio/releases/download/1.9.1/istioctl-1.9.1-osx.tar.gz
2. 简单方式(Istioctl)
该方式主要利用 istioctl
进行客户端命令行工具输出 yaml
清单的原理进行安装,该方案虽然也会生成 istiooperator
的 CRD
资源配置(更多查看:4. 关于 CRD),但是其实只是一个配置的存储而已,背后不会有 Operator Server
进行 reconcile 进行同步操作,也就是说每次更新也是需要利用 istioctl
客户端工具再次处理的,示例如下:
注意:确保你的网络能够访问 docker.io 的站点,Istio 的所有镜像默认均放在该站点中,我们会在下述
镜像加速
中来指导如何处理镜像的问题。
2.1. 默认配置
通过以下命令安装,默认会采用 /manifests/profiles/default.yaml
该配置安装:
1
2
3
➜ istioctl install
Detected that your cluster does not support third party JWT authentication. Falling back to less secure first party JWT. See https://istio.io/v1.9/docs/ops/best-practices/security/#configure-third-party-service-account-tokens for details.
This will install the Istio 1.9.1 profile with ["Istio core" "Istiod" "Ingress gateways"] components into the cluster. Proceed? (y/N)
安装时的以上提示是
istioctl
会检测集群是否支持细粒度管理Pod
的ServiceAccount Token
,主要解决的是Pod
权限的安全问题,需要集群版本支持并在Kubernetes API Server
层面设置;具体可以点击文档提示链接查看,这里还有一篇 阿里云的中文文档 - 部署服务账户令牌卷投影 结合着看来理解;不过可以放心执行,因为集群不支持会自动降级到first-party-jwt
即命名空间下默认的Service Account Token
权限
安全成功之后会在 istio-system
命名空间下创建所需的资源,我们可以发现下述 CRD
实际上就是 /manifests/profiles/default.yaml
配置项内容:
1
2
3
➜ kubectl get istiooperator
NAME REVISION STATUS AGE
installed-state 54s
安全测试应用 BookInfo Application 来查看是否正常工作
1
2
3
4
5
➜ kubectl label namespace default istio-injection=enabled
➜ kubectl -n default apply -f samples/bookinfo/platform/kube/bookinfo.yaml
➜ kubectl -n default apply -f samples/bookinfo/platform/kube/bookinfo-ingress.yaml
➜ curl -s "http://localhost/productpage" | grep -o "<title>.*</title>"
<title>Simple Bookstore App</title>
关于 BookInfo Application 更多的示例演示内容可以参考官网:https://istio.io/latest/docs/examples/bookinfo/
当本地测试完毕之后需要卸载安装并进行资源的清理
1
2
3
➜ kubectl -n default delete -f samples/bookinfo/platform/kube/bookinfo.yaml
➜ kubectl -n default delete -f samples/bookinfo/platform/kube/bookinfo-ingress.yaml
➜ istioctl x uninstall --purge
2.2. 自定义配置
当我们明白 istioctl
该客户端工具的原理之后我们可以更进一步的自定义我们的 profile
配置,我们其实可以下述的方式来进一步管理 profile 配置:
查看已有的 Profile 列表(需要明白一件事就是
istioctl
其实已经把/manifests/profiles
所有文件嵌入到了二进制中去了,具体可以参考 v1.6.1 - assets.gen.go 或 v1.9.1 - create_assets_gen.sh 或 v1.10.1 - manifest.go
查看内置 Profile 列表
1
➜ istioctl profile list
指定清单目录并查看自定义 Profile 配置(首先我们复制
manifests/profiles/default.yaml
并新建一个manifests/profiles/caryyu.yaml
并追加下述profile
字段到yaml
配置中):1 2 3 4 5 6 7 8
# manifests/profiles/caryyu.yaml apiVersion: install.istio.io/v1alpha1 kind: IstioOperator metadata: namespace: istio-system spec: profile: caryyu ...
1 2 3 4 5 6 7 8 9 10 11
➜ cp manifests/profiles/default.yaml manifests/profiles/caryyu.yaml ➜ istioctl profile list -d manifests/ Istio configuration profiles: caryyu default demo empty minimal openshift preview remote
根据上述自定义的 Profile 我们可以根据以下命令进行安装:
1
➜ istioctl install -d manifests/ --set profile=caryyu
3. 进阶方式(CRD)
该方式首先需要安装 Operator Server
进行监听 CRD
的配置创建帮助我们处理整个 istio
核心组件安装过程,我们不再需要使用 istioctl
来完成整体安装,则是采用更为标准的 Kubernetes 操作方式进行,对于 CRD Controller - Operator Server
的安装方式,我们可以选择以下两种方式(默认会被安装到 istio-operator
命名空间):
3.1. 安装 Operator (Istioctl)
尽管我们可以不再使用 istioctl
来做整体部分的安装,但我们依然可以利用其提供的方便功能来安装我们所需的独立组件 CRD Controller - Operator Server
:
1
istioctl operator init
注意:如果镜像进行了加速处理,则可以根据
--hub
选项来指定仓库的路径前缀.
3.2. 安装 Operator (Helm)
由于 Istio
官方的 Helm Chart
存在兼容问题,我们可以直接利用 helm template
的方式安装这个 yaml
清单,在做此操作之前请先删除 istio-system
与 istio-operator
的命名空间;如果对该 Helm Chart
兼容问题感兴趣的可以关注 PR:https://github.com/istio/istio/pull/30741
1
➜ helm template manifests/charts/istio-operator/ | kubectl create -f -
3.3. 创建 CRD
紧接着,我们复制 manifests/profiles/default.yaml
新建文件 /tmp/istio-crd.yaml
并新增下述 name
字段开始应用创建该 CRD
:
1
2
3
4
5
6
7
# /tmp/istio-crd.yaml
apiVersion: install.istio.io/v1alpha1
kind: IstioOperator
metadata:
namespace: istio-system
name: istio-crd
...
1
2
3
➜ cp manifests/profiles/default.yaml /tmp/istio-crd.yaml
➜ kubectl create ns istio-system
➜ kubectl create -f /tmp/istio-crd.yaml
上述步骤操作完毕之后就会发现 istio-system
命名空间下开始自动启动一些 istio
核心组件的一些 pod
了,可以根据 kubectl -n istio-system get pod
进行查看,后续的功能调整只需要进行编辑 调整 istiooperator
的资源就可以了,相关操作如下:
1
2
➜ kubeclt get istiooperator
➜ kubectl edit istiooperator istio-crd
3.4. 测试
对于测试而言,我们依然可以采用上述的 BookInfo
方式,如下:
1
2
3
4
5
➜ kubectl label namespace default istio-injection=enabled
➜ kubectl -n default apply -f samples/bookinfo/platform/kube/bookinfo.yaml
➜ kubectl -n default apply -f samples/bookinfo/platform/kube/bookinfo-ingress.yaml
➜ curl -s "http://localhost/productpage" | grep -o "<title>.*</title>"
<title>Simple Bookstore App</title>
3.5. 卸载
1
2
3
➜ kubectl -n default delete -f samples/bookinfo/platform/kube/bookinfo.yaml
➜ kubectl -n default delete -f samples/bookinfo/platform/kube/bookinfo-ingress.yaml
➜ kubectl -n istio-system delete istiooperator istio-crd
对于 Helm 而言
1
➜ helm template manifests/charts/istio-operator/ | kubectl delete -f -
注意:这里会把
isito-operator
一并清掉
对于 Istioctl 而言
1
➜ istioctl operator remove
3.6. 其它
问题:为什么自定义的 Profile 在 Operator Server 的 reconcile 过程中会报错?
我们如果通过 Operator 的 Pod 日志查看找不到 Profile 的问题,问题就是我们在上述简单方式中已经提到了对于 Helm Chart
与 manifests/
目录而言,二进制已经把 Profile
包含进去了,对于 Operator Server
来说,它只认识默认的 Profile
列表(即:原始的 manifests/profiles/
目录),站在 CRD
角度来说,其实也没有必要进行自定义 profile
了,因为完全可以利用 kubectl -n istio-system edit istiooperator
的方式进行编辑调整来达到自定义的效果。
注意:这里所说的自定义
profile
更多指的是yaml
文件中的profile: caryyu
示例字段,如果不填写则是默认的,一旦填写就会出现找不到 Profile 的问题。
4. 关于 CRD
通过 istioctl
安装方式最后会生成一个叫 installed-state
的 CRD
(利用 kubectl get istiooperator
进行查看),该 CRD
的内容与我们安装时所用的 Profile
其实是一致的;需要注意的是名为 installed-state
的 CRD
是不会被 Operator Server
进行执行的,主要由两部分来判别:
- 该
CRD
会有一个额外的注解进行标记:install.istio.io/ignoreReconcile: "true"
- 该
CRD
的名称特征会被Operator Server
进行忽略,可以查看源码获知: operator/pkg/controller/istiocontrolplane/istiocontrolplane_controller.go 和 operator/pkg/name/name.go
5. 镜像加速
目前默认的镜像全部放在 docker.io/istio
该存储服务中,我们可以根据任意的 profile
打开查看到以下关键的配置,我们只需要把字段 hub
更换成我们最终的地址即可,但前提是我们需要把所有涉及到的镜像给处理完毕(手动进行 docker pull & docker push
方式),所有涉及到镜像列表参照以下:
1
2
3
4
5
6
7
apiVersion: install.istio.io/v1alpha1
kind: IstioOperator
metadata:
namespace: istio-system
spec:
hub: docker.io/istio
tag: 1.9.1
- docker.io/istio/pilot:1.9.1 - 这个是 istio 的核心组件,管理服务发现,证书配置,运行时代理配置等等
- docker.io/istio/install-cni:1.9.1 - 这个是 istio 自带的 CNI 组件,需要启动开启支持,主要解决的是网络安全问题
- docker.io/istio/proxyv2:1.9.1 - 这个是 istio 的核心组件,其中包括了
iptable
设置脚本及envoy
模块内容,ingress
,egress
和sidecar
均采用这个组件开展 - docker.io/istio/operator:1.9.1 - 这个是 istio operator server,其实与 CRD 配置清单中的
hub
字段无关,但可以在进阶方式
安装时设置
6. 最后
整个 Isiot 安装的的部分大概就只有这一些,虽然提到了四种安装方式,但其实最主要的就是 istioctl
与 CRD
两种方式,这也是 istio
官方最为推荐又或者目前最主流的两种安装模式,更多的文档可以参考官方安装文档如下:
如果上述碰到安装的问题有疑惑的地方,欢迎留言或 E-mail 发送消息进行联系,共同探讨,共同进步,谢谢 🙏