Kubernetes Cluster: Using SkyWalking to Collect Tracing Data from Applications¶
Introduction¶
In a Kubernetes cluster, applications are deployed as images. When using SkyWalking to collect tracing data from applications, following the traditional approach—embedding the SkyWalking Agent into each application image before deployment—leads to overly large images and makes future SkyWalking version upgrades inconvenient. This article introduces a method that uses the official SkyWalking image to provide the SkyWalking Agent via initContainers for collecting tracing data.
Prerequisites¶
Install DataKit¶
- Install DataKit
- DataKit access version ≥ 1.4.15
Enable the Input¶
To enable the SkyWalking collector, you need to add the file /usr/local/datakit/conf.d/skywalking/skywalking.conf on the server where DataKit is running. When deploying with DaemonSet, you must first define a ConfigMap and then mount the file into the DataKit container. You will need the datakit.yaml file used during DataKit deployment.
Define skywalking.conf¶
Add the definition of skywalking.conf to the ConfigMap resource in the datakit.yaml file.
apiVersion: v1
kind: ConfigMap
metadata:
name: datakit-conf
namespace: datakit
data:
## The following is the new content
skywalking.conf: |-
[[inputs.skywalking]]
## skywalking grpc server listening on address
address = "0.0.0.0:11800"
Mount skywalking.conf¶
Add the following content under volumeMounts in the datakit.yaml file.
- mountPath: /usr/local/datakit/conf.d/skywalking/skywalking.conf
name: datakit-conf
subPath: skywalking.conf
Restart DataKit¶
Ingesting Java Tracing Data¶
Create a Test Application¶
The example uses datakit-springboot-demo. Download it and build it into a JAR file named service-demo-1.0-SNAPSHOT.jar.
Build the Image¶
Write a Dockerfile.
FROM openjdk:8u292
RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
RUN echo 'Asia/Shanghai' >/etc/timezone
ENV jar service-demo-1.0-SNAPSHOT.jar
ENV workdir /data/app/
RUN mkdir -p ${workdir}
COPY ${jar} ${workdir}
WORKDIR ${workdir}
ENTRYPOINT ["sh", "-ec", "exec java ${JAVA_OPTS} -jar ${jar} ${PARAMS} "]
Build the image and upload it to the image registry.
docker build -t 172.16.0.246/df-demo/service-demo:v1 .
docker push 172.16.0.246/df-demo/service-demo:v1
Deploy the Application¶
In the skywalking-demo.yaml deployment file, use initContainers to initialize the apache/skywalking-java-agent:8.7.0-alpine image. The Pod's application can then access skywalking-agent.jar. Define the startup command in JAVA_OPTS, where -Dskywalking.agent.service_name=skywalking-demo-master sets the application alias to skywalking-demo-master.
apiVersion: apps/v1
kind: Deployment
metadata:
name: skywalking-demo-deployment
spec:
replicas: 1
selector:
matchLabels:
app: skywalking-demo-pod
template:
metadata:
labels:
app: skywalking-demo-pod
annotations:
spec:
containers:
- name: skywalking-demo-demo-container
image: 172.16.0.246/df-demo/service-demo:v1
env:
- name: HOST_IP
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: status.hostIP
- name: HOST_NAME
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: spec.nodeName
- name: JAVA_OPTS
value: |-
-javaagent:/skywalking/agent/skywalking-agent.jar -Dskywalking.agent.service_name=skywalking-demo-master -Dskywalking.collector.backend_service=$(HOST_IP):11800
ports:
- containerPort: 8090
protocol: TCP
volumeMounts:
- mountPath: /skywalking
name: skywalking-agent
initContainers:
- name: agent-container
image: apache/skywalking-java-agent:8.7.0-alpine
volumeMounts:
- name: skywalking-agent
mountPath: /agent
command: [ "/bin/sh" ]
args: [ "-c", "cp -R /skywalking/agent /agent/" ]
restartPolicy: Always
volumes:
- name: skywalking-agent
emptyDir: {}
Access the Application¶
Check the Pod's port.
Invoke the application to generate tracing data.
Application Performance Monitoring (APM)¶
Log in to Guance and navigate to the Application Performance Monitoring (APM) module to view the skywalking-demo-master application.

