先决条件
部署步骤
使用 Helm 部署 Istio主要有以下两个步骤:
- 下载 Istio 发布包
- 部署 Istio
1. 下载 Istio 发布包
主要步骤:
- 下载和自动解压缩 Istio 发布包
- 配置 Istio 环境变量
-
下载和自动解压缩 Istio 发布包
curl -L https://git.io/getLatestIstio | ISTIO_VERSION=1.2.3 sh -
版本选择可以参考: Istio release 页面
-
配置 Istio 环境变量
cd istio-1.2.3 export PATH=$PWD/bin:$PATH
2. 部署 Istio
主要步骤:
- 改造 Tiller 客户端(为 Tiller 配置 Service account)
- 安装 istio-init(用于启动 Istio CRD 的安装过程)
- 部署 Istio (采用 demo 配置文件)
- 改造 Tiller 客户端(为 Tiller 配置 Service account)
-
卸载原有的 Tiller 客户端
helm reset
-
创建一个 Tiller 的 Service account
cd istio-1.2.3 kubectl apply -f install/kubernetes/helm/helm-service-account.yaml
-
安装 Tiller 并为其配置 Service account :
helm init --upgrade \ -i registry.cn-hangzhou.aliyuncs.com/google_containers/tiller:v2.14.3 \ --stable-repo-url https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts \ --service-account tiller
注:这里修改了另外两点:
1.设置 Tiller 的安装源为阿里云源
2.设置 Helm 的稳定存储库为阿里云的仓库
- 安装 istio-init(用于启动 Istio CRD 的安装过程)
注:这里启用了 cert-managerhelm install install/kubernetes/helm/istio-init --name istio-init --namespace istio-system --set certmanager.enabled=true
- 验证 CRD
注:启用了 cert-manager 时,CRD 的个数为 28 个,否则为 26 个kubectl get crds | grep 'istio.io\|certmanager.k8s.io' | wc -l
-
部署 Istio (采用 demo 配置文件)
helm install install/kubernetes/helm/istio --name istio --namespace istio-system \ --values install/kubernetes/helm/istio/values-istio-demo.yaml
注:虽然官方推荐的是使用 default 配置文件,但从官方的详细说明来看 demo 配置文件提供的功能更加完善,详细参考:https://istio.io/docs/setup/kubernetes/additional-setup/config-profiles/
-
卸载 Istio
helm delete --purge istio helm delete --purge istio-init
到这里,Istio 就已经安装完成了,但是由于不是托管云的原因,故还需对 Ingress-Gateway 进行适当改造
改造 Ingress-Gateway
在 Kubernetes 中,可以使用 Ingress 资源将集群内部的Service暴露到集群外部。
在 Istio 中,则推荐使用另一个更好的配置模型:Istio Gateway。
原因:Istio Gateway 可以允许我们将 Istio 的功能(如:监控和路由规则)应用到进入集群的流量。
Istio 部署时,同时也为我们安装了 Ingress-Gateway,且 Service 的类型为 LoadBalancer。由于不是公有云上的托管云,LoadBalancer 不能为我们分配合适的 EXTERNAL-IP,故需要进行一定的改造。改造的主要步骤如下:
- 修改 istio-ingressgateway 的 Service 参数
- 修改 istio-ingressgateway 的 Deployment 参数
- 删除 istio-ingressgateway 的水平扩展 HPA
- 修改 istio-ingressgateway 的 Service 参数
类型:
type: ClusterIP
-
删除各个
nodePort
kubectl edit svc istio-ingressgateway -n istio-system
修改后,如下:
apiVersion: v1 kind: Service metadata: ...... spec: clusterIP: 10.108.91.43 ports: - name: status-port port: 15020 protocol: TCP targetPort: 15020 - name: http2 port: 80 protocol: TCP targetPort: 80 - name: https port: 443 protocol: TCP targetPort: 443 - name: tcp port: 31400 protocol: TCP targetPort: 31400 - name: https-kiali port: 15029 protocol: TCP targetPort: 15029 - name: https-prometheus port: 15030 protocol: TCP targetPort: 15030 - name: https-grafana port: 15031 protocol: TCP targetPort: 15031 - name: https-tracing port: 15032 protocol: TCP targetPort: 15032 - name: tls port: 15443 protocol: TCP targetPort: 15443 selector: app: istio-ingressgateway istio: ingressgateway release: istio sessionAffinity: None type: ClusterIP
- 修改 istio-ingressgateway 的 Deployment 参数
- 网络设置:
hostNetwork: true
、dnsPolicy: ClusterFirstWithHostNet
- Node 亲和性调度:
nodeAffinity
- Pod 反亲和性调度:
podAntiAffinity
修改后,如下kubectl edit deploy istio-ingressgateway -n istio-system
apiVersion: extensions/v1beta1 kind: Deployment metadata: ...... spec: replicas: 2 ...... template: spec: ...... hostNetwork: true dnsPolicy: ClusterFirstWithHostNet affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: - matchExpressions: - key: node-role.kubernetes.io/edge operator: Exists podAntiAffinity: requiredDuringSchedulingIgnoredDuringExecution: - topologyKey: kubernetes.io/hostname labelSelector: matchExpressions: - key: app operator: In values: - istio-ingressgateway - key: istio operator: In values: - ingressgateway
- 删除 istio-ingressgateway 的水平扩展 HPA
由于 helm 部署的 istio-ingressgateway,同时为其创建了HPA。因为我们这里使用 hostNetwork,即将 istio-ingressgateway 固定调度到集群中的所有边缘节点上,所以需要手动删除这个 HPAkubectl delete HorizontalPodAutoscaler istio-ingressgateway -n istio-system
参考:
https://istio.io/zh/docs/setup/kubernetes/install/helm/
https://blog.frognew.com/2019/01/learning-istio-1.0-8-istio-install-with-helm.html