前言
Istio 架構(gòu)又換了,從 1.5 開始,把控制平面的所有組件組合并成一個單體結(jié)構(gòu)叫 istiod,對于運維部署來說省去很大麻煩。Mixer 組件被移除,新版本的 HTTP 遙測默認(rèn)基于 in-proxy Stats filter,同時可使用 WebAssembly 開發(fā) in-proxy 擴展。
下面展示 Istio 架構(gòu)圖前世與今生:
前世

前世
今生

今生
環(huán)境要求 [1]
Kubernetes 版本支持
- 按官方話來說,Istio 1.5 已在以下 Kubernetes 發(fā)布版本測試過:1.14, 1.15, 1.16。
Kubernetes Pod 和 Service 要求
作為 Istio 服務(wù)網(wǎng)格中的一部分,Kubernetes 集群中的 Pod 和 Service 必須滿足以下要求:
- 命名的服務(wù)端口: Service 的端口必須命名。端口名鍵值對必須按以下格式:
name: <protocol>[-<suffix>]。更多說明請參看協(xié)議選擇。 - Service 關(guān)聯(lián): 每個 Pod 必須至少屬于一個 Kubernetes Service,不管這個 Pod 是否對外暴露端口。如果一個 Pod 同時屬于多個 Kubernetes Service, 那么這些 Service 不能同時在一個端口號上使用不同的協(xié)議(比如:HTTP 和 TCP)。
- 帶有 app 和 version 標(biāo)簽(label) 的 Deployment: 我們建議顯式地給 Deployment 加上 app 和 version 標(biāo)簽。給使用 Kubernetes Deployment 部署的 Pod 部署配置中增加這些標(biāo)簽,可以給 Istio 收集的指標(biāo)和遙測信息中增加上下文信息。
- app 標(biāo)簽:每個部署配置應(yīng)該有一個不同的 app 標(biāo)簽并且該標(biāo)簽的值應(yīng)該有一定意義。app label 用于在分布式追蹤中添加上下文信息。
- version 標(biāo)簽:這個標(biāo)簽用于在特定方式部署的應(yīng)用中表示版本。
- 應(yīng)用 UID: 確保你的 Pod 不會以用戶 ID(UID)為 1337 的用戶運行應(yīng)用。
- NET_ADMIN 功能: 如果你的集群執(zhí)行 Pod 安全策略,必須給 Pod 配置 NET_ADMIN 功能。如果你使用 Istio CNI 插件 可以不配置。要了解更多 NET_ADMIN 功能的知識,請查看所需的 Pod 功能。
下載 Istio 1.15 版本
注意:Linux 操作系統(tǒng)
1.下載 Istio 1.15.1 安裝包
$ cd /usr/local/src/
$ wget https://github.com/istio/istio/releases/download/1.5.1/istio-1.5.1-linux.tar.gz
$ tar xf istio-1.5.1-linux.tar.gz
2.切換 Istio 包所在目錄
$ cd istio-1.5.1
安裝目錄包含如下內(nèi)容:
- install/kubernetes 目錄下,有 Kubernetes 相關(guān)的 YAML 安裝文件
- samples/ 目錄下,有示例應(yīng)用程序
- bin/ 目錄下,包含 istioctl 的客戶端文件。istioctl 工具用于手動注入 Envoy sidecar 代理。
3.將 istioctl 命令添加到環(huán)境變量中
# 在 ~/.bashrc 中添加一行
$ vim ~/.bashrc
PATH="$PATH:/usr/local/src/istio-1.5.1/bin"
# 應(yīng)用生效
$ source ~/.bashrc
4.配置 istioctl 參數(shù)自動補全
$ vim ~/.bashrc
source /usr/local/src/istio-1.5.1/tools/istioctl.bash
# 應(yīng)用生效
$ source ~/.bashrc
部署
istioctl 提供了多種安裝配置文件,它們之間差異:

image
安裝配置提要:
-
default基礎(chǔ)上開啟Grafana、istio-tracing、kiali附加組件 -
cni配置關(guān)閉,但相關(guān)參數(shù)已配置 - 全局禁用
TLS -
Grafana、istio-tracing、kiali、prometheus通過istio-ingressgateway暴露 - 排除
192.168.16.0/20,192.168.32.0/20k8s svc 和 k8s pod 兩個網(wǎng)段 -
Ingress Gateway與pilot開啟2個pod(默認(rèn)1個pod) - Pod 綁定節(jié)點標(biāo)簽
zone: sz -
Ingress Gateway使用HostNetwork模式暴露 -
overlays字段用來修改對應(yīng)組件的各個資源對象的manifest - 調(diào)整
PDB配置 - 安裝前需要創(chuàng)建
grafana和kialisecret,用于登陸 -
Ingress Gateway從安全的角度來考慮,不應(yīng)該暴露那些不必要的端口,對于 Ingress Gateway 來說,只需要暴露 HTTP、HTTPS 和 metrics 端口就夠了
配置 grafana 和 kiali secret
創(chuàng)建 istio-system namespaces
$ kubectl create ns istio-system
配置 kiali secret
$ KIALI_USERNAME=$(echo -n 'admin' | base64)
$ KIALI_PASSPHRASE=$(echo -n 'admin' | base64)
$ NAMESPACE=istio-system
$ cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Secret
metadata:
name: kiali
namespace: $NAMESPACE
labels:
app: kiali
type: Opaque
data:
username: $KIALI_USERNAME
passphrase: $KIALI_PASSPHRASE
EOF
配置 grafana secret
$ GRAFANA_USERNAME=$(echo -n 'admin' | base64)
$ GRAFANA_PASSPHRASE=$(echo -n 'admin' | base64)
$ NAMESPACE=istio-system
$ cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Secret
metadata:
name: grafana
namespace: $NAMESPACE
labels:
app: grafana
type: Opaque
data:
username: $GRAFANA_USERNAME
passphrase: $GRAFANA_PASSPHRASE
EOF
推薦使用 Operator 方式進行部署,這里使用 default 配置部署(default 也是用于生產(chǎn)環(huán)境)
創(chuàng)建 Istio Operator yaml 配置
$ vim istio-1.5.1.yaml
apiVersion: install.istio.io/v1alpha1
kind: IstioOperator
metadata:
namespace: istio-system
name: istio-1.5.1-controlplane
spec:
hub: docker.io/istio
profile: default # 使用默認(rèn)配置
tag: 1.5.1
addonComponents:
grafana:
enabled: true # 默認(rèn) false
k8s:
replicaCount: 1
kiali:
enabled: true # 默認(rèn) false
k8s:
replicaCount: 1
prometheus:
enabled: true # 默認(rèn) true
k8s:
replicaCount: 1
tracing:
enabled: true # 默認(rèn) false
values:
global:
imagePullPolicy: IfNotPresent # 鏡像拉取策略
mtls:
enabled: false # 全局禁用安全性
defaultResources: # 聲明默認(rèn)容器資源
requests:
cpu: 30m
memory: 50Mi
proxy:
accessLogFile: "/dev/stdout"
includeIPRanges: 192.168.16.0/20,192.168.32.0/20
autoInject: disabled # 是否開啟自動注入功能,取值enabled則該pods只要沒有被注解為sidecar.istio.io/inject: "false",就會自動注入。如果取值為disabled,則需要為pod設(shè)置注解sidecar.istio.io/inject: "true"才會進行注入
clusterDomain: cluster.local # 集群DNS域
resources:
requests:
cpu: 30m # 默認(rèn) 100m
memory: 50Mi # 默認(rèn) 128Mi
limits:
cpu: 400m # 默認(rèn) 2000m
memory: 500Mi # 默認(rèn) 1024Mi
proxy_init:
resources:
limits:
cpu: 100m
memory: 50Mi
requests:
cpu: 30m # 默認(rèn) 10m
memory: 50Mi # 默認(rèn) 10Mi
sidecarInjectorWebhook:
enableNamespacesByDefault: false # 變量為true,就會為所有命名空間開啟自動注入功能。如果賦值為false,則只有標(biāo)簽為istio-injection的命名空間才會開啟自動注入功能
rewriteAppHTTPProbe: false # 如果是 true,webhook 或 istioctl injector 將為活性健康檢查重寫 PodSpec 以重定向請求到 sidecar。這使得即使在啟用 mTLS 時,活性檢查也可以工作
cni:
excludeNamespaces: # 開啟cni功能時,下面namespaces被排除
- istio-system
- kube-system
- monitoring
- kube-node-lease
- kube-public
- kubernetes-dashboard
- ingress-nginx
logLevel: info
pilot:
autoscaleEnabled: true
autoscaleMax: 5
autoscaleMin: 1
cpu:
targetAverageUtilization: 80
prometheus:
contextPath: /prometheus # 默認(rèn) /prometheus
hub: docker.io/prom
resources: # 默認(rèn)無限制
requests:
cpu: 30m
memory: 50Mi
limits:
cpu: 500m
memory: 1024Mi
nodeSelector:
zone: "sz"
retention: 7d # 默認(rèn) 6h
scrapeInterval: 15s
security:
enabled: true
tag: v2.15.1
grafana:
contextPath: /grafana # 默認(rèn) /grafana
accessMode: ReadWriteMany
image:
repository: grafana/grafana
tag: 6.5.2
resources:
requests:
cpu: 30m
memory: 50Mi
limits:
cpu: 300m
memory: 500Mi
nodeSelector:
zone: "sz"
security: # 默認(rèn)關(guān)閉認(rèn)證
enabled: true # 默認(rèn) false
passphraseKey: passphrase # 首先創(chuàng)建 grafana secret
secretName: grafana
usernameKey: username # 首先創(chuàng)建 grafana secret
kiali:
contextPath: /kiali # 默認(rèn) /kiali
createDemoSecret: false
dashboard:
grafanaInClusterURL: http://grafana.example.com # 默認(rèn) http://grafana:3000
jaegerInClusterURL: http://tracing.example.com # 默認(rèn) http://tracing/jaeger
passphraseKey: passphrase # 首先創(chuàng)建 kiali secret
secretName: kiali
usernameKey: username # 首先創(chuàng)建 kiali secret
viewOnlyMode: false
hub: kiali # 默認(rèn) quay.io/kiali
resources:
limits:
cpu: 300m
memory: 900Mi
requests:
cpu: 30m
memory: 50Mi
nodeSelector:
zone: "sz"
tag: v1.14
tracing:
provider: jaeger # 選擇跟蹤服務(wù)
jaeger:
accessMode: ReadWriteMany
hub: docker.io/jaegertracing
tag: "1.16"
resources:
limits:
cpu: 300m
memory: 900Mi
requests:
cpu: 30m
memory: 100Mi
nodeSelector:
zone: "sz"
opencensus:
exporters:
stackdriver:
enable_tracing: true
hub: docker.io/omnition
resources:
limits:
cpu: "1"
memory: 2Gi
requests:
cpu: 100m # 默認(rèn) 200m
memory: 300Mi # 默認(rèn) 400Mi
tag: 0.1.9
zipkin:
hub: docker.io/openzipkin
javaOptsHeap: 700
maxSpans: 500000
node:
cpus: 2
resources:
limits:
cpu: 300m
memory: 900Mi
requests:
cpu: 30m # 默認(rèn) 150m
memory: 100Mi # 默認(rèn) 900Mi
tag: 2.14.2
components:
cni:
enabled: false # 默認(rèn)不啟用cni功能
ingressGateways:
- enabled: true
k8s:
hpaSpec:
minReplicas: 2 # 默認(rèn)最小為1個pod
service:
type: ClusterIP # 默認(rèn)類型為 LoadBalancer
resources:
limits:
cpu: 1000m # 默認(rèn) 2000m
memory: 1024Mi # 默認(rèn) 1024Mi
requests:
cpu: 100m # 默認(rèn) 100m
memory: 128Mi # 默認(rèn) 128Mi
strategy:
rollingUpdate:
maxSurge: 100%
maxUnavailable: 25%
nodeSelector:
zone: "sz"
overlays:
- apiVersion: apps/v1 # 使用 hostNetwork 模式暴露 ingressGateways
kind: Deployment
name: istio-ingressgateway
patches:
- path: spec.template.spec.hostNetwork
value:
true
- path: spec.template.spec.dnsPolicy
value:
ClusterFirstWithHostNet
- apiVersion: v1 # 從安全的角度來考慮,不應(yīng)該暴露那些不必要的端口,對于 Ingress Gateway 來說,只需要暴露 HTTP、HTTPS 和 metrics 端口就夠了
kind: Service
name: istio-ingressgateway
patches:
- path: spec.ports
value:
- name: status-port
port: 15020
targetPort: 15020
- name: http2
port: 80
targetPort: 80
- name: https
port: 443
targetPort: 443
pilot:
enabled: true
k8s:
hpaSpec:
minReplicas: 2 # 默認(rèn)最小為1個pod
resources:
limits:
cpu: 1000m # 默認(rèn)不限制
memory: 1024Mi # 默認(rèn)不限制
requests:
cpu: 100m # 默認(rèn) 500m
memory: 300Mi # 默認(rèn) 2048Mi
strategy:
rollingUpdate:
maxSurge: 100%
maxUnavailable: 25%
nodeSelector:
zone: "sz"
overlays: # 調(diào)整PDB配置
- apiVersion: policy/v1beta1
kind: PodDisruptionBudget
name: istiod
patches:
- path: spec.selector.matchLabels
value:
app: istiod
istio: pilot
部署 Istio
$ istioctl manifest apply -f istio-1.5.1.yaml
設(shè)置 Grafana、istio-tracing、kiali、prometheus 通過 istio-ingressgateway 暴露
$ vim istio-addon-components-gateway.yaml
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: istio-addon-components-gateway
namespace: istio-system
spec:
selector:
istio: ingressgateway # use istio default controller
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- "grafana.example.com"
- "tracing.example.com"
- "kiali.example.com"
- "prometheus.example.com"
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: istio-grafana
namespace: istio-system
spec:
hosts:
- "grafana.example.com"
gateways:
- istio-addon-components-gateway
http:
- route:
- destination:
host: grafana
port:
number: 3000
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: istio-tracing
namespace: istio-system
spec:
hosts:
- "tracing.example.com"
gateways:
- istio-addon-components-gateway
http:
- route:
- destination:
host: tracing
port:
number: 80
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: istio-kiali
namespace: istio-system
spec:
hosts:
- "kiali.example.com"
gateways:
- istio-addon-components-gateway
http:
- route:
- destination:
host: kiali
port:
number: 20001
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: istio-prometheus
namespace: istio-system
spec:
hosts:
- "prometheus.example.com"
gateways:
- istio-addon-components-gateway
http:
- route:
- destination:
host: prometheus
port:
number: 9090
部署 Grafana、istio-tracing、kiali、prometheus 服務(wù) Gateway 和 VirtualService
$ kubectl apply -f istio-addon-components-gateway.yaml
部署完成后,查看各組件狀態(tài):
$ kubectl get svc,pod,hpa,pdb,Gateway,VirtualService -n istio-system

image
參考鏈接
- [1]https://istio.io/zh/docs/ops/deployment/requirements/
- https://istio.io/docs/setup/install/standalone-operator/
- https://www.danielstechblog.io/high-available-control-plane-with-istio-1-5-on-azure-kubernetes-service/
本文由 YP小站 發(fā)布!