一、官方数据

Istio 官网 安装|配置|部署选择

官方链接:https://istio.io/latest/zh/docs/setup/install/

Helm方式安装:https://istio.io/latest/zh/docs/setup/install/helm/

二、版本支持

Istio / Supported Releases

Istio 版本的支持状态:202504

ersion Currently Supported Release Date End of Life Supported Kubernetes Versions Tested, but not supported
master No, development only 1.29, 1.30, 1.31, 1.32 1.23, 1.24, 1.25, 1.26, 1.27, 1.28
1.25 Yes March 03, 2025 ~Dec 2025 (Expected) 1.29, 1.30, 1.31, 1.32 1.24, 1.25, 1.26, 1.27, 1.28
1.24 Yes November 7, 2024 ~Aug 2025 (Expected) 1.28, 1.29, 1.30, 1.31 1.23, 1.24, 1.25, 1.26, 1.27
1.23 Yes Aug 14, 2024 Apr 16, 2025 1.27, 1.28, 1.29, 1.30 1.23, 1.24, 1.25, 1.26
1.22 No May 13, 2024 Jan 22, 2025 1.27, 1.28, 1.29, 1.30 1.23, 1.24, 1.25, 1.26
1.21 No Mar 13, 2024 Sept 27, 2024 1.26, 1.27, 1.28, 1.29 1.23, 1.24, 1.25
1.20 No Nov 14, 2023 Jun 25, 2024 1.25, 1.26, 1.27, 1.28, 1.29 1.23, 1.24
1.19 No Sept 5, 2023 Apr 24, 2024 1.25, 1.26, 1.27, 1.28 1.21, 1.22, 1.23, 1.24
1.18 No Jun 3, 2023 Jan 4, 2024 1.24, 1.25, 1.26, 1.27 1.20, 1.21, 1.22, 1.23
1.17 No Feb 14, 2023 Oct 27, 2023 1.23, 1.24, 1.25, 1.26 1.16, 1.17, 1.18, 1.19, 1.20, 1.21, 1.22
1.16 No Nov 15, 2022 Jul 25, 2023 1.22, 1.23, 1.24, 1.25 1.16, 1.17, 1.18, 1.19, 1.20, 1.21
1.15 No Aug 31, 2022 Apr 4, 2023 1.22, 1.23, 1.24, 1.25 1.16, 1.17, 1.18, 1.19, 1.20, 1.21
1.14 No May 24, 2022 Dec 27, 2022 1.21, 1.22, 1.23, 1.24 1.16, 1.17, 1.18, 1.19, 1.20
1.13 No Feb 11, 2022 Oct 12, 2022 1.20, 1.21, 1.22, 1.23 1.16, 1.17, 1.18, 1.19

Istio最新版本为1.25,因为我的 Kubernetes集群版本为1.21.9,所以我们选择安装 Istio 1.14版本。

说明:本次实验中Istio最新版1.25,因为我的Kubernetes集群版本为1.26.9,所以我们选择安装Istio 1.20版本

三、基于operator方式的Istio架构图

3.1 为什么要用operator的方式来部署Istio呢?

  1. 自动化管理:Operator可以自动化地管理和操作Istio相关的资源,减少了手动部署 和配置的工作量。通过定义自定义资源和控制器,Operator可以识别和响应Istio配置的变更,并根据定义的规则自动执行相应的操作,提高了部署和更新的效率。

  2. 简化部署过程:使用Operator可以将Istio的部署过程简化为一次定义和配置运行时 环境的任务。咱们只需创建并定义必要的自定义资源对象,而无需手动创建和管理多个Kubernetes原生资源。Operator会根据这些自定义资源对象进行部署和配置, 大大简化了整个流程。

  3. 统一管理:通过Operator,可以将Istio的配置和管理集中在一个单独的控制器中。 我们可以通过定义自定义资源来描述和管理Istio的各种对象和规则,如路由规则、 安全策略等。这样可以避免了在多个地方进行配置和管理的复杂性,提高了可维护性和一致性。

  4. 可扩展性:使用Operator可以轻松扩展Istio的功能和组件。通过定义新的自定义资 源和相应的控制器,可以增加自定义的功能和规则,以满足特定的需求。这样可以根据具体场景和要求,灵活地扩展和定制Istio的能力。

  5. 可观察性和监控:通过集成Kiali、Prometheus等组件,Operator可以提供实时的 可观察性和监控功能。大家可以通过自定义资源对象来定义监控规则,并可视化展 示服务网格的拓扑图、流量图和性能指标等。这样可以方便地监测和调试服务之间的通信和性能,提高了可观察性和故障排查的能力。

