“This is the 10th day of my participation in the Gwen Challenge in November. Check out the details: The Last Gwen Challenge in 2021.”
An overview,
1. What is SkyWalking?
Application performance monitoring tool for distributed systems, designed for microservices, cloud native architectures, and container-based (Docker, K8s, Mesos) architectures. Provides integrated solutions for distributed tracking, service grid telemetry analysis, measurement aggregation and visualization.
Official website: skywalking.apache.org/
2. SkyWalking features
- Multiple monitoring tools, language probes and Service Mesh
- Multi-language automatic probe, Java,.NET Core and Node.js
- Lightweight and efficient, no need for big data
- Modularization: UI, storage, and cluster management are optional
- Support the alarm
- Excellent visualization scheme
3. Overall structure
The whole structure is divided into four parts: top, bottom, left and right:
In order to simplify the description, we abandoned Metric indicator correlation and focused on the link correlation function of Tracing.
- Upper Agent: Collects link information from applications and sends it to the SkyWalking OAP server. Currently, Tracing data provided by SkyWalking, Zikpin, And Jaeger are supported. What we currently use is SkyWalking Agent collection
SkyWalking Tracing
Data, passed to the server. - Under section
SkyWalking OAP
: To receive Tracing data sent by agents, analyze Core, store it to external Storage, and finally provide Query function. - Right part Storage: Tracing Data store. Currently supports ES, MySQL, Sharding Sphere, TiDB, H2
Multiple memory. We currently use ES, mainly considering the SkyWalking development team’s own production environment using ES.
- The left part
SkyWalking UI
: Responsible for providing console, viewing link, etc
The simple overview principle is as follows:
Ii. Building Skywalking
1. Environment preparation
- Mkubernetes version: 1.18.5
- Nginx Ingress version: 2.2.8
- Helm version: 3.2.4
- Persistent storage driver: NFS
2. Use Chart deployment
This article describes how to deploy SkyWalking into a Kubernetes cluster using Helm Charts. Please refer to SkyWalking – Kubernetes
Four methods are currently recommended:
- Start the local Helm REPO using helm Serve provided by Helm 3
- Deploy using a local chart file
- Use the RepO feature provided by Harbor
- Deploy directly from the official REPO (not yet satisfied)
Note: Currently, skywalking chart has not been submitted to the official warehouse, please first refer to the first three methods for deployment
2.1 download chart file
Skywalking can be deployed directly from a local file. After downloading Skywalking Chart following the steps above, you can deploy skywalking directly using the following command:
git clone https://github.com/apache/skywalking-kubernetes
cd skywalking-kubernetes/chart
helm repo add elastic https://helm.elastic.co
helm dep up skywalking
export SKYWALKING_RELEASE_NAME=skywalking # Define your own name
export SKYWALKING_RELEASE_NAMESPACE=default # define your own namespace
Copy the code
2.2. Define an existing ES parameter file
Modify the values – my – es. Yaml:
oap:
image:
tag: 8.1. 0-es7 # Set the right tag according to the existing Elasticsearch version
storageType: elasticsearch7
ui:
image:
tag: 8.1. 0
elasticsearch:
enabled: false
config: # For users of an existing elasticsearch cluster,takes effect when `elasticsearch.enabled` is false
host: elasticsearch-client
port:
http: 9200
user: "elastic" # [optional]
password: "admin@123" # [optional]
Copy the code
2.3 Installation of helm
helm install "${SKYWALKING_RELEASE_NAME}" skywalking -n "${SKYWALKING_RELEASE_NAMESPACE}" \
-f ./skywalking/values-my-es.yaml
Copy the code
After the installation is completed, we verify the installation situation:
$ kubectl get deployment -n skywalking NAME READY UP-TO-DATE AVAILABLE AGE my-skywalking-oap 2/2 2 2 9m my-skywalking-ui 1/1 1 1 9mCopy the code
3. Use Skywalking Agent
The Following three methods are available for you to use agent in Java
- Use the official base image
- Build the Agent package into an existing base image
- Mounting agent in Sidecar mode (recommended)
1. Use the official base image
Check the basic image provided by the official Docker Hub, just need to build the service image From this image, directly integrate into Jenkins can be more convenient
2. Build the Agent package into the existing base image
The reason for providing this method is that the official image is a compact image and is openJDK. Many commands may not be available, so you need to install them again.
3. Mount agent in Sidecar mode
Since the service is deployed in Kubernetes, the advantage of using Skywalking Agent in this way is that there is no need to modify the original base image, nor to rebuild the new service image, but in sidecar mode. By sharing the volume, you can mount files required by the Agent to an existing service image.
3.1. Construct skywalking Agent image
Build yourself, reference: hub.docker.com/r/prophet/s…
Build with the following dockerfile:
The FROM alpine: LABEL maintainer = 3.8"[email protected]"ENV SKYWALKING_VERSION = 8.1.0 ADD http://mirrors.tuna.tsinghua.edu.cn/apache/skywalking/${SKYWALKING_VERSION}/apache-skywalking-apm-${SKYWALKING_VERSION}.tar.gz /
RUN tar -zxvf /apache-skywalking-apm-${SKYWALKING_VERSION}.tar.gz && \ mv apache-skywalking-apm-bin skywalking && \ mv /skywalking/agent/optional-plugins/apm-trace-ignore-plugin* /skywalking/agent/plugins/ && \echo -e "\n# Ignore Path" >> /skywalking/agent/config/agent.config && \
echo "# see https://github.com/apache/skywalking/blob/v8.1.0/docs/en/setup/service-agent/java-agent/agent-optional-plugins/trace-ign ore-plugin.md" >> /skywalking/agent/config/agent.config && \
echo 'trace.ignore_path=${SW_IGNORE_PATH:/health}' >> /skywalking/agent/config/agent.config
Copy the code
Docker build -t 172.16.106.237 / monitor/skywalking - agent: 8.1.0.Copy the code
After the docker is built, push it to the warehouse.
3.2 Use Sidecar for Mounting
The following is an example configuration file:
apiVersion: apps/v1
kind: Deployment
metadata:
name: demo-skywalking
spec:
replicas: 1
selector:
matchLabels:
app: demo-skywalking
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
type: RollingUpdate
template:
metadata:
labels:
app: demo-skywalking
spec:
initContainers:
- name: init-skywalking-agent
image: 172.16106.237./ monitor/skywalking - agent: 8.1.0
command:
- 'sh'
- '-c'
- 'set -ex; mkdir -p /vmskywalking/agent; cp -r /skywalking/agent/* /vmskywalking/agent; '
volumeMounts:
- mountPath: /vmskywalking/agent
name: skywalking-agent
containers:
- image: Nginx: 1.7.9
imagePullPolicy: Always
name: nginx
ports:
- containerPort: 80
protocol: TCP
volumeMounts:
- mountPath: /opt/skywalking/agent
name: skywalking-agent
volumes:
- name: skywalking-agent
emptyDir: {}
Copy the code
The above is to mount the deployment.yaml file of sidecar. Taking nginx as a service as an example, agent is mainly mounted by sharing volume. First, initContainers mount/VMSkywalking /agent in SW-agent-Sidecar through the Skywalk-Agent volume. / vmSkywalking /agent; / vmSkywalking /agent; / vmSkywalking /agent; / vmSkywalking /agent And mount it to the container’s /opt/ Skywalking /agent directory to complete the sharing process.
4. Transform the Spring Cloud application
1. Docker is packaged and pushed to the warehouse
Modify dockerfile configuration to integrate Skywalking Agent:
FROM insideo/centos7-java8-build VOLUME /tmp ADD mall-admin.jar app.jar RUN bash -c 'touch /app.jar' RUN ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo Asia/Shanghai > /etc/timezone ENTRYPOINT ["java","-Dapp.id=svc-mall-admin","-javaagent:/opt/skywalking/agent/skywalking-agent.jar","-Dskywalking.agent.service_na me=svc-mall-admin","-Dskywalking.collector.backend_service=my-skywalking-oap.skywalking.svc.cluster.local:11800","-jar", "-Dspring.profiles.active=prod","-Djava.security.egd=file:/dev/./urandom","/app.jar"]Copy the code
Instead, run maven package directly to package the project as an image.
Note:
When K8S creates a Service, it creates the corresponding DNS entry. This entry is in the format of
.
.svc.cluster.local, which means that if the container uses only
, it will resolve as a local service to the namespace. If you want to access across namespaces, you need to use a fully qualified domain name.
2. Write deployment scripts of YAML version of K8S
Here’s an example of one service:
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: svc-mall-admin
spec:
replicas: 1
selector:
matchLabels:
app: svc-mall-admin
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
type: RollingUpdate
template:
metadata:
labels:
app: svc-mall-admin
spec:
initContainers:
- name: init-skywalking-agent
image: 172.16106.237./ monitor/skywalking - agent: 8.1.0
command:
- 'sh'
- '-c'
- 'set -ex; mkdir -p /vmskywalking/agent; cp -r /skywalking/agent/* /vmskywalking/agent; '
volumeMounts:
- mountPath: /vmskywalking/agent
name: skywalking-agent
containers:
- image: 172.16106.237./ mall_repo/mall - admin: 1.0
imagePullPolicy: Always
name: mall-admin
ports:
- containerPort: 8180
protocol: TCP
volumeMounts:
- mountPath: /opt/skywalking/agent
name: skywalking-agent
volumes:
- name: skywalking-agent
emptyDir: {}
---
apiVersion: v1
kind: Service
metadata:
name: svc-mall-admin
spec:
ports:
- name: http
port: 8180
protocol: TCP
targetPort: 8180
selector:
app: svc-mall-admin
Copy the code
Then it can run directly, and it can run all the projects.
5. Test and verification
After that, you can go to the SkyWalking UI to check whether the link collection is successful.
1. Test the application API
First, request the API provided by the Spring Cloud application. Because we need to trace the link.
2. View the SkyWalking UI
Here, we see three concepts that are very important in SkyWalking:
-
Service: Represents a series or set of workloads that provide the same behavior for requests. When using Agent or SDK, you can define the name of the service. If not, SkyWalking will use the name you define on the platform (say Istio). Here, we can see that the Spring Cloud application’s service is svC-mall-admin, which we defined in the Agent environment variable Service_name.
-
Service Instance: Each workload in the set above is called an Instance. Just like the Pods in Kubernetes, a service instance is not necessarily a process on the operating system. But when you use an Agent, a service instance is actually a real process on the operating system. Here, we can see that the Spring Cloud application’s service is UUID@hostname, automatically generated by the Agent.
-
Endpoint: The request path received by a particular service, such as the HTTP URI path and the class name + method signature of the gRPC service.
Here, we can see one of the endpoints of the Spring Cloud application, the API interface /mall-admin/admin/login.
For more parameters about the Agent, see github.com/apache/skyw…
Click the Topology menu to enter the interface for viewing the topology:Click the “Trace” menu to enter the interface for viewing link data:
Six, the summary
This article details how to integrate SkyWalking using Kubernetes + Spring Cloud. By the way, downlink monitoring is an essential component of current microservices systems. Distributed tracking, service grid telemetry analysis, measurement aggregation and visualization are still useful. Here we chose Skywalking, for reasons we won’t go into detail here.
Source code:
- Github.com/zuozewei/bl…