Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I tell if my container is running inside a Kubernetes cluster?

Tags:

How can I tell whether or not I am running inside a kubernetes cluster? With docker I can check if /.dockerinit exist. Is there an equivalent?

like image 319
CESCO Avatar asked Apr 15 '16 05:04

CESCO


People also ask

How do you know if a pod is running in Kubernetes?

To check the version, enter kubectl version . In this exercise you will use kubectl to fetch all of the Pods running in a cluster, and format the output to pull out the list of Containers for each.

How do I see running processes in Kubernetes?

Run the docker exec command in that server to see the process running inside.

How do I know if container runtime is running?

In the output, look for the --container-runtime flag and the --container-runtime-endpoint flag. If your nodes use Kubernetes v1. 23 and earlier and these flags aren't present or if the --container-runtime flag is not remote , you use the dockershim socket with Docker Engine.


1 Answers

You can check for KUBERNETES_SERVICE_HOST environment variable.

This variable is always exported in an environment where the container is executed.

Refer to https://kubernetes.io/docs/concepts/services-networking/connect-applications-service/#environment-variables

like image 59
Gajus Avatar answered Sep 21 '22 15:09

Gajus