3.2 主要架构图

在基于Operator的Istio部署中,Istio Operator会创建和配置必要的Kubernetes资源, 例如Istio控制平面、Istio代理和其他相关组件。它会监听来自用户对Istio的配置变更, 并根据需求自动调整和更新Istio的部署。Kiali和Prometheus等组件则作为附加功能被集成到Istio Operator中,以提供额外的可观察性和监控能力。

  1. Istio Operator:是一个自定义的Kubernetes Operator,用于管理和操作Istio相关 的资源。它负责监视和响应Kubernetes集群中的Istio配置变更,并且负责创建、更新和删除Istio的核心组件。
  2. Istiod:是Istio的核心控制平面组件,负责管理和调度整个服务网格的运行。Istiod 与Kubernetes API进行交互,接收来自Operator的指令,并将其转化为对Istio资源 的实际操作。它负责流量管理、安全性和策略执行等功能。
  3. Kiali:是Istio的可观察性工具,用于提供对服务网格的实时监控、可视化和分析。 Kiali集成到Istio Operator中,可以通过自定义资源定义监控规则,并将Istio中的数 据进行可视化展示,包括服务拓扑图、流量图等,以帮助用户了解和分析服务之间的通信和性能。
  4. Prometheus:是一种开源的监控和报警系统,用于收集和存储服务的度量指标。在 基于Operator的Istio部署中,Prometheus通常与Istio集成,用于收集来自Istio代理的度量指标数据,并提供基于这些数据的监控和警报功能。Prometheus可以通过配置Istio Operator中的自定义资源来进行集成。

Day10-服务治理-图5

四、Istio部署配置

4.1 Istio1.14版本部署配置

4.1.1 下载 Istio

在本实验中,我们将使用 Istio 1.14版本。安装 Istio 的第一步是下载 Istio CLI (istioctl)、安装清单、示例和工具。

安装最新版本的最简单方法是使用 downloadIstio 脚本。打开一个终端窗口,打开你 要下载Istio的文件夹,然后运行下载脚本。

下载istio最新版本命令为:

curl -L https://istio.io/downloadIstio | sh -

您可以在命令行上传递变量以下载特定版本或覆盖处理器架构。例如,要下载 x86_64 架构的 Istio 1.14.3,请运行:

curl -L https://istio.io/downloadIstio | \
ISTIO_VERSION=1.14.3 \
TARGET_ARCH=x86_64 \
sh -

或者直接去:https://github.com/istio/istio/releases/download/1.14.3/istio-1.14.3-linux-amd64.tar.gz 下载安装包,

下载安装包之后解压,istio-1.14.3/bin目录下可以看到istioctl,istio-1.14.3/samples目录下是示例应用程序。

为了访问 istioctl,我们应该把它添加到 path 中。

# pwd
/usr/local/src/istio/istio-1.14.3/bin

#临时生效
# export PATH=/usr/local/src/istio/istio-1.14.3/bin:$PATH

#永久生效
# vim ~/.bashrc

# cat ~/.bashrc
export ISTIOCTL_HOME="/usr/local/src/istio/istio-1.14.3"
export PATH="$PATH:/usr/local/src/istio/istio-1.14.3/bin"

# source ~/.bashrc

#验证
# istioctl version
no running Istio pods in "istio-system"
1.14.3

4.1.2 安装 Istio

Istio 支持多个配置文件(profile)。配置文件之间的区别在于所安装的组件。

# istioctl profile list
Istio configuration profiles:
  - default
  - demo
  - empty
  - external
  - minimal
  - openshift
  - preview
  - remote

这些配置文件提供了对 Istio 控制平面和 Istio 数据平面 Sidecar 的定制内容。

