1

One can use kubectl describe pods to obtain a list of pods and then post-process to determine the nodes that these pods are running on. However, this command takes over 1 second to run.

If I am sshed into a particular Kubernetes node, is there a fast way (less than 100 ms) to talk to the local Kubernetes agent and obtain the list of pods running on localhost?

For example, are there command line clients to the talk to the local kubelet and obtain this information?

merlin2011
  • 239
  • 1
  • 8

3 Answers3

2

with kubectl:

kubectl get pods --all-namespaces --field-selector spec.nodeName=nodename

with api:

curl --cacert ca.crt --cert apiserver.crt --key apiserver.key  https://<server>:<port>/api/v1/namespaces/<namespace>/pods?fieldSelector=spec.nodeName%3Dsomenodename

ps. if docker ps doesnt work for you, you can only talk to the api

4c74356b41
  • 628
  • 5
  • 10
1

Note that kubelet is just a node agent and it does not contain info about the other nodes that belong to the cluster. Event if you do a docker container ls, you will have at least 2 containers per pod (container pod + pod sandbox).

When using kubectl a bunch of factors affect the time a simple kubectl get pods takes. For example, the size of the master node(s), the network latency between the client (kubectl) and the server (master node), the amount of the response (number of pos running on your cluster), etc.

Remember that the size of your master nodes is related to the number of nodes your cluster have. You can create a GCE instance near the zone your master is running, authenticate using a kubeconfig file and run queries to your master.

If kubectl is not an option for you, you can try to make http requests to the master directly (just what kubectl does)

ozrlz
  • 11
  • 1
  • I'm unconcerned about the other nodes in the cluster. I only want to know the names of pods running on *this* node, when I'm running from *this node*. – merlin2011 Feb 09 '19 at 00:56
1

The command kubectl describe pods aggregates different sources to provide the information. Probably one reason why it takes more time.

If you are looking for performance data per node there are many options to choose from:

  • kube-prometheus helps you to set up monitoring for containers and also the nodes. You can filter for the data you are interested. This system works "pull" based, maybe the time resolution is not fine grained enough for you.
  • In a similar way you can setup Metricbeat with the Kubernetes module to log metrics. This is working "push" based, maybe you have more control about the time resolution here.

If these come with too much overhead, here some different ideas:

  • kubectl get events
  • kubectl get pods --watch
  • docker ps and map the containers to Pods by processing metadata from somewhere else. You can run ls -l /var/log/containers to get pod name and namespace for a container from the names of the symlinks.
  • Maybe you can find something else interesting in /var/lib/kubelet/pods.
webwurst
  • 362
  • 2
  • 6