解决 Azure Kubernetes 服务 (AKS) 中的 Application Insights 问题

问题描述 投票:0回答:1

在我的本地计算机中,我运行 docker 映像并看到 Application Insight Azure 工作正常,但是当我使用此映像并将其导出为 AKS 上的服务时,我在操作时看不到 Application Insight 正在工作或跟踪任何内容在网络上。

这是我的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

然后导出服务:

kubectl 公开部署 docker-k8s-demo-deployment --port=80 --protocol=TCP --target-port=8080 --type=LoadBalancer

java azure kubernetes azure-application-insights azure-aks
1个回答
0
投票

这里我已将版本 3.4.9 更改为 azure 应用程序见解。

Pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.2.1</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demo</name>
    <description>Demo project for Spring Boot with Application Insights</description>

    <properties>
        <java.version>17</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>com.microsoft.azure</groupId>
            <artifactId>applicationinsights-core</artifactId>
            <version>3.4.9</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

在本地工作,还能够在我的应用程序洞察中获取日志跟踪。

  • 在创建集群时我们还可以看到一些监控配置。

enter image description here

ACR 存储库: enter image description here

  • 我已使用现有容器注册表配置了我的 AKS,以便我可以访问我的映像。

现在我的应用程序正在 AKS 集群上运行,我仍然可以跟踪日志。

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.