您可以从 Istio 内置配置文件的其中一个开始入手,然后根据您的特定需求进一步自定义配置文件。当前提供以下几种内置配置文件:

  1. default:根据 IstioOperator API 的默认设置启动组件。 建议用于生产部署和Multicluster Mesh 中的 Primary Cluster。

您可以运行 istioctl profile dump 命令来查看默认设置。

  1. demo:这一配置具有适度的资源需求,旨在展示 Istio 的功能。 它适合运行 Bookinfo 应用程序和相关任务。 这是通过快速开始指导安装的配置。此配置文件启 用了高级别的追踪和访问日志,因此不适合进行性能测试。

  2. minimal:与默认配置文件相同,但只安装了控制平面组件。 它允许您使用 Separate Profile 配置控制平面和数据平面组件(例如 Gateway)。

  3. remote:配置 Multicluster Mesh 的 Remote Cluster。

  4. empty:不部署任何东西。可以作为自定义配置的基本配置文件。

  5. preview:预览文件包含的功能都是实验性。这是为了探索 Istio 的新功能。不确保 稳定性、安全性和性能(使用风险需自负)。

标注 ✔ 的组件安装在每个配置文件中:

default demo minimal remote empty preview
核心组件
istio-egressgateway
istio-ingressgateway
istiod

推荐用于生产部署的配置文件是 default 配置文件。

我们将安装 demo 配置文件,因为它包含所有的核心组件,启用了跟踪和日志记录,便于学习不同的 Istio 功能。

我们也可以从 minimal 的组件开始,以后单独安装其他功能,如 ingress 和 egress 网关。

因为我们将使用 Istio Operator 进行安装,所以我们必须先部署 Operator。关于Istio Operator 简介可以查看:

https://istio.io/v1.14/zh/blog/2019/introducing-istio-operator/

部署 Istio Operator:

# istioctl operator init
Installing operator controller in namespace: istio-operator using
image: docker.io/istio/operator:1.14.3
Operator controller will watch namespaces: istio-system
✔ Istio operator installed
✔ Installation complete

init 命令创建了 istio-operator 命名空间,并部署了 CRD、OperatorDeployment 以及 operator 工作所需的其他资源。安装完成后,Operator 就可以使用了。

要安装 Istio,我们必须创建 IstioOperator 资源,并指定我们要使用的配置文件。

创建一个名为 istio-demo-profile.yaml的文件,内容如下:

#创建目录istioyaml,用来专门存放yaml文件
# mkdir istioyaml && cd istioyaml/

#profile: demo表示使用demo配置文件安装istio
# cat istio-demo-profile.yaml
apiVersion: v1
kind: Namespace
metadata:
  name: istio-system
---
apiVersion: install.istio.io/v1alpha1
kind: IstioOperator
metadata:
  namespace: istio-system
  name: demo-istio-install
spec:
  profile: demo

我们还在文件中添加了命名空间资源,以创建 istio-system 命名空间。

我们需要做的最后一件事是创建资源:

# kubectl apply -f istio-demo-profile.yaml

#可以查看istio-system命名空间下的所有资源
# kubectl get all -o wide -n istio-system

一旦 Operator 检测到 IstioOperator 资源,它将开始安装 Istio。整个过程可能需要5分钟左右。

为了检查安装的状态,我们可以看看 istio-system 命名空间中的 Pod 的状态。

# kubectl get pod -o wide -n istio-system

当所有的 Pod 都在运行时,Operator 已经完成了 Istio 的安装。

4.2 Istio1.20版本部署配置

4.2.1 下载 Istio

在本实验中,我们将使用 Istio 1.20.8版本。安装 Istio 的第一步是下载 Istio CLI (istioctl)、安装清单、示例和工具。

安装最新版本的最简单方法是使用 downloadIstio 脚本。打开一个终端窗口,打开你 要下载Istio的文件夹,然后运行下载脚本。

下载istio最新版本命令为:

curl -L https://istio.io/downloadIstio | sh -

您可以在命令行上传递变量以下载特定版本或覆盖处理器架构。例如,要下载 x86_64 架构的 Istio 1.20.8,请运行:

curl -L https://istio.io/downloadIstio | \
ISTIO_VERSION=1.20.8 \
TARGET_ARCH=x86_64 \
sh -

