How to see if a pod is topping its CPU limit?

I have a pod in kubernetes where it's slowing down under heavy load. The pod has two containers -- Nginx and PHP.

I see that Nginx is set to use "100m" CPU and PHP is set to use 1 CPU (1 core). I'm suspecting that Nginx might be bottleneck, but I'm having hard time to determine it.

This is my Kube setting for the nginx.

 resources:
      limits:
        cpu: 100m
        memory: 128M
      requests:
        cpu: 100m
        memory: 128M

When I SSH into Nginx container and use "top" command, I see 1% CPU pretty much all the time. I never see it goes over 1%.

7 nginx 20 0 31972 2360 972 S 0.7 0.0 7:07.94 nginx 1 root 20 0 31480 1784 976 S 0.0 0.0 0:00.01 nginx

Is that mean that Nginx container is limited to 1% CPU usage because I set the CPU request to 100m?

Am I reading it correctly? or is there a standard way of reading CPU usage of a single container in a pod?

3 answers

  • answered 2018-11-08 07:34 Prafull Ladha

    To check the pods that use most memory and CPU, you can use the kubectl top command, but it doesn't sort the pods on basis of highest usage. You can only see the current usage of pods.

    $ kubectl top pod --all-namespaces
    NAMESPACE NAME CPU(cores) MEMORY(bytes)
    kube-system kube-proxy-gke-rel3170-default-pool-3459fe6a 2m 12Mi
    kube-system kube-proxy-gke-rel3170-default-pool-3459fe6a 2m 12Mi
    kube-system fluentd-gcp-v2.0.9-5t9q6 8m 85Mi
    kube-system fluentd-gcp-v2.0.9-pd4s9 10m 84Mi
    

    However it doesn't show the quota limits of pods. It just shows current CPU and memory usage of pod. Hope this helps.

  • answered 2018-11-08 08:13 Ijaz Ahmad Khan

    Regardless , you need to re-architect your setup.

    • run and scale nginx independently on separate pods
    • run php app on separate pods

  • answered 2018-11-08 08:31 Manvendra Jina

    Use kubernetes dashboard to analyse your pods.

    To deploy you need to use "kubectl proxy" command.

    kubectl proxy

    Create a token for your kube dashboard configuration and you will be able to monitor your pods through dashboard.

    you can check below video https://www.youtube.com/watch?v=RNgjy31gFuI