How to use Skywalking Agent?

Keywords: Java Apache glibc Nginx

How to use Skywalking Agent?

If you don't know what Skywalking agent is, Please click here to see Probe perhaps Here's a quick look at agent Since most of my services are JAVA services, here are three ways to choose from using agent in Java

Three ways:

  • Using the Officially Provided Basic Mirror
  • Building agent packages into existing base images
  • sidecar mode mount agent
1. Use the Officially Provided Basic Mirror

Check out the official docker hub base image You just need to build the service image from From, which is more convenient to integrate directly into Jenkins.

2. Build agent packages into existing base images

The reason for this is that the official image is a streamlined image, and it's openjdk. Maybe many commands don't exist, so you need to install it again. Here's how I built it.

  • Download oracle jdk

    Now oracle is a little sick, wget can't do all kinds of things, and then I give up and go straight from Official website Downloaded

  • Download skywalking Official distribution package And decompression (take 6.3.0 as an example)

    wget https://www.apache.org/dyn/closer.cgi/skywalking/6.3.0/apache-skywalking-apm-6.3.0.tar.gz && tar -zxvf apache-skywalking-apm-6.3.0.tar.gz
  • Build the underlying image with the following dockerfile

    FROM alpine:3.8 
    
    ENV LANG=C.UTF-8
    
    RUN set -eux && \
        apk update && apk upgrade && \
        wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub &&\
            wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.30-r0/glibc-2.30-r0.apk &&\
            apk --no-cache add unzip vim curl git bash ca-certificates glibc-2.30-r0.apk file && \
        rm -rf /var/lib/apk/* &&\
            mkdir -p /usr/skywalking/agent/
    
    # A streamlined jre
    ADD jdk1.8.0_221/ /usr/java/jdk1.8.0_221/
    ADD apache-skywalking-apm-bin/agent/ /usr/skywalking/agent/
    
    # set env
    ENV JAVA_HOME /usr/java/jdk1.8.0_221
    ENV PATH ${PATH}:${JAVA_HOME}/bin
    
    # run container with base path:/
    WORKDIR /
    
    CMD bash

Because alpine is based on mini lib, but java needs glibc, so glibc-related things are added. Finally, the size of the image is about 490M. It should be a little big for adding a lot of commands. For reference only, the same image can also be directly configurated to jenkins.

3.sidecar mode mount agent

If your service is deployed in Kubernetes, you can also use Skywalking Agent in this way. The advantage of this way is that it does not need to modify the original basic image, nor rebuild the new service image, but uses sidecar mode to share the relevant text needed by the agent by sharing volume. Components are mounted into existing service images

Method of Constructing skywalking agent sidecar Mirror

  • Download skywalking Official distribution package And decompress

    wget https://www.apache.org/dyn/closer.cgi/skywalking/6.3.0/apache-skywalking-apm-6.3.0.tar.gz && tar -zxvf apache-skywalking-apm-6.3.0.tar.gz
  • Build with the following dockerfile

    FROM busybox:latest 
    
    ENV LANG=C.UTF-8
    
    RUN set -eux && mkdir -p /usr/skywalking/agent/
    
    ADD apache-skywalking-apm-bin/agent/ /usr/skywalking/agent/
    
    WORKDIR /

Note: I didn't download the skywalking distribution package in dockerfile here because it guaranteed that the built sidecar image was kept to a minimum, bosybox was only about 700 k, and the final size of the agent was less than 20M.

How to use sidecar?

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    name: demo-sw
  name: demo-sw
spec:
  replicas: 1
  selector:
    matchLabels:
      name: demo-sw
  template:
    metadata:
      labels:
        name: demo-sw
    spec:
      initContainers:
      - image: registry-hz.rubikstack.com/library/sidecar-sw:latest
        name: sw-agent-sidecar
        imagePullPolicy: IfNotPresent
        command: ['sh']
        args: ['-c','mkdir -p /skywalking/agent && cp -r /usr/skywalking/agent/* /skywalking/agent']
        volumeMounts:
        - mountPath: /skywalking/agent
          name: sw-agent
      containers:
      - image: nginx:1.7.9
        name: nginx
        volumeMounts:
        - mountPath: /usr/skywalking/agent
          name: sw-agent
        ports:
        - containerPort: 80
      volumes:
      - name: sw-agent
        emptyDir: {}

The above is the deployment.yaml file of sidecar. Taking nginx as a service for example, agent is mounted mainly by sharing volume. Firstly, initContainers mounts / skywalking/agent in sw-agent-sidecar through sw-agent volume, and the agent directory cp in the mirror built above is added to sky/sky/sidecar. Walking / agent directory, after the completion of nginx start-up also mounted sw-agent volume, and mounted it to the container's / usr/skywalking/agent directory, thus completing the sharing process.

summary

In addition to ServiceMesh, the way I can think of is introduced. I hope it can help you. Finally Skywalking a Star bar The pride of the Chinese people.

Posted by tpstudent on Thu, 29 Aug 2019 21:19:07 -0700