【问题标题】:Get the current and the most latest CPU and Memory usage of all the pods获取所有 Pod 的当前和最新的 CPU 和内存使用情况
【发布时间】:2019-08-10 14:01:19
【问题描述】:

我想知道如何获取所有 Pod 的 CPU 和内存使用情况的当前或上次读取的指标值。

我试图调用小贩端点。我通过按 f12 进入浏览器开发人员模式,并从加载 pod 的指标页面时进行的调用列表中获取此端点。

https://metrics.mydev.abccomp.com/hakular/metrics/gauges/myservice%dfjlajdflk-lkejre-12112kljdfkl%2Fcpu%2Fusage_rate/data?bucketDuration=1mn&start=-1mn

但是,这将为我提供该特定 pod 在最后一分钟的 cpu 使用指标。我正在尝试查看是否存在命令或方式,它只会为我提供所有 pod 的 CPU 使用情况和内存统计信息的当前快照,如下所示:

pod        memory usage     memory max       cpu usage         cpu max
pod1       0.4 mb            2.0 mb            20 m cores       25 m cores
pod2       1.5 mb            2.0 mb            25 m cores       25 m cores 

【问题讨论】:

    标签: kubernetes redhat kubernetes-helm redhat-containers hawkular


    【解决方案1】:

    要查看使用最多 cpu 和内存的 pod,您可以使用 kubectl top 命令,但它尚未排序,并且还缺少配额限制和每个 pod 的请求。您只能看到当前的使用情况。

    执行以下命令:

    $ kubectl top pods --all-namespaces --containers=true
    

    由于这些限制,还因为您希望持续收集和存储这些资源使用信息,因此监控工具会派上用场。这使您可以实时和历史分析资源使用情况,还可以提醒您容量瓶颈。

    解决问题“来自服务器的错误(禁止):未知(获取服务 http:heapster”

    确保heapster部署不要忘记为heapster安装Service,否则你将不得不手动进行。

    例如:

    $ kubectl create -f /dev/stdin <<SVC
    apiVersion: v1
    kind: Service
    metadata:
      name: heapster
      namespace: kube-system
    spec:
      selector:
        whatever-label: is-on-heapster-pods
      ports:
      - name: http
        port: 80
        targetPort: whatever-is-heapster-is-listening-on
    SVC
    

    【讨论】:

      【解决方案2】:

      列出所有容器(pod)的资源 CPU 和内存利用率

      kubectl top pods --all-namespaces --containers=true

      默认的 admin、edit、view 和 cluster-reader 集群角色支持集群角色聚合,其中每个角色的集群规则会随着新规则的创建而动态更新。仅当您通过创建自定义资源来扩展 Kubernetes API 时,此功能才相关。 Cluster-role-aggregator

      apiVersion: rbac.authorization.k8s.io/v1
      kind: ClusterRole
      metadata:
        name: top-pods-admin
        labels:
          rbac.authorization.k8s.io/aggregate-to-admin: "true"
          rbac.authorization.k8s.io/aggregate-to-edit: "true"
          rbac.authorization.k8s.io/aggregate-to-view: "true"
      rules:
      - apiGroups:
        - metrics.k8s.io
        resources:
        - pods
        verbs:
        - get
        - list
        - watch
      
      

      【讨论】:

      • 我没有安装 kubectl。可以这样做吗:oc top pods --all-namespaces --containers=true
      • 是的,oc adm top pods --all-namespaces --containers=true
      • 顺便说一句,当你安装 oc 时,它也会安装 kubectl
      • 我现在安装了 kubectl。这就是我得到的$ kubectl top pods --all-namespaces --containers=true Error from server (Forbidden): unknown (get services http:heapster:)
      • 所以,你需要一个 RBAC。看来您只能访问项目资源,请让您的集群管理员给您一个角色(集群读者)来访问这些端点,
      猜你喜欢
      • 2021-05-09
      • 2019-08-04
      • 1970-01-01
      • 1970-01-01
      • 2020-11-12
      • 1970-01-01
      • 2015-09-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多