一文讲解如何获取k8s容器里运行的jar包

Kande ·
更新时间:2024-11-10
· 1119 次阅读

目录

01 引言

02 从镜像信息获取

03 进入容器获取(推荐)

04 文末

01 引言

k8s上运行了第三方的应用,很多时候我们都想知道运行流程,一般都会从k8s容器中获取jar包。

那么该如何把里面的jar包提取出来呢?

其实有两种方式,分别为:

① 从镜像信息获取;

② 进入容器获取

02 从镜像信息获取

主要参考了:https://www.jb51.net/article/264058.htm

首先,查看镜像:

docker image ls |grep 你想要找到镜像名

查看镜像内容:

docker inspect 镜像ID

内容大概如下:

[ { "Id": "sha256:bd95813096bd754b657fb7e531e3b86075ccf4388df5b452a819919ff00c91c2", "RepoTags": [ "vvp-gateway:2.6.3_simon" ], "RepoDigests": [], "Parent": "sha256:59250f7815884db8ace5b956946370e8924ac74ad12acb922eb4431ad477418c", "Comment": "", "Created": "2022-07-11T07:12:46.084025129Z", "Container": "cfca40ed3f7bb18674c6a2fcf0f78267517de6268c6d6bfddfc8c380fb33818d", "ContainerConfig": { "Hostname": "cfca40ed3f7b", "Domainname": "", "User": "root", "AttachStdin": false, "AttachStdout": false, "AttachStderr": false, "ExposedPorts": { "8080/tcp": {} }, "Tty": false, "OpenStdin": false, "StdinOnce": false, "Env": [ "PATH=/usr/local/openjdk-11/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", "JAVA_HOME=/usr/local/openjdk-11", "LANG=C.UTF-8", "JAVA_VERSION=11.0.15" ], "Cmd": [ "/bin/sh", "-c", "#(nop) ", "CMD [\"java\" \"-Xdebug\" \"-agentlib:jdwp=transport=dt_socket,server=y,address=0.0.0.0:8899,suspend=n\" \"-XX:MaxRAMPercentage=50.0\" \"-XX:MaxMetaspaceSize=256m\" \"-Djava.security.egd=file:/dev/./urandom\" \"-cp\" \"/vvp/app:/vvp/app/lib/*\" \"com.ververica.platform.gateway.GatewayApplication\"]" ], "Image": "sha256:59250f7815884db8ace5b956946370e8924ac74ad12acb922eb4431ad477418c", "Volumes": { "/vvp/data": {}, "/vvp/etc": {}, "/vvp/secrets": {} }, "WorkingDir": "", "Entrypoint": null, "OnBuild": null, "Labels": { "maintainer": "Ververica <platform@ververica.com>" } }, "DockerVersion": "20.10.5", "Author": "", "Config": { "Hostname": "", "Domainname": "", "User": "root", "AttachStdin": false, "AttachStdout": false, "AttachStderr": false, "ExposedPorts": { "8080/tcp": {} }, "Tty": false, "OpenStdin": false, "StdinOnce": false, "Env": [ "PATH=/usr/local/openjdk-11/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", "JAVA_HOME=/usr/local/openjdk-11", "LANG=C.UTF-8", "JAVA_VERSION=11.0.15" ], "Cmd": [ "java", "-Xdebug", "-agentlib:jdwp=transport=dt_socket,server=y,address=0.0.0.0:8899,suspend=n", "-XX:MaxRAMPercentage=50.0", "-XX:MaxMetaspaceSize=256m", "-Djava.security.egd=file:/dev/./urandom", "-cp", "/vvp/app:/vvp/app/lib/*", "com.ververica.platform.gateway.GatewayApplication" ], "Image": "sha256:59250f7815884db8ace5b956946370e8924ac74ad12acb922eb4431ad477418c", "Volumes": { "/vvp/data": {}, "/vvp/etc": {}, "/vvp/secrets": {} }, "WorkingDir": "", "Entrypoint": null, "OnBuild": null, "Labels": { "maintainer": "Ververica <platform@ververica.com>" } }, "Architecture": "amd64", "Os": "linux", "Size": 919299037, "VirtualSize": 919299037, "GraphDriver": { "Data": { "LowerDir": "/var/lib/docker/overlay2/cc946e03217e4171399be855e56505bb037276d062c2829beea93d77f43cfaf6/diff:/var/lib/docker/overlay2/6b0a352106f128579123a45e3991b9f2492994d435180b3ca630b022f7cde088/diff:/var/lib/docker/overlay2/29ccfa6c76844dc9f104eabbf2c0e4db32a040ebfa3691078f9e751ea5a7d891/diff:/var/lib/docker/overlay2/d3eda21c53fad143abc5981dfccfac0ed33f5a2e71d3a78d9ca22ea3a6243c89/diff:/var/lib/docker/overlay2/6f336ec260b8060e77e268412246b8ecbf8a3ccbe025422dacf341337228793e/diff:/var/lib/docker/overlay2/d73a8b39b5bb63ba313669bab84d6a15378bd327944e4a43519fb8080b6e2fab/diff:/var/lib/docker/overlay2/568f3a48847e451e5482ffa75b65eff42d46b6eabe20371529379dcc79d528fb/diff:/var/lib/docker/overlay2/85feabbee50004762db71400d79ee1213b6bd580a949f628c765f3c29f7b5dd3/diff:/var/lib/docker/overlay2/76336ac57ecea887d8e5743c5897618a6398a609f9936ae7be811a2c45aad847/diff:/var/lib/docker/overlay2/db8d96c0e03b7632ee96077360103a053b88a04c95323ea6b8d612ecc918b78e/diff:/var/lib/docker/overlay2/41c62e7cf81c95bc8b77e6ce2677ded8448722b1fdb72ff9db395db7537fce8c/diff:/var/lib/docker/overlay2/35b917ac3d4b14291f8459e2ca01da3d016750b0586d7d1e412034340fe0f686/diff:/var/lib/docker/overlay2/769a1d6b4fd308283f55d7dea89c0bf375997560f85115a167b7528d26c3f256/diff:/var/lib/docker/overlay2/d8d20b6d384247cc05a7e1c1c4b0011f580ff0f01b0c1a0506420d7497dae89c/diff", "MergedDir": "/var/lib/docker/overlay2/8a1defde1405c4ad9ee22830f3dac0bab42a492cbb55109364f3e968db3eab30/merged", "UpperDir": "/var/lib/docker/overlay2/8a1defde1405c4ad9ee22830f3dac0bab42a492cbb55109364f3e968db3eab30/diff", "WorkDir": "/var/lib/docker/overlay2/8a1defde1405c4ad9ee22830f3dac0bab42a492cbb55109364f3e968db3eab30/work" }, "Name": "overlay2" }, "RootFS": { "Type": "layers", "Layers": [ "sha256:9c1b6dd6c1e6be9fdd2b1987783824670d3b0dd7ae8ad6f57dc3cea5739ac71e", "sha256:13a34b6fff7804cf7f6e8f52a4cf25ceb2e32fc35a6f39e8158074c64831ebf0", "sha256:8da60230c8c21a305a0b1871ea654b3a68ace50520397bd46b8b647c6e0891c4", "sha256:f93bb772c4958617a803266969a338094cb73511c18605d87f53b1b2cfadc7b0", "sha256:af70cff76a6274cc87e5a2f1c6c1fc6554524adf407fa94e387292d91b808d39", "sha256:4503e1661bd9fe4381f37dd8c9960ef4301f387c88e6d1582922cccd0544d03e", "sha256:690041a64b809a889f8e5e2ec9eda4300fbf76dfd488b8ee334eea3ced9ac7a3", "sha256:f346876b3ef523394c2d0473501a50392d1df530daf0bd70d351830c782ccba3", "sha256:620e3c5d227e2b96f1205ead77b84be11b239adf387d7b7e83c6cd4a508431aa", "sha256:9b33a349b1c75a9040b5a8e277c0e0a535a87ba6fa87861268280f9862f8803d", "sha256:6f55434bbaa3b9d42d629ce6ac1c0eba4214b835cdb7b3c5c74deae69a5c5436", "sha256:8a9739c65869fd51708ba2ab262469b6b6d54f9576a924c89a852c26e8125c7b", "sha256:cfe58338cf6bc3ed59ab76b731315e9d47ab96e8b8f4c84a501ce709e18930e0", "sha256:57e0cc2daa9243c201289f7c677c40e1f45bc2f17023795ef7a8ef45f147d796", "sha256:095b3833d28e6e3049512b7c588025cdb34fbf08c0de67cbd8e818714ab5b4c5" ] }, "Metadata": { "LastTagTime": "2022-07-11T15:12:46.143347824+08:00" } } ]

