{"id":11219,"date":"2025-01-25T09:51:44","date_gmt":"2025-01-25T09:51:44","guid":{"rendered":"https:\/\/putridparrot.com\/blog\/?p=11219"},"modified":"2025-01-26T11:10:44","modified_gmt":"2025-01-26T11:10:44","slug":"is-my-asp-net-core-application-running-in-kubernetes-or-docker","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/is-my-asp-net-core-application-running-in-kubernetes-or-docker\/","title":{"rendered":"Is my ASP.NET core application running in Kubernetes (or Docker) ?"},"content":{"rendered":"<p>I came across a situation where I needed to change some logic in my ASP.NET core application dependant upon whether I was running inside Kubernetes or an Azure Web app, luckily there is an environment variable that we can use (and whilst we&#8217;re at it, there&#8217;s one for Docker as well)<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nvar isHostedInKubernetes = \r\n   Environment.GetEnvironmentVariable(&quot;KUBERNETES_SERVICE_HOST&quot;) != null;\r\nvar isHostedInDocker = \r\n   Environment.GetEnvironmentVariable(&quot;DOTNET_RUNNING_IN_CONTAINER&quot;) == &quot;true&quot;;\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I came across a situation where I needed to change some logic in my ASP.NET core application dependant upon whether I was running inside Kubernetes or an Azure Web app, luckily there is an environment variable that we can use (and whilst we&#8217;re at it, there&#8217;s one for Docker as well) var isHostedInKubernetes = Environment.GetEnvironmentVariable(&quot;KUBERNETES_SERVICE_HOST&quot;) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[200,102,314],"tags":[],"class_list":["post-11219","post","type-post","status-publish","format-standard","hentry","category-asp-net-core","category-docker","category-kubernetes"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/11219","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/comments?post=11219"}],"version-history":[{"count":4,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/11219\/revisions"}],"predecessor-version":[{"id":11225,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/11219\/revisions\/11225"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=11219"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=11219"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=11219"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}