Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error 'Application is not running inside a Kubernetes cluster' in AKS pod's logs #370

Open
ReySka91 opened this issue Oct 3, 2024 · 1 comment
Assignees

Comments

@ReySka91
Copy link

ReySka91 commented Oct 3, 2024

Description
We are running ApplicationInsights.Kubernetes with our microservices in AKS.
We take the tool into use like this:
services.AddApplicationInsightsTelemetry();
services.AddApplicationInsightsKubernetesEnricher();

We have configured RBAC permissions according to this guide.

For some reason, the tool does not work at all.

We have run the troubleshooter tool without any issues using the same versions as our main applicaion. We have enabled the diagnostics with services.AddApplicationInsightsKubernetesEnricher(LogLevel.Trace);. The only message related to this tool in the pod's logs is: [Error] [2024-10-03T10:23:15.6375636Z] Application is not running inside a Kubernetes cluster..

Package Versions
Application Insights Kubernetes Version: 7.0.0
Application Insights SDK Version: 2.22.0
.NET Core Version: 8

Expected behavior
The tool works without errors and the additional information is shown in application insights

Actual bevior
The tool fails on error 'Application is not running inside a Kubernetes cluster' even though it is running in AKS.

Can you please help with this issue? I'm not sure whether this is a bug or just a misconfiguration or if it has something to do with our versions (even though the troubleshooter works with the same versions)

@xiaomi7732 xiaomi7732 self-assigned this Oct 14, 2024
@xiaomi7732
Copy link
Member

@ReySka91, in the latest version, the check is straightforward:

public bool IsInCluster => KubernetesClientConfiguration.IsInCluster();

That, in turn, calls:
https://github.com/kubernetes-client/csharp/blob/541abb00bd1472e86b37863822cce5415613806b/src/KubernetesClient/KubernetesClientConfiguration.InCluster.cs#L21

Basically, do you see any of these line of code returning false for your environment:

        public static bool IsInCluster()
        {
            var host = Environment.GetEnvironmentVariable("KUBERNETES_SERVICE_HOST");
            var port = Environment.GetEnvironmentVariable("KUBERNETES_SERVICE_PORT");

            if (string.IsNullOrEmpty(host) || string.IsNullOrEmpty(port))
            {
                return false;
            }

            var tokenPath = Path.Combine(ServiceAccountPath, ServiceAccountTokenKeyFileName);
            if (!FileSystem.Current.Exists(tokenPath))
            {
                return false;
            }

            var certPath = Path.Combine(ServiceAccountPath, ServiceAccountRootCAKeyFileName);
            return FileSystem.Current.Exists(certPath);
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants