docker一键打包上传阿里云镜像仓库并发布k8s容器
docker镜像一键打包上传阿里云镜像仓库并发布k8s容器,脚本一键打包发布
·
阿里云镜像仓库说明:
将镜像推送到Registry
$ docker login --username=aliyun0398513152 rz-dt-image-server-registry.cn-shanghai.cr.aliyuncs.com
$ docker tag [ImageId] rz-dt-image-server-registry.cn-shanghai.cr.aliyuncs.com/rz-dt/k8s-springboot-demo:[镜像版本号]
$ docker push rz-dt-image-server-registry.cn-shanghai.cr.aliyuncs.com/rz-dt/k8s-springboot-demo:[镜像版本号]
自己实战操作如下:
第一步生成本地镜像:
docker build -t rz-dt-image-server-registry.cn-shanghai.cr.aliyuncs.com/rz-dt/k8s-springboot-demo:2022-12-01-17-34 .
第二步重命名本地镜像标签版本(docker images 查看镜像id0cd11ecdaf0f ):
docker tag 0cd11ecdaf0f rz-dt-image-server-registry.cn-shanghai.cr.aliyuncs.com/rz-dt/k8s-springboot-demo:2022-12-01-17-34
第三步上传阿里云镜像仓库:
docker push rz-dt-image-server-registry.cn-shanghai.cr.aliyuncs.com/rz-dt/k8s-springboot-demo:2022-12-01-17-34
第四步发布k8s
kubectl apply -f k8s-springboot-demo.yaml
一键打包和k8s发布 脚本build.sh内容如下:
一定使用vim 命令新建build.sh脚本,window和Linux编码不一致会报错。
echo "开始制作镜像..."
image_tag=`date +%Y%m%d-%H%M%S` #_%H%M
echo "当前时间:$image_tag"
docker build -t k8s-springboot-demo:${image_tag} .
echo "制作镜像成功!"
echo "登录"
sudo docker login --username=aliyun0398515 rz-dt-image-server-registry.cn-shanghai.cr.aliyuncs.com --password=1234
echo "镜像最新版本提交"
docker tag k8s-springboot-demo:${image_tag} rz-dt-image-server-registry.cn-shanghai.cr.aliyuncs.com/rz-dt/k8s-springboot-demo:${image_tag}
docker push rz-dt-image-server-registry.cn-shanghai.cr.aliyuncs.com/rz-dt/k8s-springboot-demo:${image_tag}
echo "k8s一键部署"
export IMG_TAG=${image_tag}
envsubst < k8s-springboot-demo.yaml | kubectl apply -f -
更多推荐
已为社区贡献23条内容
所有评论(0)