How to extract information about a PV attached to a pod from an app running in another pod?

12/18/2020

Among a big stack of orchestrated k8s pods, I have following two pods of interest: 1. Elasticsearch pod attached to a PV 2. A tomcat based application pod that serves as administrator for all other pods

I want to be able to query and display very minimal/basic disk availability and usage statistics of the PV (attached to pod #1) on the app running in pod #2

Can this be achieved without having to run a web-server inside my ES pod? Since ES might be very loaded, I prefer not to add a web-server to it.

The PV attached to ES pod also holds the logs. So I want to avoid any log-extraction-based solution to achieve getting this information over to pod #2.

-- A.R.K.S
kubernetes
kubernetes-pvc

1 Answer

12/18/2020

You need get the PV details from kubernetes cluster API, where ever you are.

Accessing the Kubernetes cluster API from within a Pod

When accessing the API from within a Pod, locating and authenticating to the API server are slightly different to the external client case described above.

The easiest way to use the Kubernetes API from a Pod is to use one of the official client libraries. These libraries can automatically discover the API server and authenticate.

Using Official Client Libraries

From within a Pod, the recommended ways to connect to the Kubernetes API are:

  • For a Go client, use the official Go client library. The rest.InClusterConfig() function handles API host discovery and authentication automatically. See an example here.

  • For a Python client, use the official Python client library. The config.load_incluster_config() function handles API host discovery and authentication automatically. See an example here.

  • There are a number of other libraries available, please refer to the Client Libraries page.

In each case, the service account credentials of the Pod are used to communicate securely with the API server.

Reference

https://kubernetes.io/docs/tasks/administer-cluster/access-cluster-api/#accessing-the-api-from-within-a-pod

-- BMW
Source: StackOverflow