或者直接去:https://github.com/istio/istio/releases/download/1.20.8/istio-1.20.8-linux-amd64.tar.gz下载安装包,下载安装包之后解压,istio-1.20.8/bin目录下可以看到istioctl,istio-1.20.8/samples目录下是示例应用程序。

[root@master01 ~]# cd 10
[root@master01 10]# tar xf istio-1.20.8-linux-amd64.tar.gz 
[root@master01 10]# cd istio-1.20.8/
# istio-1.20.8/bin目录下可以看到istioctl
[root@master01 istio-1.20.8]# ls bin/
istioctl

# istio-1.20.8/samples目录下是示例应用程序
[root@master01 istio-1.20.8]# ls samples/
addons    cicd              external      helloworld  kind-lb         operator   security  wasm_modules
bookinfo  custom-bootstrap  grpc-echo     httpbin     multicluster    ratelimit  sleep     websockets
certs     extauthz          health-check  jwt-server  open-telemetry  README.md  tcp-echo

为了访问 istioctl,我们应该把它添加到 path 中。

#查看路径
[root@master01 bin]# pwd
/root/10/istio-1.20.8/bin

#临时生效
[root@master01 bin]# export PATH=/root/10/istio-1.20.8/bin:$PATH

#永久生效,末尾处添加
[root@master01 bin]# vim ~/.bashrc
export ISTIOCTL_HOME="/root/10/istio-1.20.8"
export PATH="$PATH:/root/10/istio-1.20.8/bin"

#验证
[root@master01 bin]# cat ~/.bashrc
export ISTIOCTL_HOME="/root/10/istio-1.20.8"
export PATH="$PATH:/root/10/istio-1.20.8/bin"

#配置生效 
[root@master01 bin]# source ~/.bashrc

#验证
[root@master01 10]# istioctl version
no ready Istio pods in "istio-system"
1.20.8

4.2.2 安装 Istio

Istio 支持多个配置文件(profile)。配置文件之间的区别在于所安装的组件。

# 查看配置文件
[root@master01 10]# istioctl profile list
Istio configuration profiles:
    ambient
    default
    demo
    empty
    external
    minimal
    openshift
    preview
    remote

这些配置文件提供了对 Istio 控制平面和 Istio 数据平面 Sidecar 的定制内容。

您可以从 Istio 内置配置文件的其中一个开始入手,然后根据您的特定需求进一步自定义配置文件。当前提供以下几种内置配置文件:

  1. default:根据 IstioOperator API 的默认设置启动组件。 建议用于生产部署和Multicluster Mesh 中的 Primary Cluster。

您可以运行 istioctl profile dump 命令来查看默认设置。

  1. demo:这一配置具有适度的资源需求,旨在展示 Istio 的功能。 它适合运行 Bookinfo 应用程序和相关任务。 这是通过快速开始指导安装的配置。此配置文件启 用了高级别的追踪和访问日志,因此不适合进行性能测试。

  2. minimal:与默认配置文件相同,但只安装了控制平面组件。 它允许您使用 Separate Profile 配置控制平面和数据平面组件(例如 Gateway)。

  3. remote:配置 Multicluster Mesh的 Remote Cluster。

  4. empty:不部署任何东西。可以作为自定义配置的基本配置文件。

  5. preview:预览文件包含的功能都是实验性。这是为了探索 Istio 的新功能。不确保 稳定性、安全性和性能(使用风险需自负)。

标注 ✔ 的组件安装在每个配置文件中:

default demo minimal remote empty preview
核心组件
istio-egressgateway
istio-ingressgateway
istiod

推荐用于生产部署的配置文件是 default 配置文件。

我们将安装 demo 配置文件,因为它包含所有的核心组件,启用了跟踪和日志记录,便于学习不同的 Istio 功能。

我们也可以从 minimal 的组件开始,以后单独安装其他功能,如 ingress 和 egress 网关。

因为我们将使用 Istio Operator 进行安装,所以我们必须先部署 Operator。关于Istio Operator 简介可以查看:

https://istio.io/v1.14/zh/blog/2019/introducing-istio-operator/

部署 Istio Operator:

国外环境

