赞
踩
问题的前提是这样的,我们修改了平台某一个模块的代码,想直接将修改放到docker镜像中,以便我们的k8s环境可以直接使用这个镜像来启动容器;
步 骤:① 将需要修改的镜像先运行起来,我们的这个镜像会依赖平台的其他配置,无法单独运行,可以这样仅仅把容器运行起来,不启动里面的服务;
docker run -d --name needModifyImage nbiot.com/needModifyImage:1.0.0 /bin/bash -c "tail -f /dev/null"
② 将需要修改的文件或者jar包,复制到已经运行起来的needModifyImage容器中(直接替换掉需要修改的文件或者jar);
docker cp needModifyImage_20210120.jar needModifyImage:/opt/nbiot/config/jar/
(切记,在将jar包copy到容器后,注意修改jar文件的操作权限,以防在运行的时候,无read权限出现报错,chmod +x needModifyImage_20210120.jar)
③ 将修改后的needModifyImage容器,做成快照,保存到本地目录;
docker export needModifyImage > needModifyImage_20200120.tar
④ 将快照(needModifyImage_20200120.tar)恢复成指定名字的新的镜像;(在哪台服务器运行此命令,就会在该服务器上生成镜像)
cat needModifyImage_20200120.tar |docker import - nbiot.com/needModifyImage:2.0.0
⑤ 将启动k8s - pod 的配置helm chart中的镜像版本修改成新的nbiot.com/needModifyImage:2.0.0,并启动;
helm install -n myServiceName myServiceName/
⑥ 查看启动的pod信息;
kubectl describe pod myServiceName
⑦ 发现启动报错
Warning Failed 8s (x2 over 9s) kubelet, worknode2 Error: Error response from daemon: No command specified
若无执行命令,则会报上面的错误,因为我们是在pod启动的服务,没办法像docker那样直接再启动的命令行里添加可执行的指令,只能像下面的做法,将需 要执行的命令,添加在yaml文件中;
- spec:
- securityContext:
- runAsNonRoot: true
- runAsUser: 10555
- fsGroup: 10555
- containers:
- - name: server
- image: xxxxxx-xxxxxx:xxxx
- command: ["java", "-XX:MaxRAM=1825361100", "-XX:MaxRAMFraction=1", "-Djava.security.egd=file:///dev/./urandom", "-Dlog4j2.configurationFile=/staging/jars/log4j_server.xml", "-DCONFIGDIR=/appl/config", "-Dname=ServerId", "-jar", "/staging/jars/server.jar"]
- imagePullPolicy: Always
command: ["java","-XX:MaxRAM=1825361100", "-XX:MaxRAMFraction=1", "-Djava.security.egd=file:///dev/./urandom", "-Dlogback.configurationFile=/staging/jars/log4j_server.xml", "-DCONFIGDIR=/appl/config", "-Dname=SerId", "-jar", "/opt/nbiot/config/jar/needModifyImage_20210120.jar"]
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。