You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure Kubernetes Service(AKS)中Application Insights故障排查求助

本地Docker镜像运行时Azure Application Insights正常,部署到AKS后无追踪数据

本地运行Docker镜像时,Azure Application Insights可正常工作;但将该镜像部署为AKS中的服务后,操作Web应用时无法看到Application Insights工作或生成任何追踪数据。

以下是相关配置:

pom.xml依赖配置

<dependency>
    <groupId>com.microsoft.azure</groupId>
    <artifactId>applicationinsights-core</artifactId>
    <version>3.4.19</version>
</dependency>

<dependency>
    <groupId>com.microsoft.azure</groupId>
    <artifactId>applicationinsights-runtime-attach</artifactId>
    <version>3.4.19</version>
</dependency>

applicationinsights.json配置

{
  "connectionString": "InstrumentationKey=SECRET",

  "instrumentation": {

    "logging": {

      "level": "DEBUG"

    }

  }
}

主应用启动代码

package com.example.springsocial;

import com.example.springsocial.config.AppProperties;
import com.microsoft.applicationinsights.attach.ApplicationInsights;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;

@SpringBootApplication
@EnableConfigurationProperties(AppProperties.class)
public class SpringSocialApplication {

    public static void main(String[] args) {
        ApplicationInsights.attach();
        SpringApplication.run(SpringSocialApplication.class, args);
    }
}

Dockerfile配置

FROM maven:3.8.5-openjdk-17 AS build
COPY . .
RUN mvn clean package -Pprod -DskipTests

FROM openjdk:17.0.1-jdk-slim
EXPOSE 8080
COPY --from=build /target/spring-social-0.0.1-SNAPSHOT.jar spring-social.jar
ENTRYPOINT ["java","-jar","spring-social.jar"]

AKS部署操作与配置

部署应用

执行命令:

kubectl apply -f docker-k8s.yaml

docker-k8s.yaml部署配置

apiVersion: apps/v1
kind: Deployment
metadata:
  name: docker-k8s-demo-deployment
  labels:
    app: docker-k8s-demo
spec:
  replicas: 1
  selector:
    matchLabels:
      app: docker-k8s-demo
  template:
    metadata:
      labels:
        app: docker-k8s-demo
    spec:
      containers:
      - name: docker-k8s-demo
        image: image here
        ports:
        - containerPort: 8080

创建LoadBalancer服务

执行命令:

kubectl expose deployment docker-k8s-demo-deployment --port=80 --protocol=TCP --target-port=8080 --type=LoadBalancer

内容的提问来源于stack exchange,提问作者abcd1211231

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.03 08:24:59