[root@master01 10]# istioctl operator init
Installing operator controller in namespace: istio-operator using
image: docker.io/istio/operator:1.20.8
Operator controller will watch namespaces: istio-system
✔ Istio operator installed
✔ Installation complete

国内环境

#创建目录istioyaml,用来专门存放yaml文件
[root@master01 10]# mkdir istioyaml && cd istioyaml/
[root@master01 istioyaml]# istioctl operator dump > operator-config.yaml
[root@master01 istioyaml]# vim operator-config.yaml 
# 修改第156行内容
156           image: registry.cn-hangzhou.aliyuncs.com/abroad_images/operator:1.20.8

#完整配置文件
[root@master01 istioyaml]# vim  operator-config.yaml 
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  creationTimestamp: null
  name: istio-operator
rules:
# istio groups
- apiGroups:
  - authentication.istio.io
  resources:
  - '*'
  verbs:
  - '*'
- apiGroups:
  - config.istio.io
  resources:
  - '*'
  verbs:
  - '*'
- apiGroups:
  - install.istio.io
  resources:
  - '*'
  verbs:
  - '*'
- apiGroups:
  - networking.istio.io
  resources:
  - '*'
  verbs:
  - '*'
- apiGroups:
  - security.istio.io
  resources:
  - '*'
  verbs:
  - '*'
# k8s groups
- apiGroups:
  - admissionregistration.k8s.io
  resources:
  - mutatingwebhookconfigurations
  - validatingwebhookconfigurations
  verbs:
  - '*'
- apiGroups:
  - apiextensions.k8s.io
  resources:
  - customresourcedefinitions.apiextensions.k8s.io
  - customresourcedefinitions
  verbs:
  - '*'
- apiGroups:
  - apps
  - extensions
  resources:
  - daemonsets
  - deployments
  - deployments/finalizers
  - replicasets
  verbs:
  - '*'
- apiGroups:
  - autoscaling
  resources:
  - horizontalpodautoscalers
  verbs:
  - '*'
- apiGroups:
  - monitoring.coreos.com
  resources:
  - servicemonitors
  verbs:
  - get
  - create
  - update
- apiGroups:
  - policy
  resources:
  - poddisruptionbudgets
  verbs:
  - '*'
- apiGroups:
  - rbac.authorization.k8s.io
  resources:
  - clusterrolebindings
  - clusterroles
  - roles
  - rolebindings
  verbs:
  - '*'
- apiGroups:
  - coordination.k8s.io
  resources:
  - leases
  verbs:
  - get
  - create
  - update
- apiGroups:
  - ""
  resources:
  - configmaps
  - endpoints
  - events
  - namespaces
  - pods
  - pods/proxy
  - pods/portforward
  - persistentvolumeclaims
  - secrets
  - services
  - serviceaccounts
  - resourcequotas
  verbs:
  - '*'
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: istio-operator
subjects:
- kind: ServiceAccount
  name: istio-operator
  namespace: istio-operator
roleRef:
  kind: ClusterRole
  name: istio-operator
  apiGroup: rbac.authorization.k8s.io
---

---
apiVersion: apps/v1
kind: Deployment
metadata:
  namespace: istio-operator
  name: istio-operator
spec:
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      name: istio-operator
  template:
    metadata:
      labels:
        name: istio-operator
      annotations:
        prometheus.io/port: "15014"
        prometheus.io/scrape: "true"
    spec:
      serviceAccountName: istio-operator
      containers:
        - name: istio-operator
          image: registry.cn-hangzhou.aliyuncs.com/abroad_images/operator:1.20.8 
          command:
          - operator
          - server
          - --monitoring-host=127.0.0.1
          - --monitoring-port=15014
          securityContext:
            allowPrivilegeEscalation: false
            capabilities:
              drop:
              - ALL
            privileged: false
            readOnlyRootFilesystem: true
            runAsNonRoot: true
          resources:
            limits:
              cpu: 200m
              memory: 256Mi
            requests:
              cpu: 50m
              memory: 128Mi
          env:
            - name: WATCH_NAMESPACE
              value: "istio-system"
            - name: LEADER_ELECTION_NAMESPACE
              value: "istio-operator"
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: OPERATOR_NAME
              value: "istio-operator"
            - name: WAIT_FOR_RESOURCES_TIMEOUT
              value: "300s"
            - name: REVISION
              value: ""
---
apiVersion: v1
kind: Service
metadata:
  namespace: istio-operator
  labels:
    name: istio-operator
  name: istio-operator
spec:
  ports:
  - name: http-metrics
    port: 8383
    targetPort: 8383
    protocol: TCP
  selector:
    name: istio-operator
---
apiVersion: v1
kind: ServiceAccount
metadata:
  namespace: istio-operator
  name: istio-operator
---
# SYNC WITH manifests/charts/base/files
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: istiooperators.install.istio.io
  labels:
    release: istio
spec:
  conversion:
    strategy: None
  group: install.istio.io
  names:
    kind: IstioOperator
    listKind: IstioOperatorList
    plural: istiooperators
    singular: istiooperator
    shortNames:
    - iop
    - io
  scope: Namespaced
  versions:
  - additionalPrinterColumns:
    - description: Istio control plane revision
      jsonPath: .spec.revision
      name: Revision
      type: string
    - description: IOP current state
      jsonPath: .status.status
      name: Status
      type: string
    - description: 'CreationTimestamp is a timestamp representing the server time
        when this object was created. It is not guaranteed to be set in happens-before
        order across separate operations. Clients may not set this value. It is represented
        in RFC3339 form and is in UTC. Populated by the system. Read-only. Null for
        lists. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata'
      jsonPath: .metadata.creationTimestamp
      name: Age
      type: date
    name: v1alpha1
    subresources:
      status: {}
    schema:
      openAPIV3Schema:
        type: object
        x-kubernetes-preserve-unknown-fields: true
    served: true
    storage: true
---

# 初始化
[root@master01 istioyaml]# kaf operator-config.yaml 

# 验证
[root@master01 istioyaml]# kg -f  operator-config.yaml 
NAME                                                   CREATED AT
clusterrole.rbac.authorization.k8s.io/istio-operator   2025-04-16T12:25:58Z

NAME                                                          ROLE                         AGE
clusterrolebinding.rbac.authorization.k8s.io/istio-operator   ClusterRole/istio-operator   30s

NAME                             READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/istio-operator   1/1     1            1           30s

NAME                     TYPE        CLUSTER-IP        EXTERNAL-IP   PORT(S)    AGE
service/istio-operator   ClusterIP   192.168.167.186   <none>        8383/TCP   30s

NAME                            SECRETS   AGE
serviceaccount/istio-operator   1         29s

NAME                                                                            CREATED AT
customresourcedefinition.apiextensions.k8s.io/istiooperators.install.istio.io   2025-04-16T12:25:59Z

init 命令创建了 istio-operator 命名空间,并部署了 CRD、OperatorDeployment 以及 operator 工作所需的其他资源。安装完成后,Operator 就可以使用了。

要安装 Istio,我们必须创建 Istio Operator 资源,并指定我们要使用的配置文件。

创建一个名为 istio-demo-profile.yaml的文件,内容如下:

#profile: demo表示使用demo配置文件安装istio
[root@master01 istioyaml]# vim istio-demo-profile.yaml
apiVersion: v1
kind: Namespace
metadata:
  name: istio-system
---
apiVersion: install.istio.io/v1alpha1
kind: IstioOperator
metadata:
  namespace: istio-system
  name: demo-istio-install
spec:
  profile: demo
  values:
    global:
      hub: registry.cn-hangzhou.aliyuncs.com/github_images1024
      tag: 1.20.8  

我们还在文件中添加了命名空间资源,以创建 istio-system 命名空间。

我们需要做的最后一件事是创建资源:

[root@master01 istioyaml]# kg -f istio-demo-profile.yaml
NAME                     STATUS   AGE
namespace/istio-system   Active   4m52s

NAME                                                REVISION   STATUS    AGE
istiooperator.install.istio.io/demo-istio-install              HEALTHY   4m52s

