# Istio Helm Chart 详解 - 全局变量

> 这是《Istio Helm Chart 详解》系列的第二篇。

## 前言

我们在使用现有 Chart 的时候，通常都不会修改 Chart 的本体，仅通过对[变量](https://docs.helm.sh/chart_template_guide/#variables)的控制来实现对部署过程的定制。Istio Helm Chart 提供了大量的变量来帮助用户进行定制。

第一篇中我们提到过，Istio Chart 分为父子两层，因此变量也具有[全局和本地](https://docs.helm.sh/chart_template_guide/#subcharts-and-global-values)两级，全局变量使用保留字 `global` 来进行定义，子 Chart 可以通过 `.Values.global` 的方式引用全局变量，而主 Chart 中也可以用 `chart.var` 的方式为子 Chart 指定变量值，本篇会首先讲解一下 `values.yaml` 中涉及到的全局变量，也就是 `global` 一节；各个 Chart 涉及到的专属变量会留在各个 Chart 的章节中。

## hub 和 tag

缺省值分别为 `docker.io/istio` 和 `1.0.2`。

> 这里看到版本的控制主要是在镜像层面的，Chart 自身的版本控制并不是很规矩，差评。

多数情况下，这一配置代表所有镜像的地址，具体名称一般由 `{{ .Values.global.hub }}/[component]/:{{ .Values.global.tag }}` 的形式拼接而成。proxy\_init、Mixer、Grafana 和 Pilot 中，一旦其 `image` 变量中包含了路径符 `/`，则会弃用 `global.hub`，直接采用 `image` 的定义。

### 影响范围

| 文件 | 对象 | 备注 |
| --- | --- | --- |
| `charts/certmanager/templates/deployment.yaml` | Deployment：`certmanager` |  |
| `charts/galley/templates/deployment.yaml` | Deployment：`istio-galley` |  |
| `charts/gateways/templates/deployment.yaml` | 所有 Gateway 的 Deployment | Container：`istio-proxy` |
| `charts/grafana/templates/create-custom-resources-job.yaml` | Job：`istio-grafana-post-install` |  |
| `charts/grafana/templates/deployment.yaml` | Deployment：`grafana` |  |
| `charts/ingress/templates/deployment.yaml` | Deployment：`istio-ingress` |  |
| `charts/kiali/templates/deployment.yaml` | Deployment：`kiali` |  |
| `charts/mixer/templates/deployment.yaml` | Deployment：`istio-policy`/`istio-telemetry` | Container：`istio-proxy`/`mixer` |
| `charts/mixer/templates/statsdtoprom.yaml` | Deployment：`istio-statsd-prom-bridge` |  |
| `charts/pilot/templates/deployment.yaml` | Deployment：`istio-pilot` |  |
| `charts/prometheus/templates/deployment.yaml` | Deployment：`prometheus` |  |
| `charts/security/templates/cleanup-secrets.yaml` | Job：`istio-cleanup-secrets` |  |
| `charts/security/templates/create-custom-resources-job.yaml` | Job：`istio-security-post-install` |  |
| `charts/security/templates/deployment.yaml` | Deployment：`istio-citadel` |  |
| `charts/servicegraph/templates/deployment.yaml` | Deployment：`servicegraph` |  |
| `charts/sidecarInjectorWebhook/templates/deployment.yaml` | Deployment：`istio-sidecar-injector` |  |
| `charts/tracing/templates/deployment.yaml` | Deployment：`istio-tracing` |  |
| `templates/sidecar-injector-configmap.yaml` | ConfigMap：`istio-sidecar-injector` | `istio-init`、`enable-core-dump`、`istio-proxy` |

## k8sIngressSelector

缺省值为 `ingress`。

这一变量比较 Buggy。原则上讲，他仅在 `ingress.enabled` 为 `true` 的时候生效。

### 影响范围

#### `charts/pilot/templates/gateway.yaml`

这个文件中定义了一个 Gateway - `istio-autogenerated-k8s-ingress`，其中的 `spec.selector` 是这样设计的：`istio: {{ .Values.global.k8sIngressSelector }}`，实际上该文件中并没有针对 `ingress.enabled` 开关做出是否生成网关的判断，该网关一定会创建，但是只有在 `Ingress` Chart 中才会创建符合该条件的 Deployment，因此在 `Ingress` Chart 没有创建的情况下，该网关的 `Selector` 就无法匹配成功，也就无法生效了。

#### `templates/configmap.yaml`

这里会引用 `ingress.enabled` 进行判断，如果判断成功，则在 `istio` ConfigMap 对象中写入 `ingressService: istio-{{ .Values.global.k8sIngressSelector }}`。

## k8sIngressHttps

缺省值为 `false`。

### 影响范围

#### `charts/pilot/templates/gateway.yaml`

如果启用该字段，会给 Gateway 定义中加入 443 端口及其 TLS 配置。

这段配置中对 `/etc/istio/ingress/certs/` 下面的证书文件有依赖，因此需要启用这一选项，首先要启用 `ingress.enabled`，从而能够成功创建 `ingress` Chart 的 Deployment；另外还需要创建一个命名为 `ingress-certs` 的 tls secret，给 `istio-ingress` Deployment 进行加载。这些条件如果没有满足，LDS 会拒绝服务，从而无法提供 Ingress 功能。

## proxy.image

缺省值为 `proxyv2`。

### 影响范围

#### `istio/templates/sidecar-injector-configmap.yaml`

其中的 ConfigMap `istio-sidecar-injector` 中的注入部分会使用该值作为 `istio-proxy` 的镜像名。

```bash
image: {{ "[[ if (isset .ObjectMeta.Annotations \"sidecar.istio.io/proxyImage\") -]]" }}
{{ "\"[[ index .ObjectMeta.Annotations \"sidecar.istio.io/proxyImage\" ]]\"" }}
{{ "[[ else -]]" }}
{{ .Values.global.hub }}/{{ .Values.global.proxy.image }}:{{ .Values.global.tag }}
{{ "[[ end -]]" }}
```

这段代码表明，首先会判断 Pod 的 `sidecar.istio.io/proxyImage` 注解，如果注解不存在，才会使用这一变量，拼接方式为：`{{ .Values.global.hub }}/{{ .Values.global.proxy.image }}:{{ .Values.global.tag }}`。

## proxy.resources

这里为 Sidecar 定义了资源分配的方案。根据官方的[伸缩性和规模调整指南](https://preliminary.istio.io/zh/docs/concepts/performance-and-scalability/#scalability-and-sizing-guide)：

> 开启访问日志（默认开启）时，为 Sidecar 每分配 1 个 vCPU 能够负担 1000 qps 的访问峰值，没有开启则 0.5 vCPU 即可负担同样峰值，节点上的 fluentd 由于需要捕获和上传日志，是主要的性能消耗者。

### 影响范围

| 文件 | 对象 | 备注 |
| --- | --- | --- |
| `charts/mixer/templates/deployment.yaml` | Deployment：`istio-policy`/`istio-telemetry` Container：`istio-proxy`/`mixer` |  |
| `charts/pilot/templates/deployment.yaml` | Deployment：`istio-pilot` |  |
| `templates/sidecar-injector-configmap.yaml` | ConfigMap：`istio-sidecar-injector` | 会注入到所有 Pod |

## proxy.concurrency

缺省值为 `0`。

Proxy worker 线程数量，如果设置为 0，则根据 CPU 线程/核的数量进行分配。

### 影响范围

| 文件 | 对象 |
| --- | --- |
| `istio/templates/configmap.yaml` | ConfigMap：`istio` |

## proxy.accessLogFile

缺省值为 `/dev/stdout`。

Sidecar 的访问日志位置，如果设置为空字符串，则关闭访问日志功能。

### 影响范围

| 文件 | 对象 |
| --- | --- |
| `templates/configmap.yaml` | ConfigMap：`istio` |

## proxy.privileged

缺省值为 `false`。

`istio-init`、`istio-proxy` 的特权模式开关。

### 影响范围

| 文件 | 对象 |
| --- | --- |
| `templates/sidecar-injector-configmap.yaml` | ConfigMap `istio-sidecar-injector` |

## proxy.enableCoreDump

缺省值为 `false`。

如果打开，新注入的 Sidecar 会启动 CoreDump 功能，加入初始化容器 `enable-core-dump`。

### 影响范围

| 文件 | 对象 |
| --- | --- |
| `templates/sidecar-injector-configmap.yaml` | ConfigMap `istio-sidecar-injector` |

## proxy.includeIPRanges

缺省值为 `"*"`。

[劫持白名单](https://istio.io/docs/tasks/traffic-management/egress.html#calling-external-services-directly)，仅劫持该 CIDR 范围内的 IP。

### 影响范围

| 文件 | 对象 |
| --- | --- |
| `templates/sidecar-injector-configmap.yaml` | ConfigMap `istio-sidecar-injector` |

修改 `istio-init` 的 `-i` 参数，等价的 Pod Annotation 为 `traffic.sidecar.istio.io/includeOutboundIPRanges`。

## proxy.excludeIPRanges

缺省值为 `""`。

CIDR 范围之外的所有 IP 都会被劫持。

### 影响范围

| 文件 | 对象 |
| --- | --- |
| `templates/sidecar-injector-configmap.yaml` | ConfigMap `istio-sidecar-injector` |

修改 `istio-init` 的 `-x` 参数，等价的 Pod Annotation 为 `traffic.sidecar.istio.io/excludeOutboundIPRanges`。

## proxy.includeInboundPorts

缺省值为 `"*"`。

进入端口的劫持白名单，所有从范围内端口进入 Pod 的流量会被劫持。

### 影响范围

| 文件 | 对象 |
| --- | --- |
| `templates/sidecar-injector-configmap.yaml` | ConfigMap `istio-sidecar-injector` |

修改 [`istio-init`](https://github.com/istio/istio/blob/master/tools/deb/istio-iptables.sh) 的 `-b` 参数，等价的 Pod Annotation 为 `traffic.sidecar.istio.io/includeInboundPorts`。

## proxy.excludeInboundPorts

缺省值为 `""`。

进入端口的劫持黑名单，所有从范围外端口进入 Pod 的流量会被劫持。

### 影响范围

| 文件 | 对象 |
| --- | --- |
| `templates/sidecar-injector-configmap.yaml` | ConfigMap `istio-sidecar-injector` |

修改 [`istio-init`](https://github.com/istio/istio/blob/master/tools/deb/istio-iptables.sh) 的 `-d` 参数，等价的 Pod Annotation 为 `traffic.sidecar.istio.io/excludeOutboundIPRanges`。

## proxy.autoInject

缺省值为 `enabled`。用于指定 Sidecar 注入器的策略。

### 影响范围

| 文件 | 对象 |
| --- | --- |
| `templates/sidecar-injector-configmap.yaml` | ConfigMap `istio-sidecar-injector` |

## proxy.envoyStatsd

缺省值为：

```yaml
enabled: true
host: istio-statsd-prom-bridge
port: 9125
```

设置 Envoy 的 statsd 目标，也就是 Envoy 的 `"--statsdUdpAddress` 参数。某些情况下（例如没有安装 Mixer）可以关闭。

### 影响范围

| 文件 | 对象 | 备注 |
| --- | --- | --- |
| `charts/ingress/templates/deployment.yaml` | Deployment：`istio-ingress` |  |
| `templates/configmap.yaml` | ConfigMap：`istio` |  |
| `templates/sidecar-injector-configmap.yaml` | ConfigMap：`istio-sidecar-injector` | `istio-init`、`enable-core-dump`、`istio-proxy` 三个容器的镜像 |

## proxy\_init.image

缺省值为 `proxy_init`，指定初始化镜像。

> 前面提到过，如果这里使用一个带有路径符号 `/` 的镜像名称，会忽略前面的 `global.hub/tag` 的设置。

### 影响范围

| 文件 | 对象 |
| --- | --- |
| `templates/sidecar-injector-configmap.yaml` | ConfigMap `istio-sidecar-injector` |

## imagePullPolicy

缺省值为 `IfNotPresent`。镜像的拉取策略。

## 影响范围

| 文件 | 对象 | 说明 |
| --- | --- | --- |
| `charts/certmanager/templates/deployment.yaml` | Deployment：`certmanager` |  |
| `charts/galley/templates/deployment.yaml` | Deployment：`istio-galley` |  |
| `charts/gateways/templates/deployment.yaml` | 所有 Gateway 的 Deployment | Container：`istio-proxy` |
| `charts/grafana/templates/deployment.yaml` | Deployment：`grafana` |  |
| `charts/ingress/templates/deployment.yaml` | Deployment：`istio-ingress` |  |
| `charts/mixer/templates/deployment.yaml` | Deployment：`istio-policy/istio-telemetry` | Container：`istio-proxy`/`mixer` |
| `charts/mixer/templates/statsdtoprom.yaml` | Deployment：`istio-statsd-prom-bridge` |  |
| `charts/pilot/templates/deployment.yaml` | Deployment：`istio-pilot` |  |
| `charts/prometheus/templates/deployment.yaml` | Deployment：`prometheus` |  |
| `charts/security/templates/deployment.yaml` | Deployment：`istio-citadel` |  |
| `charts/servicegraph/templates/deployment.yaml` | Deployment：`servicegraph` |  |
| `charts/sidecarInjectorWebhook/templates/deployment.yaml` | Deployment：`istio-sidecar-injector` |  |
| `charts/tracing/templates/deployment.yaml` | Deployment：`istio-tracing` |  |
| `templates/sidecar-injector-configmap.yaml` | ConfigMap：`istio-sidecar-injector` | Container：`istio-init`，`istio-proxy`，`enable-core-dump` 未受影响 |

## controlPlaneSecurityEnabled

缺省值为 `false`。控制面是否启用 mTLS。

### 影响范围

| 文件 | 对象 | 说明 |
| --- | --- | --- |
| `charts/ingress/templates/deployment.yaml` | Deployment：`istio-ingress` | 控制 Ingress 参数 `--controlPlaneAuthPolicy` 的取值，`MUTUAL_TLS` 或者 `NONE` |
| `charts/mixer/templates/config.yaml` | DestinationRule: `istio-policy` 和 DestinationRule: `istio-telemetry` | 为端口 `15004` 启用 `ISTIO_MUTUAL` |
| `charts/mixer/templates/deployment.yaml` | Deployment：`istio-policy`/`istio-telemetry` | 控制 Sidecar `istio-proxy` 参数 `--controlPlaneAuthPolicy` 的值，可选 `MUTUAL_TLS` 或者 `NONE` |
| `charts/pilot/templates/deployment.yaml` | Deployment：`istio-pilot` | 控制 Sidecar `istio-proxy` 参数 `--controlPlaneAuthPolicy` 的值，可选 `MUTUAL_TLS` 或者 `NONE` |
| `templates/configmap.yaml` | ConfigMap：`istio` | 控制 Sidecar `istio-proxy` 参数 `--controlPlaneAuthPolicy` 的值，可选 `MUTUAL_TLS` 或者 `NONE` |

## disablePolicyChecks

缺省值 `false`。

禁用 Mixer 策略检查。

### 影响范围

| 文件 | 对象 |
| --- | --- |
| `templates/configmap.yaml` | ConfigMap `istio` |

## enableTracing

缺省值 `true`。

设置请求跟踪。

| 文件 | 对象 |
| --- | --- |
| `templates/configmap.yaml` | ConfigMap `istio` |

### 影响范围

| 文件 | 对象 |
| --- | --- |
| `templates/configmap.yaml` | ConfigMap `istio` |

## mtls.enabled

缺省值 `false`。服务间 mTLS 的缺省设置，可以使用目标规则或者服务注解进行覆盖。这一开关会控制生成一系列的 Job、ConfigMap 以及 Kubernetes RBAC 的相关内容，详情将会在 Security Chart 中讲解。

### 影响范围

| 文件 | 对象 | 说明 |
| --- | --- | --- |
| `charts/security/templates/configmap.yaml` | ConfigMap：`istio-security-custom-resources` |  |
| `charts/security/templates/create-custom-resources-job.yaml` | ServiceAccount: `istio-security-post-install-account` ClusterRole: `istio-security-post-install-istio-system` ClusterRoleBinding: `istio-security-post-install-role-binding-istio-system` Job：`istio-security-post-install` | 这几个对象都需要启动这一开关才会创建 |

## imagePullSecrets

缺省为空。

用于为 ServiceAccount 分配镜像拉取过程所需的凭证。

### 影响范围

| 文件 | 对象 |
| --- | --- |
| `charts/certmanager/templates/serviceaccount.yaml` | ServiceAccount: `certmanager` |
| `charts/galley/templates/serviceaccount.yaml` | ServiceAccount: `istio-galley-service-account` |
| `charts/gateways/templates/serviceaccount.yaml` | 所有 Gateways 自动生成的 ServiceAccount |
| `charts/ingress/templates/serviceaccount.yaml` | ServiceAccount: `istio-ingress-service-account` |
| `charts/kiali/templates/serviceaccount.yaml` | ServiceAccount: `kiali-service-account` |
| `charts/mixer/templates/serviceaccount.yaml` | ServiceAccount: `istio-mixer-service-account` |
| `charts/pilot/templates/serviceaccount.yaml` | ServiceAccount: `istio-pilot-service-account` |
| `charts/prometheus/templates/serviceaccount.yaml` | ServiceAccount: `prometheus` |
| `charts/security/templates/serviceaccount.yaml` | ServiceAccount: `istio-citadel-service-account` |
| `charts/sidecarInjectorWebhook/templates/serviceaccount.yaml` | ServiceAccount: `istio-sidecar-injector-service-account` |

## arch

缺省值：

```yaml
amd64: 2
s390x: 2
ppc64le: 2
```

用于 Kubernetes 的节点亲和性调度过程。

这里列出了几种支持的服务器架构，并给出了优先级。详情请参看本文系列第一篇。

## oneNamespace

缺省值 `false`。

如果设置为 `true`，会对控制面管理的应用命名空间进行限制。如果没有设置，则监控所有命名空间。

### 影响范围

| 文件 | 对象 |
| --- | --- |
| `charts/pilot/templates/deployment.yaml` | Deployment：`istio-pilot` |

设置 [Pilot discovery 的 `-a` 参数](https://istio.io/docs/reference/commands/pilot-discovery/#pilot-discovery-discovery)。这一参数取值为监控的命名空间名称，目前会选用 Istio 所在的命名空间。

## configValidation

缺省值 `ture`。用于配置是否开启服务端的配置验证。该选项开启之后，会生成一个 ValidatingWebhookConfiguration 对象，并被包含到 Galley 的配置之中，从而启用校验功能。

### 影响范围

| 文件 | 说明 |
| --- | --- |
| `charts/galley/templates/validatingwehookconfiguration.yaml.tpl` | ValidatingWebhookConfiguration: `istio-galley` |

## meshExpansion

缺省值为 `false`。如果启用，Pilot 和 Citadel 会在 Ingress Gateway 上公开服务。

### 影响范围

| 文件 | 对象 | 说明 |
| --- | --- | --- |
| `charts/pilot/templates/gateway.yaml` | Gateway：`meshexpansion-gateway` | 用于公开服务的 Gateway |
| `charts/pilot/templates/meshexpansion.yaml` | VirtualService：`meshexpansion-pilot` | Pilot 的 VirtualService |
| `charts/security/templates/meshexpansion.yaml` | VirtualService：`meshexpansion-citadel` | Citadel 的 的 VirtualService |

## meshExpansionILB

缺省值为 `false`。Pilot 和 Citadel 的 mTLS 和明文端口会在内部网关进行公开。

### 影响范围

| 文件 | 对象 | 说明 |
| --- | --- | --- |
| `charts/pilot/templates/gateway.yaml` | Gateway：`meshexpansion-ilb-gateway` | 用于公开服务的 Gateway |
| `charts/pilot/templates/meshexpansion.yaml` | VirtualService：`ilb-meshexpansion-pilot` | Pilot 的 VirtualService |
| `charts/security/templates/meshexpansion.yaml` | VirtualService：`meshexpansion-ilb-citadel` | Citadel 的 的 VirtualService |

## defaultResources

缺省值：

```yaml
requests:
  cpu: 10m
```

为 Istio 组件提供一个最小的资源定义，以便 HPA 工作方便，每个组件可以定义自己的资源定义进行覆盖。

### 影响范围

| 文件 | 对象 | 说明 |
| --- | --- | --- |
| `charts/galley/templates/deployment.yaml` | Deployment：`istio-galley` |  |
| `charts/gateways/templates/deployment.yaml` | 所有网关创建的 Deployment |  |
| `charts/grafana/templates/deployment.yaml` | Deployment：`grafana` |  |
| `charts/ingress/templates/deployment.yaml` | Deployment：`istio-ingress` |  |
| `charts/kiali/templates/deployment.yaml` | Deployment：`kiali` |  |
| `charts/mixer/templates/deployment.yaml` | Deployment：`istio-policy`/`istio-telemetry` | Container：`istio-proxy`/`mixer` |
| `charts/mixer/templates/statsdtoprom.yaml` | Deployment：`istio-statsd-prom-bridge` |  |
| `charts/pilot/templates/deployment.yaml` | Deployment：`istio-pilot` | Container：`istio-proxy`/`discovery` |
| `charts/prometheus/templates/deployment.yaml` | Deployment：`prometheus` |  |
| `charts/security/templates/deployment.yaml` | Deployment：`istio-citadel` |  |
| `charts/servicegraph/templates/deployment.yaml` | Deployment：`servicegraph` |  |
| `charts/sidecarInjectorWebhook/templates/deployment.yaml` | Deploymet: `istio-sidecar-injector` |  |
| `charts/tracing/templates/deployment.yaml` | Deployment：`istio-tracing` |  |

## hyperkube

缺省值：

```yaml
hub: quay.io/coreos
tag: v1.7.6_coreos.0
```

用于创建 CRD 的容器镜像。

### 影响范围

| 文件 | 对象 |
| --- | --- |
| `charts/grafana/templates/create-custom-resources-job.yaml` | Job：`istio-grafana-post-install` |
| `charts/security/templates/cleanup-secrets.yaml` | Job：`istio-cleanup-secrets` |
| `charts/security/templates/create-custom-resources-job.yaml` | Job：`istio-security-post-install` |

## priorityClassName

Kubernetes 1.11.0 以上有两个 [`PriorityClass`](https://kubernetes.io/docs/concepts/configuration/pod-priority-preemption/#priorityclass)，用这种方式创建 Istio 组件 Pod，可以防止因较低的优先级被杀掉。

### 影响范围

| 文件 | 对象 |
| --- | --- |
| `charts/certmanager/templates/deployment.yaml` | Deployment：`certmanager` |
| `charts/galley/templates/deployment.yaml` | Deployment：`istio-galley` |
| `charts/gateways/templates/deployment.yaml` | 所有网管创建的 Deployment |
| `charts/grafana/templates/deployment.yaml` | Deployment：`grafana` |
| `charts/ingress/templates/deployment.yaml` | Deployment：`istio-ingress` |
| `charts/kiali/templates/deployment.yaml` | Deployment：`kiali` |
| `charts/mixer/templates/deployment.yaml` | Deployment：`istio-policy/istio-telemetry` |
| `charts/pilot/templates/deployment.yaml` | Deployment：`istio-pilot` |
| `charts/prometheus/templates/deployment.yaml` | Deployment：`prometheus` |
| `charts/security/templates/deployment.yaml` | Deployment：`istio-citadel` |
| `charts/servicegraph/templates/deployment.yaml` | Deployment：`servicegraph` |
| `charts/sidecarInjectorWebhook/templates/deployment.yaml` | Deployment：`istio-sidecar-injector` |
| `charts/tracing/templates/deployment.yaml` | Deployment：`istio-tracing` |

## crds

缺省值 `true`。

如果使用的是 Helm 2.10 以上的 `helm install`，或者是 `helm template` 方式的安装，应该设置为 `true`；如果 Helm 版本小于 2.9，必须设置为 `false`，并手工执行 `kubectl apply -f install/kubernetes/helm/istio/templates/crds.yaml` 来首先创建 CRD。

### 影响范围

| 文件 | 说明 |
| --- | --- |
| `templates/crds.yaml` | 随这一开关确定是否创建所有 CRD |

## 小结

本节中很多涉及到下层 Chart 的内容并未深入，会在子 Chart 的相关章节中尝试进一步说明。
