k8s cluster container integrated arthas, netstat immediate diagnostic analysis tools

Background:
K8S cluster, java application container to add real-time diagnostic tool to analyze arthas, netstat

1. The pre-download good arthas-packaging-3.1.1-bin.zip documents in the Dockerfile same directory and rename arthas.zip
wget http://repo1.maven.org/maven2/com/taobao/arthas/ arthas-packaging / 3.1.1 / arthas-packaging-3.1.1-bin.zip

mv arthas-packaging-3.1.1-bin.zip arthas.zip

2.netstat tool in alpine is ospd-netstat, in Dockerfile can be added directly apk add

3. The following is Dokcerfile file (Note: the need openjdk, jre if it is, it will lack dt.jar, tools.jar arthas tool to use; you need to install tools tini, because the default java application running in the container will be No. 1 pid , arthas will not call)
the FROM openjdk: the JDK-8-Alpine
COPY Repositories / etc / APK /
RUN APK --no the Add-Cache Mesa-GL \
ttf-freefont \
OSPD-netstat \
curl \
of TiNi \
JQ \
ttf-dejavu \
tzdata && \
mkdir -p / usr / local / Arthas && \
RM -rf / var / Cache / APK / *

Set Environment Variables

ENV TZ=Asia/Shanghai

Set the time zone

RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
COPY simhei.ttf /usr/share/fonts/
COPY simkaigb2312.ttf /usr/share/fonts/
COPY simsun.ttc /usr/share/fonts/simsun.ttc
COPY arthas.zip /tmp/
ADD ./health.sh /
RUN unzip /tmp/arthas.zip -d /usr/local/arthas && \
rm -rf /tmp/arthas.zip

4. The mirror package, and pushed to the private warehouse
Docker Build -t 192.168.3.10:5001/library/javabase:v8.0.22.
Docker Push 192.168.3.10:5001/library/javabase:v8.0.22

5. Summary of issues:
If tini facility is not installed, and at startup, performed in advance
ENTRYPOINT [ "/ sbin / tini" , "-"], the implementation CMD [ "sh", "- c", "java -Xms1500m -Xmx1500M -XX: + UnlockExperimentalVMOptions -XX: + UseCGroupMemoryLimitForHeap -jar /usr/local/factoring_web/xxxx.jar "]
or will be given as follows:

[ERROR] Start arthas failed, exception stack trace:
com.sun.tools.attach.AttachNotSupportedException: Unable to get pid of LinuxThreads manager thread
at sun.tools.attach.LinuxVirtualMachine.<init>(LinuxVirtualMachine.java:86)
at sun.tools.attach.LinuxAttachProvider.attachVirtualMachine(LinuxAttachProvider.java:78)
at com.sun.tools.attach.VirtualMachine.attach(VirtualMachine.java:250)
at com.taobao.arthas.core.Arthas.attachAgent(Arthas.java:75)
at com.taobao.arthas.core.Arthas.<init>(Arthas.java:28)
at com.taobao.arthas.core.Arthas.main(Arthas.java:113)
[INFO] Attach process 1 success.
[INFO] arthas-client connect 127.0.0.1 3658
Connect to telnet server error: 127.0.0.1 3658
java.net.ConnectException: Connection refused (Connection refused)
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at org.apache.commons.net.SocketClient.connect(SocketClient.java:188)
at org.apache.commons.net.SocketClient.connect(SocketClient.java:209)
at com.taobao.arthas.client.TelnetConsole.main(TelnetConsole.java:268)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.taobao.arthas.boot.Bootstrap.main(Bootstrap.java:503)

正常执行成功:
/usr/local/arthas # java -jar arthas-boot.jar
Picked up JAVA_TOOL_OPTIONS: -javaagent:/home/admin/.opt/ArmsAgent/arms-bootstrap-1.7.0-SNAPSHOT.jar -Darms.licenseKey=fqkkah9ke2@1f6f53b91f6e3fd -Darms.appName=test-factoring-web -Darms.agent.env=ACSK8S -Darms.agent.args=
2019-08-06 17:28:47 WARN JDK version=1.8.0_212
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
2019-08-06 17:28:50 WARN arms agent start cost: 3755ms
[INFO] arthas-boot version: 3.1.1
[INFO] Found existing java process, please choose one and hit RETURN.

  • [1]: 6 /usr/local/factoring_web/app.jar
    1
    [INFO] arthas home: /usr/local/arthas
    [INFO] Try to attach process 6
    Picked up JAVA_TOOL_OPTIONS: -javaagent:/home/admin/.opt/ArmsAgent/arms-bootstrap-1.7.0-SNAPSHOT.jar -Darms.licenseKey=fqkkah9ke2@1f6f53b91f6e3fd -Darms.appName=test-factoring-web -Darms.agent.env=ACSK8S -Darms.agent.args=
    2019-08-06 17:31:17 WARN JDK version=1.8.0_212
    SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
    SLF4J: Defaulting to no-operation (NOP) logger implementation
    SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
    2019-08-06 17:31:20 WARN arms agent start cost: 3623ms
    [INFO] Attach process 6 success.
    [INFO] arthas-client connect 127.0.0.1 3658
    ,---. ,------. ,--------.,--. ,--. ,---. ,---.
    / O \ | .--. ''--. .--'| '--' | / O \ ' .-'
    | .-. || '--'.' | | | .--. || .-. |.-.
    | | | || |\ \ | | | | | || | | |.-' |
    --'--'--' '--'--' --'--'--'--'`-----'

wiki https://alibaba.github.io/arthas
tutorials https://alibaba.github.io/arthas/arthas-tutorials
version 3.1.1
pid 6
time 2019-08-06 17:31:21

$ exit
/usr/local/arthas # netstat -tlnp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:3658 0.0.0.0: LISTEN 6/java
tcp 0 0 0.0.0.0:80 0.0.0.0:
LISTEN 6/java
tcp 0 0 127.0.0.1:8563 0.0.0.0:* LISTEN 6/java

Example 6. Construction jenkins, mirror package to the base

cat >./target/Dockerfile <<EOF
FROM 192.168.3.10:5001/library/javabase:v8.0.22
RUN \
mkdir -p /usr/local/ocr
ADD ./app.jar /usr/local/ocr/
WORKDIR /usr/local
EXPOSE 80

ENTRYPOINT ["/sbin/tini", "--"]
CMD ["sh","-c","java -Xms3000m -Xmx3000m -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -jar /usr/local/ocr/app.jar"]
EOF

ssh [email protected] "/bin/bash /usr/jenkins_home/deploy_history/scf-test/deploy.sh test ocr && \
/usr/bin/kubectl apply -f /usr/jenkins_home/deploy_history/scf-test/test-ocr.yaml && \
exit"

Reference links:
https://alibaba.github.io/arthas/docker.html
https://github.com/alibaba/arthas/issues/734
https://pkgs.alpinelinux.org/packages?name=openjdk8&branch=edge

Guess you like

Origin blog.51cto.com/daisywei/2427434