#可以查看istio-system命名空间下的所有资源
[root@master01 istioyaml]# kubectl get all -o wide -n istio-system
NAME                                        READY   STATUS    RESTARTS   AGE     IP              NODE       NOMINATED NODE   READINESS GATES
pod/istio-egressgateway-7cbb4d6cff-nzglx    1/1     Running   0          4m56s   172.20.59.223   master02   <none>           <none>
pod/istio-ingressgateway-7f8c8c6db7-lf5gw   1/1     Running   0          79s     172.20.59.238   master02   <none>           <none>
pod/istiod-77cc598c96-79ln4                 1/1     Running   0          5m6s    172.20.59.220   master02   <none>           <none>

NAME                           TYPE           CLUSTER-IP        EXTERNAL-IP   PORT(S)                                                                      AGE     SELECTOR
service/istio-egressgateway    ClusterIP      192.168.139.213   <none>        80/TCP,443/TCP                                                               4m56s   app=istio-egressgateway,istio=egressgateway
service/istio-ingressgateway   LoadBalancer   192.168.149.121   10.0.0.12     15021:31360/TCP,80:31978/TCP,443:31805/TCP,31400:30191/TCP,15443:30922/TCP   4m56s   app=istio-ingressgateway,istio=ingressgateway
service/istiod                 ClusterIP      192.168.154.52    <none>        15010/TCP,15012/TCP,443/TCP,15014/TCP                                        5m6s    app=istiod,istio=pilot

NAME                                   READY   UP-TO-DATE   AVAILABLE   AGE     CONTAINERS    IMAGES                                                               SELECTOR
deployment.apps/istio-egressgateway    1/1     1            1           4m56s   istio-proxy   registry.cn-hangzhou.aliyuncs.com/github_images1024/proxyv2:1.20.8   app=istio-egressgateway,istio=egressgateway
deployment.apps/istio-ingressgateway   1/1     1            1           4m56s   istio-proxy   registry.cn-hangzhou.aliyuncs.com/github_images1024/proxyv2:1.20.8   app=istio-ingressgateway,istio=ingressgateway
deployment.apps/istiod                 1/1     1            1           5m6s    discovery     registry.cn-hangzhou.aliyuncs.com/github_images1024/pilot:1.20.8     istio=pilot

NAME                                              DESIRED   CURRENT   READY   AGE     CONTAINERS    IMAGES                                                               SELECTOR
replicaset.apps/istio-egressgateway-7cbb4d6cff    1         1         1       4m56s   istio-proxy   registry.cn-hangzhou.aliyuncs.com/github_images1024/proxyv2:1.20.8   app=istio-egressgateway,istio=egressgateway,pod-template-hash=7cbb4d6cff
replicaset.apps/istio-ingressgateway-7f8c8c6db7   1         1         1       4m56s   istio-proxy   registry.cn-hangzhou.aliyuncs.com/github_images1024/proxyv2:1.20.8   app=istio-ingressgateway,istio=ingressgateway,pod-template-hash=7f8c8c6db7
replicaset.apps/istiod-77cc598c96                 1         1         1       5m6s    discovery     registry.cn-hangzhou.aliyuncs.com/github_images1024/pilot:1.20.8     istio=pilot,pod-template-hash=77cc598c96

一旦 Operator 检测到 IstioOperator 资源,它将开始安装 Istio。整个过程可能需要5分钟左右。

为了检查安装的状态,我们可以看看 istio-system 命名空间中的 Pod 的状态。

[root@master01 istioyaml]# kubectl get pod -o wide -n istio-system
NAME                                    READY   STATUS    RESTARTS   AGE     IP              NODE       NOMINATED NODE   READINESS GATES
istio-egressgateway-7cbb4d6cff-nzglx    1/1     Running   0          5m18s   172.20.59.223   master02   <none>           <none>
istio-ingressgateway-7f8c8c6db7-lf5gw   1/1     Running   0          101s    172.20.59.238   master02   <none>           <none>
istiod-77cc598c96-79ln4                 1/1     Running   0          5m28s   172.20.59.220   master02   <none>           <none>

当所有的 Pod 都在运行时,Operator 已经完成了 Istio 的安装。

五、启用 sidecar 注入

服务网格需要让每个应用程序同时运行

要将 sidecar 代理注入到现有的 的 kube-inject 动作。

