根据节点具体的PID如何定位到指定的容器,三种方法
- 笨方法,根据进程PID定位,如节点运行了很多的java进程,在部署设计时没有什么区别及环境变量,很难区分进程对应的容器
- 列出具体应用的进程,如下
<root@SIT-K8S-WN7 ~># ps -ef | grep java nflow 1272 1245 9 11:26 ? 00:01:33 java -jar -javaagent:/home/nflow/servers/jvmAgent/jmx_prometheus_javaagent-0.15.0.jar=8888:/home/nflow/servers/jvmAgent/config.yml -d64 -server -XX:+UseContainerSupport -XX:MaxRAMPercentage=80.0 -XX:InitialRAMPercentage=80.0 -XX:MinRAMPercentage=80.0 -Duser.timezone=GMT+08 -XX:MetaspaceSize=512m -XX:MaxMetaspaceSize=512M -Djava.security.egd=file:/dev/./urandom /home/nflow/servers/app.jar nflow 3504 3469 0 Apr01 ? 04:11:43 java -jar -d64 -server -XX:+UseContainerSupport -XX:MaxRAMPercentage=80.0 -XX:InitialRAMPercentage=80.0 -XX:MinRAMPercentage=80.0 -Duser.timezone=GMT+08 -XX:MetaspaceSize=512m -XX:MaxMetaspaceSize=512M -Djava.security.egd=file:/dev/./urandom /home/nflow/servers/app.jar --spring.profiles.active=sit02 nflow 5865 5846 0 Jul28 ? 03:24:03 java -jar -javaagent:/home/nflow/servers/jvmAgent/jmx_prometheus_javaagent-0.15.0.jar=8888:/home/nflow/servers/jvmAgent/config.yml -d64 -server -XX:+UseContainerSupport -XX:MaxRAMPercentage=80.0 -XX:InitialRAMPercentage=80.0 -XX:MinRAMPercentage=80.0 -Duser.timezone=GMT+08 -XX:MetaspaceSize=512m -XX:MaxMetaspaceSize=512M -Djava.security.egd=file:/dev/./urandom /home/nflow/servers/app.jar nflow 8457 8428 0 Aug16 ? 00:10:03 /usr/local/java/bin/java -Djava.util.logging.config.file=/home/nflow/servers/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0022 -javaagent:/home/nflow/servers/jvmAgent/jmx_prometheus_javaagent-0.15.0.jar=8888:/home/nflow/servers/jvmAgent/config.yml -d64 -server -XX:+UseContainerSupport -XX:MaxRAMPercentage=80.0 -XX:InitialRAMPercentage=80.0 -XX:MinRAMPercentage=80.0 -Duser.timezone=GMT+08 -XX:MetaspaceSize=512m -XX:MaxMetaspaceSize=512M -Djava.security.egd=file:/dev/./urandom -Dignore.endorsed.dirs= -classpath /home/nflow/servers/tomcat/bin/bootstrap.jar:/home/nflow/servers/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/home/nflow/servers/tomcat -Dcatalina.home=/home/nflow/servers/tomcat -Djava.io.tmpdir=/home/nflow/servers/tomcat/temp org.apache.catalina.startup.Bootstrap start nflow 10338 10100 0 Apr01 ? 09:28:40 java -jar -d64 -server -XX:+UseContainerSupport -XX:MaxRAMPercentage=80.0 -XX:InitialRAMPercentage=80.0 -XX:MinRAMPercentage=80.0 -Duser.timezone=GMT+08 -XX:MetaspaceSize=512m -XX:MaxMetaspaceSize=512M -Djava.security.egd=file:/dev/./urandom /home/nflow/servers/app.jar --spring.profiles.active=sit02 nflow 12192 12173 1 Jun30 ? 20:52:01 java -jar -javaagent:/home/nflow/servers/jvmAgent/jmx_prometheus_javaagent-0.15.0.jar=8888:/home/nflow/servers/jvmAgent/config.yml -d64 -server -XX:+UseContainerSupport -XX:MaxRAMPercentage=80.0 -XX:InitialRAMPercentage=80.0 -XX:MinRAMPercentage=80.0 -Duser.timezone=GMT+08 -XX:MetaspaceSize=512m -XX:MaxMetaspaceSize=512M -Djava.security.egd=file:/dev/./urandom /home/nflow/servers/app.jar --spring.profiles.active=sit03
- 根据子PID定位父PID
<root@SIT-K8S-WN7 ~># ps -ef | grep 3504 nflow 3504 3469 0 Apr01 ? 04:11:44 java -jar -d64 -server -XX:+UseContainerSupport -XX:MaxRAMPercentage=80.0 -XX:InitialRAMPercentage=80.0 -XX:MinRAMPercentage=80.0 -Duser.timezone=GMT+08 -XX:MetaspaceSize=512m -XX:MaxMetaspaceSize=512M -Djava.security.egd=file:/dev/./urandom /home/nflow/servers/app.jar --spring.profiles.active=sit02 root 27273 7708 0 11:47 pts/0 00:00:00 grep --color=auto 3504 <root@SIT-K8S-WN7 ~># ps -ef | grep 3469 nflow 3469 3443 0 Apr01 ? 00:00:00 /bin/bash /home/nflow/scripts/start.sh nflow 3504 3469 0 Apr01 ? 04:11:44 java -jar -d64 -server -XX:+UseContainerSupport -XX:MaxRAMPercentage=80.0 -XX:InitialRAMPercentage=80.0 -XX:MinRAMPercentage=80.0 -Duser.timezone=GMT+08 -XX:MetaspaceSize=512m -XX:MaxMetaspaceSize=512M -Djava.security.egd=file:/dev/./urandom /home/nflow/servers/app.jar --spring.profiles.active=sit02
- 逐层追踪
<root@SIT-K8S-WN7 ~># ps -ef | grep 3443 root 3443 1858 0 Apr01 ? 00:29:24 containerd-shim -namespace moby -workdir /var/lib/containerd/io.containerd.runtime.v1.linux/moby/06be66e1babe13bd58d3b7aa462aae055d5b90595378a9eca684de5b0571109c -address /run/containerd/containerd.sock -containerd-binary /usr/bin/containerd -runtime-root /var/run/docker/runtime-runc nflow 3469 3443 0 Apr01 ? 00:00:00 /bin/bash /home/nflow/scripts/start.sh
- 第3步已经追踪到具体的container_id,06be66e1babe13bd58d3b7aa462aae055d5b90595378a9eca684de5b0571109c
- 定位