分析 AlloyDB Omni Kubernetes Operator 内存堆使用情况

本文档介绍了如何获取 AlloyDB Omni 运算符内存堆的快照,以帮助诊断和调试潜在的内存问题。请按照以下步骤获取要分析的内存堆:

  1. 确定要分析哪个 AlloyDB Omni operator 部署。AlloyDB Omni operator 包含两个部署,您可以分析其中任一部署的内存堆。如需识别这两个部署,请运行以下命令:

    kubectl get deployment -n alloydb-omni-system

    输出结果会显示 alloydb-omni-system 命名空间中的两个部署:

    • fleet-controller-manager
    • local-controller-manager

    您可以获取任一部署的内存堆。出于演示目的,以下步骤展示了如何获取 local-controller-manager 部署的内存堆。

  2. 通过指定要使用的可用端口来开启内存分析。指定端口后,Pod 会重启。如需指定可用端口,请在部署中使用 pprof-address 参数:

    1. 运行以下命令,在文本编辑器中打开部署:

      kubectl edit -n alloydb-omni-system deploy local-controller-manager
    2. 在模板 speccontainer 部分的 args 中指定端口:

      apiVersion: apps/v1
      kind: Deployment
      spec:
        ...
        template:
        ...
          spec:
            containers:
            - args
              - --pprof-address=:PORT
      
    3. 保存部署文件。保存部署文件后,Pod 会重启。

  3. 等待 pod 重启,然后继续执行下一步。

    如需确保 Pod 已重启,请运行以下命令:

    kubectl get pod -n alloydb-omni-system

    验证 pod 的 STATUS 列中的输出值为 Running,并且其 AGE 列中的输出值为短时时长。例如,如果 STATUS 列为 Running,且 AGE 列中的值为 50s,则表示该 Pod 在重启后已运行 50 秒。

  4. 使用以下命令开启端口转发:

    kubectl port-forward -n alloydb-omni-system DEPLOYMENT_POD_NAME PORT:PORT

    DEPLOYMENT_POD_NAME 替换为以下命令输出中 NAME 列中显示的部署名称:

    kubectl get pod -n alloydb-omni-system
  5. 在其他终端中,运行以下命令以创建包含部署内存堆的快照的文件:

    curl http://localhost:PORT/debug/pprof/heap > heap.out
  6. 保存 heap.out 文件,并使用该文件查看您选择分析的 AlloyDB Omni 运算符部署的内存堆。

  7. 从部署中移除包含您使用的端口的 pprof-address 参数,以关闭内存分析:

    1. 在文本编辑器中打开部署:

      kubectl edit -n alloydb-omni-system deploy local-controller-manager
    2. 从您之前添加的模板 speccontainer 部分的 args 中移除端口 --pprof-address=:PORT 行。

后续步骤