然而,我们也可以在任意 Kubernetes 命名空间上启用 sidecar 自动注入。如果我们用istio-injection=enabled 标记命名空间,Istio 会自动为我们在该命名空间中创建的所有 Kubernetes Pod 注入 sidecar。

让我们通过添加标签来启用 microservice 命名空间的 sidecar 自动注入。

#创建命名空间
[root@master01 istioyaml]# kubectl create ns microservice

#给命名空间打标签
[root@master01 istioyaml]# kubectl label namespace microservice istio-injection=enabled

#验证,目前无资源
[root@master01 istioyaml]# kgp -n microservice 
No resources found in microservice namespace.

要检查命名空间是否被标记,请运行下面的命令。 microservice 命名空间应该是唯一一个启用了该值的命名空间。

[root@master01 istioyaml]# kubectl get namespace -L istio-injection | grep enabled
microservice           Active   3m13s   enabled

现在我们可以尝试在 microservice 命名空间创建一个 Deployment,并观察注入的代理。我们将创建一个名为 mynginx 的 Deployment,使用hub.c.163.com/library/nginx:latest 镜像的单一容器

# 创建
[root@master01 istioyaml]# kubectl create deployment mynginx --image=hub.c.163.com/library/nginx:latest -n microservice

如果我们看一下 Pod,你会发现 Pod 里有两个容器。

# 查看Deployment
[root@master01 istioyaml]# kubectl get deployment -n microservice
NAME      READY   UP-TO-DATE   AVAILABLE   AGE
mynginx   1/1     1            1           66s

# 查看pod
[root@master01 istioyaml]# kgp -n  microservice
NAME                       READY   STATUS    RESTARTS   AGE
mynginx-6f8dc84486-2nsw2   2/2     Running   0          27s

同样地,描述 Pod 时会显示 Kubernetes 同时创建了一个 nginx 容器和一个 istio-proxy 容器:

[root@master01 istioyaml]# kubectl describe pod mynginx-6f8dc84486-2nsw2 -n microservice
...
...
Events:
  Type     Reason     Age   From               Message
  ----     ------     ----  ----               -------
  Normal   Scheduled  100s  default-scheduler  Successfully assigned microservice/mynginx-6f8dc84486-2nsw2 to master02
  Normal   Pulled     100s  kubelet            Container image "registry.cn-hangzhou.aliyuncs.com/github_images1024/proxyv2:1.20.8" already present on machine
  Normal   Created    100s  kubelet            Created container istio-init
  Normal   Started    100s  kubelet            Started container istio-init
  Normal   Pulling    99s   kubelet            Pulling image "hub.c.163.com/library/nginx:latest"
  Normal   Pulled     79s   kubelet            Successfully pulled image "hub.c.163.com/library/nginx:latest" in 20.746829761s (20.74684513s including waiting)
  Normal   Created    78s   kubelet            Created container nginx
  Normal   Started    78s   kubelet            Started container nginx
  Normal   Pulled     78s   kubelet            Container image "registry.cn-hangzhou.aliyuncs.com/github_images1024/proxyv2:1.20.8" already present on machine
  Normal   Created    78s   kubelet            Created container istio-proxy
  Normal   Started    78s   kubelet            Started container istio-proxy
  Warning  Unhealthy  78s   kubelet            Startup probe failed: Get "http://172.20.59.240:15021/healthz/ready": dial tcp 172.20.59.240:15021: connect: connection refused

运行下面的命令,删除deployment:

[root@master01 istioyaml]# kubectl delete deployment mynginx -n microservice

六、更新和卸载Istio

如果我们想更新当前的安装或改变配置文件,那么需要更新先前部署的IstioOperator资源。

要删除安装,我们必须删除 IstioOperator ,例如:

# kubectl get istiooperator -n istio-system

# # kubectl delete istiooperator demo-istio-install -n istio-system

在 Operator 删除了Istio 后,运行下面的命令来删除 Operator:

# istioctl operator remove

请确保在删除 Operator 之前先删除 IstioOperator 资源。否则,可能会有剩余的Istio资源

要从集群中完整卸载 Istio,运行下面卸载命令:

# istioctl x uninstall --purge

可选的 --purge 参数将删除所有的 Istio 资源,包括可能被其他 Istio 控制平面共享的、集群范围的资源