赞
踩
需求:
解决:
简要步骤:
确认生产alpine版本为3.8:
在K8S上,通过k9s工具/K8S-dashboard/docker exec等命令登录目标容器,执行命令cat /etc/os-release
查看系统版本。
bash-4.4# hostname
file-tg-cfd48df98-fnzbv
bash-4.4# cat /etc/os-release
NAME="Alpine Linux"
ID=alpine
VERSION_ID=3.8.2
PRETTY_NAME="Alpine Linux v3.8"
HOME_URL="http://alpinelinux.org"
BUG_REPORT_URL="http://bugs.alpinelinux.org"
bash-4.4#
在本人电脑(或其它运行docker可以上网的服务器)上,搜索拉取镜像,运行容器
PS C:\Users\Czm> docker pull alpine:3.8
3.8: Pulling from library/alpine
486039affc0a: Pull complete
Digest: sha256:2bb501e6173d9d006e56de5bce2720eb06396803300fe1687b58a7ff32bf4c14
Status: Downloaded newer image for alpine:3.8
docker.io/library/alpine:3.8
PS C:\Users\Czm> docker run -itd --name al38 alpine:3.8 /bin/sh
1e4353774d57297b44c10dafd4b30335015aae80bcee342dcf929bdf3f0bba92
PS C:\Users\Czm> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1e4353774d57 alpine:3.8 "/bin/sh" 3 seconds ago Up 2 seconds al38
登录容器下载apk安装包:
PS C:\Users\Czm> docker exec -it al38 /bin/sh
更换alpine apk源为国内源:
# 清华大学源
sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories
# 阿里云源
sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
# 中科大源
sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories
创建存放apk的目录,下载curl及其依赖:
/ # mkdir curl
/ # cd curl/
/curl # apk fetch curl -R -o /curl
Downloading libssh2-1.9.0-r1
Downloading zlib-1.2.11-r1
Downloading musl-1.1.19-r11
Downloading libcurl-7.61.1-r3
Downloading busybox-1.28.4-r3
Downloading libressl2.7-libssl-2.7.5-r0
Downloading nghttp2-libs-1.39.2-r0
Downloading libressl2.7-libcrypto-2.7.5-r0
Downloading ca-certificates-20191127-r2
/curl # ls
busybox-1.28.4-r3.apk curl-7.61.1-r3.apk libressl2.7-libcrypto-2.7.5-r0.apk libssh2-1.9.0-r1.apk nghttp2-libs-1.39.2-r0.apk
ca-certificates-20191127-r2.apk libcurl-7.61.1-r3.apk libressl2.7-libssl-2.7.5-r0.apk musl-1.1.19-r11.apk zlib-1.2.11-r1.apk
/curl #
/curl # apk fetch busybox-extras -R -o /curl
Downloading busybox-extras-1.28.4-r3
打包所有apk文件为一个tar包,方便传输:
/ # tar -zcvf czm-231110-Alpine3.8-curl.telnet.tgz /curl/
退出容器命令行,返回Windows cmd,执行docker cp命令,复制tar包到Windows。
PS C:\Users\Czm> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1e4353774d57 alpine:3.8 "/bin/sh" 16 hours ago Up 16 hours al38
3127f7c3a2bd anapsix/alpine-java:8_server-jre_unlimited "/bin/bash" 7 weeks ago Up 17 hours tz
PS C:\Users\Czm> docker cp al38:/czm-231110-Alpine3.8-curl.telnet.tgz d:/czm-231110-Alpine3.8-curl.telnet.tgz
Successfully copied 2.78MB to d:\czm-231110-Alpine3.8-curl.telnet.tgz
PS C:\Users\Czm>
将tar包传输到K8S服务器
[sysma@prod-k8s-0001 ~]$ pwd
/home/sysma
[sysma@prod-k8s-0001 ~]$ ll |grep Alpine
-rw-r--r-- 1 sysma sysma 2781771 Nov 10 10:07 czm-231110-Alpine3.8-curl.telnet.tgz
[sysma@prod-k8s-0001 ~]$ ll |grep Al
-rwxr-xr-x 1 sysma sysma 365 Oct 31 09:28 07_getAllDeploy.sh
-rw-r--r-- 1 sysma sysma 2781771 Nov 10 10:07 czm-231110-Alpine3.8-curl.telnet.tgz
drwxr-xr-x 5 sysma sysma 326 Nov 3 09:30 czm_BathAlterDeployEnv
[sysma@prod-k8s-0001 ~]$ kubectl cp czm-231110-Alpine3.8-curl.telnet.tgz file-tg-cfd48df98-fnzbv:/ -c file-tg -n media
Error from server (NotFound): pods "file-tg-cfd48df98-fnzbv" not found
[sysma@prod-k8s-0001 ~]$ kubectl cp czm-231110-Alpine3.8-curl.telnet.tgz file-tg-9b658c46-xkd48:/ -c file-tg -n media
[sysma@prod-k8s-0001 ~]$
使用K9S工具登录容器
选择不是sider-car的容器
刚才kubectl 复制的文件已经到了容器内部。
解压,然后安装curl工具,貌似apk无法自动解决依赖问题,需要按如下顺序安装之前下载的apk安装包:
实际操作如下:
bash-4.4# ls
busybox-1.28.4-r3.apk libcurl-7.61.1-r3.apk mii-tool-1.60_git20140218-r2.apk zlib-1.2.11-r1.apk
busybox-extras-1.28.4-r3.apk libressl2.7-libcrypto-2.7.5-r0.apk musl-1.1.19-r11.apk
ca-certificates-20191127-r2.apk libressl2.7-libssl-2.7.5-r0.apk net-tools-1.60_git20140218-r2.apk
curl-7.61.1-r3.apk libssh2-1.9.0-r1.apk nghttp2-libs-1.39.2-r0.apk
bash-4.4# apk add --no-network nghttp2-libs-1.39.2-r0.apk
WARNING: Ignoring APKINDEX.adfa7ceb.tar.gz: No such file or directory
WARNING: Ignoring APKINDEX.efaa1f73.tar.gz: No such file or directory
(1/1) Installing nghttp2-libs (1.39.2-r0)
Executing glibc-bin-2.29-r0.trigger
OK: 24 MiB in 30 packages
bash-4.4# apk add --no-network libssh2-1.9.0-r1.apk
WARNING: Ignoring APKINDEX.adfa7ceb.tar.gz: No such file or directory
WARNING: Ignoring APKINDEX.efaa1f73.tar.gz: No such file or directory
(1/1) Installing libssh2 (1.9.0-r1)
Executing glibc-bin-2.29-r0.trigger
OK: 24 MiB in 31 packages
bash-4.4# apk add --no-network libcurl-7.61.1-r3.apk
WARNING: Ignoring APKINDEX.adfa7ceb.tar.gz: No such file or directory
WARNING: Ignoring APKINDEX.efaa1f73.tar.gz: No such file or directory
(1/1) Installing libcurl (7.61.1-r3)
Executing glibc-bin-2.29-r0.trigger
OK: 24 MiB in 32 packages
bash-4.4# apk add --no-network curl-7.61.1-r3.apk
WARNING: Ignoring APKINDEX.adfa7ceb.tar.gz: No such file or directory
WARNING: Ignoring APKINDEX.efaa1f73.tar.gz: No such file or directory
(1/1) Installing curl (7.61.1-r3)
Executing busybox-1.28.4-r3.trigger
OK: 24 MiB in 33 packages
bash-4.4#
从容器内部发送任意curl请求,成功。如图是post请求发送一个500MB文件到对端服务器
优点:pod不用重启,业务不用中断。
缺点:传输安装包复杂,需要提前准备相同版本alpine系统镜像。容器重启后curl、telnet工具丢失,还得重复再装一次。
就不详细写了,需要详细过程的留言。
简要步骤:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。