skywalking-agent镜像制作
FROM 10.58.239.195/bn-dev/busybox:latest
ENV LANG=C.UTF-8
RUN set -eux && mkdir -p /usr/skywalking/agent/
ADD ./skywalking/agent/ /usr/skywalking/agent/
WORKDIR /
docker build -t skywalking-agent-sidecar:8.2.0 .
k8s接入
在spec:下添加
initContainers:
- image: 10.58.239.195/skywalking/spring2go/skywalking-agent-sidecar:8.2.0-3
name: sw-agent-sidecar
imagePullPolicy: IfNotPresent
command: ['sh']
args: ['-c','mkdir -p /opt/skywalking/agent && cp -r /usr/skywalking/agent/* /opt/skywalking/agent']
volumeMounts:
- mountPath: /opt/skywalking/agent
name: sw-agent
或者直接引入
env:
- name: JAVA_OPTIONS
value: -javaagent:/opt/skywalking/agent/skywalking-agent.jar #-Dskywalking_config=/opt/skywalking/agent/config/agent-lecshop-sales.config
- name: SW_AGENT_NAME
value: lecshop-sales
- name: SW_LOGGING_FILE_NAME
value: skywalking-api-lecshop-sales.log
- name: SW_AGENT_COLLECTOR_BACKEND_SERVICES
value: 10.60.30.155:11800 # FQDN: servicename.namespacename.svc.cluster.local
- name: SW_MOUNT_FOLDERS
value: plugins,activations
- name: BOOT_OPTIONS
在volumeMounts:下添加
- name: sw-agent
mountPath: /opt/skywalking/agent/
在volumes:下添加
- name: sw-agent
emptyDir: {}
第二种方式
apiVersion: v1
kind: ConfigMap
metadata:
name: skywalking-options
namespace: lecshop
data:
JAVA_OPTIONS: -javaagent:/opt/skywalking/agent/skywalking-agent.jar
SW_AGENT_NAME: lecshop-sales
SW_LOGGING_FILE_NAME: skywalking-api-lecshop-sales.log
SW_AGENT_COLLECTOR_BACKEND_SERVICES: 10.60.30.155:11800
SW_MOUNT_FOLDERS: plugins,activations
SW_LOGGING_MAX_FILE_SIZE: "314572800"
SW_LOGGING_MAX_HISTORY_FILES: "1"
SW_AGENT_TRACE_IGNORE_PATH: /xxx/**
在spec:下添加
initContainers:
- image: 10.58.239.195/skywalking/spring2go/skywalking-agent-sidecar:8.2.0-3
name: sw-agent-sidecar
imagePullPolicy: IfNotPresent
command: ['sh']
args: ['-c','mkdir -p /opt/skywalking/agent && cp -r /usr/skywalking/agent/* /opt/skywalking/agent']
volumeMounts:
- mountPath: /opt/skywalking/agent
name: sw-agent
测试环境在env平行位置添加
envFrom:
- configMapRef:
name: skywalking-options
在volumeMounts:下添加
- name: sw-agent
mountPath: /opt/skywalking/agent/
在volumes:下添加
- name: sw-agent
emptyDir: {}
开发侧修改
dockerfile文件
添加${JAVA_OPTIONS}这个变量
ENTRYPOINT ["sh","-c","java {BOOT_OPTIONS} ${ADDITIONAL_OPTIONS}"]
pom文件
增加maven依赖:
<dependency>
<groupId>org.apache.skywalking</groupId>
<artifactId>apm-toolkit-logback-1.x</artifactId>
<version>6.2.0</version>
</dependency>
logback.xml文件
增加一个appender,如下
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
<layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout">
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} | %localIp | ${serviceName} | %thread | %-5level | %logger{36} |%tid | %msg%n
</pattern>
</layout>
</encoder>
</appender>