How to identify Host cloud provider from kubernetes pods?

8/10/2018

Is it possible to identify the Host cloud provider/Platform from kubernetes Pods? If so, how?

Right now, I am only looking for google cloud, aws and azure. Do they mount any specific file on a pod or do they set any specific Environment variable, from where I can identify the cloud provider/platform?

I am not looking for a generic way, different ways to find out different cloud providers is also fine at this moment.

-- Abdullah Al Maruf - Tuhin
amazon-web-services
azure
google-cloud-platform
kubernetes

1 Answer

8/10/2018

There are no environment variables or mounts that i know of, but the linux kernel version string can give you a hint. The version info provided by uname or cat /proc/version actually is of the node not of the pod.

For example on Azure kubectl exec my-pod-name -- uname -r yields:

4.15.0-1018-azure

On GKE you should see something like

4.15.0-1018-gke

And AWS got

4.15.0-1018-aws

Using awk you can then filter out the cloud provider. This yields azure, gke or aws when run inside a pod:

uname -r|awk -F"-" '{print $3}'
-- Markus Dresch
Source: StackOverflow