尧图网站设计 尧图网站设计YAOTU DESIGN
ARTICLE DETAIL

资讯详情

深耕网站设计与一线实操的经验洞察。

Cilium clustermesh-apiserver 依赖注入诊断:`clustermesh hive dot-graph` 命令完全指南

Cilium clustermesh-apiserver 依赖注入诊断:`clustermesh hive dot-graph` 命令完全指南 Cilium clustermesh-apiserver 依赖注入诊断clustermesh hive dot-graph命令完全指南【免费下载链接】ciliumeBPF-based Networking, Security, and Observability项目地址: https://gitcode.com/GitHub_Trending/ci/ciliumclustermesh hive dot-graph是 Cilium ClusterMesh API Serverclustermesh-apiserver提供的 Hive 诊断子命令用于以 Graphviz DOT 格式输出进程内所有组件cell之间的依赖关系图。本文以该命令的官方 cmdref 文档为主体结合仓库中clustermesh-apiserver与pkg/hive的源码实现完整讲解命令用法、全部可继承参数、依赖图输出机制及其在排查 ClusterMesh 启动问题时的实战价值。读完本文你将能够熟练使用该命令生成并解读依赖图理解 clustermesh-apiserver 的模块化架构与参数体系。命令概述什么是clustermesh hive dot-graphclustermesh hive dot-graph是clustermesh-apiserver二进制中clustermesh根命令源码入口下的 hive 子命令体系之一其功能是Output the dependencies graph in graphviz dot format以 Graphviz DOT 格式输出依赖图。该命令源于 Cilium 使用的 Hive 依赖注入框架github.com/cilium/hiveCilium 在 pkg/hive/hive.go 中对其做了封装。整个 clustermesh-apiserver 进程由若干被称为 cell 的模块构成cell 之间通过构造函数cell.Provide、依赖注入与生命周期钩子cell.Invoke、cell.Hook相互关联。dot-graph子命令可以在不真正启动进程的前提下把这张完整的依赖关系网以机器可读的 DOT 文本形式打印出来方便开发者将输出交给 Graphviz 工具渲染成可视化依赖图用于分析模块结构、定位循环依赖或验证新增 cell 的连接关系。其基础语法为clustermesh-apiserver clustermesh hive dot-graph [flags]本命令专属选项dot-graph子命令自身只有一个选项其余全部继承自父命令见下文-h, --help help for dot-graph这一点也说明了dot-graph是一个轻量的纯查询型命令它不做任何业务操作只是把 Hive 已经组装好的 cell 图导出为文本。命令在命令树中的位置dot-graph是clustermesh hive的子命令。在 clustermesh-apiserver/cmd/root.go 中可以看到二进制根的组装逻辑clustermesh.NewCmd(hive.New(common.Cell, clustermesh.Cell)),其中clustermesh.NewCmdroot.go会执行h.RegisterFlags(rootCmd.Flags())将 Hive 的全部配置项注册为命令行 flag随后通过rootCmd.AddCommand(h.Command())挂载 Hive 自带的管理子命令——其中就包含hive、hive dot-graph、hive dot-graph的兄弟命令如hive的 inspect 等。因此整个命令路径为clustermesh-apiserver clustermesh— Run ClusterMesh真正启动进程clustermesh-apiserver clustermesh hive— Inspect the hiveclustermesh-apiserver clustermesh hive dot-graph— Output the dependencies graph in graphviz dot format本文主题继承自父命令的完整参数表dot-graph虽然只输出依赖图但会完整继承clustermesh hive及clustermesh根命令的全部配置项。这些参数同时也是 clustermesh-apiserver 运行时Run ClusterMesh的真实配置因此在阅读依赖图输出、排查启动问题时理解这些参数与 Hive 模块的对应关系非常关键。以下参数表完整继承自官方 cmdref 文档--cluster-id uint32 Unique identifier of the cluster --cluster-name string Name of the cluster. It must consist of at most 32 lower case alphanumeric characters and -, start and end with an alphanumeric character. (default default) --cluster-users-config-path string The path of the config file with the list of remote cluster users (default /var/lib/cilium/etcd-config/users.yaml) --cluster-users-enabled Enable the management of etcd users for remote clusters --clustermesh-default-global-namespace Mark all namespaces as global by default unless overridden by annotation (default true) --clustermesh-enable-mcs-api Enable Cluster Mesh MCS-API support --clustermesh-mcs-api-install-crds Install and manage the MCS API CRDs. Only applicable if MCS API support is enabled. (default true) --controller-group-metrics strings List of controller group names for which to enable metrics. Accepts all and none. The set of controller group names available is not guaranteed to be stable between Cilium versions. --crd-wait-timeout duration Cilium will exit if CRDs are not available within this duration upon startup (default 5m0s) -D, --debug Enable debugging mode --enable-cilium-endpoint-slice Enables the CiliumEndpointSlice feature --enable-gops Enable gops server (default true) --enable-k8s Enable the k8s clientset (default true) --enable-k8s-api-discovery Enable discovery of Kubernetes API groups and resources with the discovery API --gops-port uint16 Port for gops server to listen on (default 9892) --health-port int TCP port for ClusterMesh health API (default 9880) --k8s-api-server-urls strings Kubernetes API server URLs --k8s-client-burst int Burst value allowed for the K8s client (default 20) --k8s-client-connection-keep-alive duration Configures the keep alive duration of K8s client connections. K8 client is disabled if the value is set to 0 (default 30s) --k8s-client-connection-timeout duration Configures the timeout of K8s client connections. K8s client is disabled if the value is set to 0 (default 30s) --k8s-client-qps float32 Queries per second limit for the K8s client (default 10) --k8s-heartbeat-timeout duration Configures the timeout for api-server heartbeat, set to 0 to disable (default 30s) --k8s-kubeconfig-path string Absolute path of the kubernetes kubeconfig file --k8s-service-proxy-name string Value of K8s service-proxy-name label for which Cilium handles the services (empty all services without service.kubernetes.io/service-proxy-name label) --kvstore string Key-value store type (default etcd) --kvstore-lease-ttl duration Time-to-live for the KVstore lease. (default 15m0s) --kvstore-max-consecutive-quorum-errors uint Max acceptable kvstore consecutive quorum errors before recreating the etcd connection (default 2) --kvstore-opt stringToString Key-value store options e.g. etcd.address127.0.0.1:4001 (default []) --log-driver strings Logging endpoints to use (example: syslog) --log-opt map Log driver options (example: formatjson) --max-connected-clusters uint32 Maximum number of clusters to be connected in a clustermesh. Increasing this value will reduce the maximum number of identities available. Valid configurations are [255, 511]. (default 255) --pprof Enable serving pprof debugging API --pprof-address string Address that pprof listens on (default localhost) --pprof-block-profile-rate int Enable goroutine blocking profiling and set the rate of sampled events in nanoseconds (set to 1 to sample all events [warning: performance overhead]) --pprof-mutex-profile-fraction int Enable mutex contention profiling and set the fraction of sampled events (set to 1 to sample all events) --pprof-port uint16 Port that pprof listens on (default 6063) --prometheus-serve-addr string Address to serve Prometheus metrics --shell-sock-path string Path to the shell UNIX socket (default /var/run/cilium/shell.sock)参数分组与模块对应关系结合 clustermesh-apiserver/clustermesh/cells.go 中Cell的组装方式可以把上述参数映射到具体模块帮助你在依赖图中找到对应节点集群身份与规模--cluster-iduint32集群唯一标识、--cluster-name默认default最多 32 个字符只能包含小写字母数字与-且须以字母数字开头和结尾、--max-connected-clusters合法值为[255, 511]默认 255注意增大该值会减少可用 identity 数量因为 identity 空间需要在集群间共享。这些参数由clustermesh/types与mcsapitypes配置提供。etcd 用户管理--cluster-users-config-path默认/var/lib/cilium/etcd-config/users.yaml、--cluster-users-enabled对应usersManagementCell实现在 users_mgmt.go用于为远程集群管理 etcd 用户。Kubernetes 客户端--enable-k8s默认 true、--k8s-api-server-urls、--k8s-kubeconfig-path、--k8s-client-qps默认 10、--k8s-client-burst默认 20、--k8s-client-connection-keep-alive默认 30s、--k8s-client-connection-timeout默认 30s、--k8s-heartbeat-timeout默认 30s、--k8s-service-proxy-name、--enable-k8s-api-discovery。这些参数对应k8sClient.Cell用于构建访问 API Server 的 clientset。CRD 与资源同步--crd-wait-timeout默认 5m超时未就绪则进程退出、--enable-cilium-endpoint-slice、--clustermesh-enable-mcs-api、--clustermesh-mcs-api-install-crds默认 true、--clustermesh-default-global-namespace默认 true。对应synced.CRDSyncCell与cmk8s.ResourcesCell以及 CiliumNode、CiliumIdentity、CiliumEndpoint、CiliumEndpointSlice 四个同步器。KVStoreetcd--kvstore默认etcd、--kvstore-opt如etcd.address127.0.0.1:4001、--kvstore-lease-ttl默认 15m、--kvstore-max-consecutive-quorum-errors默认 2。对应 KVStore 心跳模块heartbeat.CellClusterMesh 通过它将 K8s 资源状态发布到共享 etcd。可观测与调试--pprof系列--pprof-address默认localhost、--pprof-port默认 6063、--pprof-block-profile-rate、--pprof-mutex-profile-fraction对应pprof.Cell、--enable-gops/--gops-port默认 9892对应gops.Cell、--health-port默认 9880对应HealthAPIEndpointsCell见 health.go、--prometheus-serve-addr、--shell-sock-path默认/var/run/cilium/shell.sock对应 Hive 的 shell 子命令。日志--log-driver、--log-opt、-D/--debug、--controller-group-metrics。如何运行与解读依赖图基本用法在编译好的 clustermesh-apiserver 二进制上直接执行即可clustermesh-apiserver clustermesh hive dot-graph命令会在标准输出打印一份 DOT 格式的依赖图无需连接任何真实集群。若需要渲染成图片可将输出重定向到文件后用 Graphviz 工具处理clustermesh-apiserver clustermesh hive dot-graph hive.dot dot -Tpng hive.dot -o hive.png为什么它能在不启动进程的情况下工作dot-graph属于 Hive 的自省inspect类命令它只读取已注册 cell 的类型与依赖元数据并导出不会执行任何启动钩子。这一点在源码中有明确注释——cells.go 的registerClientsetValidator将客户端校验逻辑放进OnStart钩子时特别说明Executed inside a start hook to avoid blocking when the hive is not actually started (e.g., the dependency graph is output).即需要真实资源如 K8s clientset 是否启用的校验被刻意放入启动钩子就是为了保证在执行dot-graph这类命令时进程不会因为缺少运行环境而阻塞或报错。同理hive的其它自省命令如依赖列表也遵循这一设计原则。从依赖图中能看到什么将clustermesh-apiserver的 Hive 细胞集合展开后依赖图会包含以下典型节点对应 cells.go 中的模块声明clustermesh模块cell.Module(clustermesh, Cilium ClusterMesh, ...)clustermesh-synchronization子模块Synchronization内部又按资源类型分组Service/EndpointSlice 同步ServiceSyncCell、EndpointSliceSyncCell、ServiceExport 同步ServiceExportSyncCell以及四个通过RegisterSynchronizer注册的同步器synchronizer.goCiliumNode、CiliumIdentity、CiliumEndpoint、CiliumEndpointSlice基础设施 cellpprof.Cell、gops.Cell、k8sClient.Cell、cmk8s.ResourcesCell、synced.Cell/synced.CRDSyncCell、heartbeat.Cell、HealthAPIEndpointsCell、clustercfgcell.Cell、usersManagementCell由 pkg/hive/hive.go 统一注入的通用 celljob 组job.Cell、模块健康health.Cell、Hive 指标、StateDBstatedb.Cell并提供按模块作用域的*statedb.DB句柄与 watcher metrics。图中节点代表 cell边代表Provide的依赖被其他 cellInvoke消费的关系。利用它可以快速回答三类问题某个配置/客户端被哪些模块消费、新增模块后注入关系是否成立、是否存在异常依赖路径如跨模块的隐式耦合。与相关命令的关系dot-graph的兄弟命令和父命令官方 cmdref 的 SEE ALSO 部分原文档内部链接已转换为仓库根路径clustermesh-apiserver clustermesh hive — Inspect the hive查看 Hive 运行状况与依赖结构是dot-graph的父命令二者共享同一套继承参数clustermesh-apiserver clustermesh— Run ClusterMesh实际启动进程会执行全部OnStart钩子K8s 客户端校验、CRD 等待、资源同步等。若你想对照依赖图里的模块与运行时的真实行为可以用该命令以--debug启动观察日志。此外这些 cmdref 文档本身由 pkg/cmdref/cmdref.go 通过 spf13/cobra 的doc.GenMarkdownTreeCustom自动生成文件头部的注释This file was autogenerated via clustermesh-apiserver cmdref, do not edit manually即由此写入。这意味着任何新参数的加入或命令结构的变化都会在重新生成后同步反映到本文所述的参数表中参数说明与二进制实际行为始终保持一致。小结clustermesh hive dot-graph是理解 clustermesh-apiserver 内部结构的一把钥匙它以零副作用的方式把 Hive 依赖注入容器中的 cell 依赖关系导出为 Graphviz DOT 文本配合本文梳理的完整继承参数表你可以在不运行真实集群的情况下完成模块结构审查、参数与模块映射分析并为后续排查启动顺序、同步异常等问题打下基础。阅读官方参考页可继续查阅 clustermesh-apiserver clustermesh hive 与 clustermesh-apiserver 等配套文档。【免费下载链接】ciliumeBPF-based Networking, Security, and Observability项目地址: https://gitcode.com/GitHub_Trending/ci/cilium创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表