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

前端 未结 3 1342
慢半拍i
慢半拍i 2021-01-17 09:33

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?

3条回答
  •  悲哀的现实
    2021-01-17 10:12

    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

提交回复
热议问题