从内容中,可以看到打包镜像的流程,其中Cmd的标签,可以看出使用java来执行程序,依赖库及执行程序入口如下:

一般jar包在UpperDir:

进入对应的路径:

cd /var/lib/docker/overlay2/8a1defde1405c4ad9ee22830f3dac0bab42a492cbb55109364f3e968db3eab30/diff

可以看到里面有对应的文件及jar包,如果还没有,只能进入容器查看了。

03 进入容器获取(推荐)

进入容器命令:

kubectl exec -it pod名称 -n命名空间 bash

注意到了以上的提示,默认进入“appmanager”容器,实际我们希望进入的容器是gateway,所以需要指定容器进入:

kubectl exec -it pod名称 -n命名空间 -c容器名 bash

看看里面有什么内容:

进入目录:

可以看到此目录已经含有所有程序运行时需要的内容了。

04 文末

文本主要讲解了使用两种方式去获取容器中运行的jar包

到此这篇关于如何获取k8s容器里运行的jar包的文章就介绍到这了,更多相关获取k8s容器的jar包内容请搜索软件开发网以前的文章或继续浏览下面的相关文章希望大家以后多多支持软件开发网!



jar包 jar 运行 k8s

需要 登录 后方可回复, 如果你还没有账号请 注册新账号
相关文章
Noya 2021-01-29
844