一、安装SkyWalking服务

1.下载SkyWalking APM:https://skywalking.apache.org/downloads/ 这里下载Distribution的v9.0.0版本tar并解压

2.进入bin目录分别启动oapService.sh,webappService.sh

 3.访问地址:http://127.0.0.1:8080


二、制作SkyWalking-Agent镜像
1.下载Java Agent:https://skywalking.apache.org/downloads/ 这里下载Distribution的v8.10.0版本的tar并解压

2.创建Dockfile文件,内容如下:

FROM busybox:latest
COPY skywalking-agent/ /skywalking/agent/
WORKDIR /


3.目录结构如下:


4.制作镜像,在/opt目录下执行命令:docker build -t tiandizhiguai/skywalking-agent:8.9 .

5.上传镜像到docker hub:docker push tiandizhiguai/skywalking-agent:8.9

6.假如有一个名称为hello的springboot应用,打包成hello.jar,生成docker镜像时增加如下配置:

ENTRYPOINT ["java”, "-javaagent:/opt/agent/skywalking-agent.jar”, "-Dskywalking.agent.service_name=hello", "-Dskywalking.collector.backend_service=172.27.42.63:11800", "-jar”, "hello.jar”]

7.制作SpringBoot应用的Deployment文件hello-deployment.yml,内容如下:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: hello-app
  template:
    metadata:
      labels:
        app: hello-app
    spec:
      initContainers:
        - name: skywalking-agent
          image: tiandizhiguai/skywalking-agent:8.9
          command: ['cp','-rf','/skywalking/agent','/tmp']
          volumeMounts:
            - mountPath: /tmp
              name: skw-agent-volume
      containers:
        - name: hello-app
          image: tiandizhiguai/hello-1.0.0:1648457495615
          env:
            - name: TZ
              value: Asia/Shanghai
          volumeMounts:
            - mountPath: /opt
              name: skw-agent-volume
      volumes:
        - name: skw-agent-volume
          emptyDir: {}

三、部署Springboot应用

1.执行如下命令:

kubectl create -f hello-deployment.yml

2.执行如下命令,查询pod的ip:

kubectl get pods -o wide

结果如下:

3.访问hello应用的接口

curl http://10.244.1.4:8080/hello

 4.访问SkyWalking Web:http://localhost:8080/,如下图:

集成成功。

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