ARTICLE DETAIL

资讯详情

深耕郑州网站建设与运营推广的一线实战洞察。

Istio Helm Profiles 机制详解:内置配置集、三级合并原理与 copy-templates 打包流程

Istio Helm Profiles 机制详解:内置配置集、三级合并原理与 copy-templates 打包流程 Istio Helm Profiles 机制详解内置配置集、三级合并原理与 copy-templates 打包流程【免费下载链接】istioConnect, secure, control, and observe services.项目地址: https://gitcode.com/GitHub_Trending/is/istioIstio 的 Helm Profile 是一组可复用的 values 配置集让你用一行--set profiledemo或--set platformgke就能切换整套安装配置。本文以 manifests/helm-profiles/README.md 为核心结合 manifests/zzz_profile.yaml 合并模板与 Makefile.core.mk 的copy-templates目标讲清 profile 的完整生命周期它如何被选中、按什么优先级合并、如何随 chart 分发以及修改后应如何重新生成。什么是 Helm Profilemanifests/helm-profiles/目录提供了一组用于 Helm 安装的 profiles配置档案。根据 README.md 的说明围绕 profile 有两类使用方式显式传参用户可以像传任意 values 一样直接通过--values/-f把某个 profile 文件传给helm install随 chart 内置分发Istio 提供了一项机制把manifests/helm-profiles/下的全部文件打包进各 chart 的files/目录这样即使从远程 chart远程仓库 URL安装用户也能直接--set profilexxx选用而无需本地存在这些 YAML 文件。README 指出该机制对应copy-templatesMakefile 目标和 manifests/zzz_profile.yaml 模板。当前仓库中内置的 profile 一览文件用途stable.yaml启用 admission control限制只使用稳定的资源与字段demo.yaml面向非生产环境的体验配置降低资源占用、默认开启若干演示功能、ingress 开放更多端口ambient.yaml启用 ambient 模式remote.yaml支持 remote control plane远程控制面安装preview.yaml探索实验性新功能的尝鲜配置compatibility-version-1.25.yaml 至 compatibility-version-1.30.yaml按旧版本行为回滚 1.251.30 各版本的破坏性行为变更platform-gke.yaml、platform-k3d.yaml、platform-k3s.yaml、platform-microk8s.yaml、platform-minikube.yaml、platform-openshift.yaml针对特定 Kubernetes 发行版/平台的适配配置warning-edit.txt复制进 chart 时自动前置的勿直接编辑警告头与 IstioOperator profile 的关键区别README 中有一个必须牢记的警告与IstioOperatorprofiles 不同这些 Helm profile 不能启用或禁用某些组件components。因此即使用户选择了某个 profile仍需自行保证安装了与该 profile 配套的正确 chart。例如remote.yaml 的首行注释明确要求 Thebaseandistio-discoverycharts must be deployed with this profileambient.yaml 的首行注释要求 The Istiod, CNI, and ztunnel charts must be deployed。README 指出这类约束已记录在每个 profile 文件的注释中选 profile 时应先阅读其头部说明。内置 Profile 逐项解读以下 YAML 内容直接取自仓库均可作为helm install -f的 values 文件或理解为--set profilexxx时的实际生效值。stable收紧到仅稳定字段stable.yaml 全文如下# The stable profile deploys admission control to ensure that only stable resources and fields are used # THIS IS CURRENTLY EXPERIMENTAL AND SUBJECT TO CHANGE experimental: stableValidationPolicy: true它通过experimental.stableValidationPolicy: true部署一个 admission 校验策略拒绝使用非稳定的 Istio 资源类型或字段。注意文件头明确标注该能力目前为实验性质可能随时变化。demo面向演示与文档教程的低占用配置demo.yaml 的文件头注释说明其目标降低资源占用、默认开启一些演示功能尤其是 istio.io 文档任务用到的功能、ingress 上开放更多端口。核心内容包括三块访问日志与遥测扩展。将meshConfig.accessLogFile指向/dev/stdout并声明四个extensionProvidersmeshConfig: accessLogFile: /dev/stdout extensionProviders: - name: otel envoyOtelAls: service: opentelemetry-collector.observability.svc.cluster.local port: 4317 - name: skywalking skywalking: service: tracing.istio-system.svc.cluster.local port: 11800 - name: otel-tracing opentelemetry: port: 4317 service: opentelemetry-collector.observability.svc.cluster.local - name: jaeger opentelemetry: port: 4317 service: jaeger-collector.istio-system.svc.cluster.local全面调低资源请求。CNI、ztunnel、sidecar proxy、waypoint、pilot、两个 gateway 的resources.requests均压到cpu: 10m / memory: 40Mi左右pilot 为100Mi并关闭 pilot 与 ingress/egress gateway 的autoscaleEnabledpilot.traceSampling设为 100cni: resources: requests: cpu: 10m memory: 40Mi pilot: autoscaleEnabled: false traceSampling: 100 resources: requests: cpu: 10m memory: 100Miingress 开放更多端口。gateways.istio-ingressgateway.ports显式列出15021/status-port、80(http2)、443(https)、31400(tcp)、15443(tlsSNI 路由端口)五个端口。文件内注释特别提醒helm 对列表是整体替换而非合并用户若要自定义端口必须在 override 中包含 profile 里已有的全部端口同时注释引用了 AWS ELB 会对该列表第一个端口做健康检查的背景对应 issue #12503因此把15021的 status-port 放在首位。ambient启用 ambient 模式ambient.yaml 全文# The ambient profile enables ambient mode. The Istiod, CNI, and ztunnel charts must be deployed meshConfig: defaultConfig: proxyMetadata: ISTIO_META_ENABLE_HBONE: true serviceScopeConfigs: - servicesSelector: matchExpressions: - key: istio.io/global operator: In values: [true] scope: GLOBAL global: variant: distroless pilot: env: PILOT_ENABLE_AMBIENT: true cni: ambient: enabled: true逐条看其作用ISTIO_META_ENABLE_HBONE: true通过 proxy 元数据开启 HBONEHTTP-based Overlay Network Encryption即 ambient 模式的隧道基础serviceScopeConfigs将带istio.io/globaltrue标签的服务设为 GLOBAL scopeglobal.variant: distroless选用 distroless 代理变体PILOT_ENABLE_AMBIENT让 istiod 处理 ambient 相关资源cni.ambient.enabled: true让 CNI 组件接管 ztunnel 的注入与网络配置。再次注意该 profile 只改配置不会替你部署 istiod/CNI/ztunnel 这些 chart这正是上一节警告的实例。remote远程控制面remote.yaml 全文# The remote profile enables installing istio with a remote control plane. The base and istio-discovery charts must be deployed with this profile. istiodRemote: enabled: true configMap: false telemetry: enabled: false global: # TODO BML maybe a different profile for a configcluster/revisit this omitSidecarInjectorConfigMap: true它把本地控制面关掉configMap: false、telemetry.enabled: false通过istiodRemote.enabled: true指向远端 istiod并用global.omitSidecarInjectorConfigMap省略本地 sidecar 注入配置。注释中的 TODO 表明为 configcluster 单独出 profile仍是作者留待重新设计的事项。preview实验特性入口preview.yaml 声明包含实验特性不保证稳定性、安全性与性能使用风险自负当前内容为meshConfig: defaultConfig: proxyMetadata: # Enable Istio agent to handle DNS requests for known hosts # Unknown hosts will automatically be resolved using upstream dns servers in resolv.conf ISTIO_META_DNS_CAPTURE: true即默认开启 istio-agent 对已知主机的 DNS 处理未知主机自动回落到resolv.conf上游 DNS。这是一个典型的新特性先在 preview 落地、成熟后再进默认值的演进通道。compatibility-version-*行为版本回滚compatibility-version-1.30.yaml 展示了这类 profile 的形态——通过 pilot 环境变量把新版本的行为拉回旧版本pilot: env: # 1.31 behavioral changes PILOT_ENABLE_STRICT_GATEWAY_MERGING: false PILOT_SPAWN_UPSTREAM_SPAN_FOR_GATEWAY: false PILOT_AUTO_SEND_UNHEALTHY_ENDPOINTS: false从 1.25 到 1.30 各文件结构相同每升一个版本就把该版本引入的行为变更环境变量置为旧值从而让升级后的控制面保持旧版本行为。它与profile参数不是二选一的关系——在合并模板中compatibilityVersion是独立于profile的第二层叠加见下一节即选一个功能 profile 锁定一个行为版本可以共存。platform-*平台适配platform-openshift.yaml开启global.nativeNftables: trueCNI 使用 multus providercniBinDir: /var/lib/cni/bin、cniConfDir: /etc/cni/multus/net.d、chained: false、provider: multuspilot 侧cni.provider同步seLinuxOptions.type: spc_t注释说明 OpenShift 要求特权 pod 运行在 kube-system因此trustedZtunnelNamespace: kube-system。platform-gke.yamlcni.cniBinDir: 被有意留空注释解释这是为了让 GKE 上基于模板的自动检测正常工作同时开启cni.resourceQuotas与全局resourceQuotasGKE 要求资源配额相关设置。platform-k3s.yaml仅两行把 CNI 目录指到 k3s 的位置——cniConfDir: /var/lib/rancher/k3s/agent/etc/cni/net.d、cniBinDir: /bin。合并原理zzz_profile.yaml 的三级优先级用户执行helm install --set profilestable时真正生效的合并逻辑在各 chart 的templates/zzz_profile.yaml由 manifests/zzz_profile.yaml 生成。该模板头注释把值来源归纳为三个集合按后者胜出排序chart 内置的values.yaml默认值用户选定的 profile用户的输入-f或--set。难点在于 Helm 把 (1) 和 (3) 合并后作为同一个.Values交给模板profile (2) 无法直接插入中间。模板给出的绕法是把所有内置默认值放在一个专用键_internal_defaults_do_not_set下从.Values中剥离依次执行mustMergeOverwritedefaults → 叠加 profile → 再叠加用户 Values模板关键片段摘自 manifests/zzz_profile.yaml{{- $defaults : $.Values._internal_defaults_do_not_set }} {{- $_ : unset $.Values _internal_defaults_do_not_set }} {{- $profile : dict }} {{- with (coalesce ($.Values).profile ($.Values.global).profile) }} {{- with $.Files.Get (printf files/profile-%s.yaml .)}} {{- $profile (. | fromYaml) }} {{- else }} {{- fail (cat unknown profile .) }} {{- end }} {{- end }}从中可以看出三个机制细节profile 名即文件名--set profilestable会去读files/profile-stable.yaml找不到直接fail unknown profile——这是错拼 profile 名时报错的来源profile与global.profile等价coalesce先取顶层profile再回退到global.profile兼容旧写法compatibilityVersion与platform是两条独立的叠加链分别读files/profile-compatibility-version-ver.yaml与files/profile-platform-platform.yaml均以mustMergeOverwrite叠加到$profile上且各自的未知取值都会fail。最终顺序可归纳为内置默认值 功能 profile compatibilityVersion platform 用户-f/--set。模板还有一段防御逻辑如果用户显式设置了.Values.defaults.*会直接fail并提示把--set defaults.hubfoo改成--set hubfoo防止业务键误用保留命名空间。对 ztunnel 与 gateway 两个 chart生成时FLATTEN_GLOBALS_REPLACEMENT被替换为true会把$profile.global扁平化合并进全局值以适配这两个 chart 不按 chart 级划分global的结构。打包流程make copy-templatesREADME.md 要求对该目录的任何修改之后都应执行make copy-templates。该目标定义在 Makefile.core.mk其逻辑为定义 chart 清单CHARTS gateway default ztunnel base gateways/istio-ingress gateways/istio-egress istio-control/istio-discovery istio-cni即 profile 会被分发到全部七个 chart同步 egress gateway 模板把 istio-ingress 的 templates 复制到 istio-egress 并用sed做 ingress→egress 的命名替换这部分与 profile 无关但同属该目标复制 profile清空各 chart 的files/profile-*.yaml后遍历manifests/helm-profiles/*.yaml每个文件头部插入 warning-edit.txt 的内容WARNING: DO NOT EDIT, THIS FILE IS A COPY……run make gen再写入manifests/charts/$chart/files/profile-basename生成合并模板把 manifests/zzz_profile.yaml 按 chart 复制为templates/zzz_profile.yaml其中FLATTEN_GLOBALS_REPLACEMENT对 ztunnel/gateway chart 替换为true其余替换为false。copy-templates同时是gen目标的一部分Makefile.core.mk中gen:依赖copy-templates因此完整的生成链路是make gen内部还会执行rm manifests/charts/.../profile-*.yaml再重建保证删除旧 profile 后不残留。这也解释了仓库中为什么每个 chart 的files/目录里都有一整套profile-*.yaml副本它们是构建期产物只应修改manifests/helm-profiles/下的原件。使用方法基于上述机制三类典型用法如下均以从仓库/远程 chart 安装为前提# 1. 选用功能 profile读 files/profile-demo.yaml 并叠加到默认值之上 istioctl install --set profiledemo # 2. 叠加平台适配与行为版本可与 profile 共存顺序profile compatibilityVersion platform 显式 --set istioctl install --set profiledemo --set platformgke --set compatibilityVersion1.30 # 3. 不经过内置分发直接把 profile 文件当 values 传给 helm helm install istio base -f manifests/helm-profiles/stable.yaml注意事项与适用前提profile 只能覆盖已有 values 键的取值不能增删组件remote 需baseistio-discoveryambient 需 istiod CNI ztunnel见各文件头部注释stableprofile 标注为实验特性previewprofile 明确不承诺稳定性列表型值如 demo 的 ingressports会被整体替换自定义时须携带 profile 中的完整列表profile 内容随当前仓库版本演进跨大版本升级时应重新核对所用 profile 的注释与默认行为compatibility-version-*正是为此提供的回退手段且当前仓库只覆盖到 1.30。小结Istio 的 Helm profile 机制由三部分构成manifests/helm-profiles/下的可编辑原件含 stable/demo/ambient/remote/preview、compatibility-version-1.25~1.30 与六个 platform-* 配置、copy-templates目标驱动的 chart 内分发每个 chart 的files/profile-*.yaml副本加warning-edit.txt警告头、以及zzz_profile.yaml生成的三级合并模板内置默认值 profile compatibilityVersion platform 用户输入。理解了这条链路你就能安全地选用现成 profile、按平台/版本精确叠加配置也知道修改 profile 后必须重新运行make copy-templates或make gen才能让 chart 内的副本保持同步。【免费下载链接】istioConnect, secure, control, and observe services.项目地址: https://gitcode.com/GitHub_Trending/is/istio创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表