请先关注 [低调大师] 公众号 优秀的自媒体个人博客,低调大师,许军

低调大师

您现在的位置是:首页>文章详情

文章详情

容器服务kubernetes(ACK)基础镜像制作记录

2019-10-09 33热度

1.概述

容器服务云上环境与弹内差别较大,很多弹内支持默认埋点的 agent 在云上没法使用,同时需要预先部署一些云上环境需要的 agent, 因而云上的基础镜像跟弹内差异较大,需要从centos基础镜像开始配置环境。
容器镜像服务在云上,当云效部署时,需要从镜像服务拉取基础镜像建立镜像,因而需要将基础镜像 push 到镜像服务仓库中。
为了方便镜像 push 到镜像仓库,因而采用一个跳板机制作镜像,并上传到镜像仓库的方式来加快镜像制作和上传。
最终执行环境:

  • 本地办公电脑执行打包脚本命令;
  • 跳板机打包镜像;
  • 跳板机镜像上传到镜像仓库。

2. 镜像制作:

主要步骤有:

  1. 跳板机环境安装 Docker;
  2. 上传镜像中需要的第三方包和基础软件安装包上传到跳板机,比如 jdk, agent等;
  3. 编写本地执行脚本,执行镜像打包,并 push 镜像到仓库;

## 2.1 镜像打包跳板机环境配置:
安装 docker:

1、检查内核版本,必须是3.10及以上 uname -r 注:如果版本低于3.10,使用 yum update 升级 2、安装docker yum install docker 3、输入y确认安装 4、启动docker [root@localhost ~]# systemctl start docker [root@localhost ~]# docker -v Docker version 1.12.6, build 3e8e77d/1.12.6 5、开机启动docker [root@localhost ~]# systemctl enable docker Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service. 6、停止docker systemctl stop docker

2.2 上传安装依赖包:

上传 jdk, Agent 等应用依赖的第三方包:

#!/bin/bash env=$1 if [ ! -n "${env}" ]; then echo "Usage: ./upload.sh env " echo "env is resource upload or erase enviroment name:daily or online" exit 1 fi ## 设置跳板机登录证书和账号等 if [ ${env} == "online" ]; then echo "upload wukong resource to online jump machine." source "../ssh-production.sh" else echo "upload wukong resource to daily jump machine." source "../ssh-testing.sh" fi ## 删除原有资源目录 echo "remove file on jump machine ssh -i ${JUMP_CERT} -t ${JUMP_USER}@${JUMP_MACHINE} 'rm -rf /home/admin/resources/; mkdir /home/admin/resources/;'" ## ssh -i ${JUMP_CERT} -t ${JUMP_USER}@${JUMP_MACHINE} "rm -rf /home/admin/resources; mkdir /home/admin/resources/;" ## 上传依赖软件 echo "scp packag/home/admin/resources/target to jump machine ${JUMP_MACHINE}" scp -i ${JUMP_CERT} -r ./jdk/ ${JUMP_USER}@${JUMP_MACHINE}:/home/admin/resources scp -i ${JUMP_CERT} -r ./sunfire/ ${JUMP_USER}@${JUMP_MACHINE}:/home/admin/resources ${JUMP_USER}@${JUMP_MACHINE}:/home/admin/resources scp -i ${JUMP_CERT} ./tengine-yun-1.0.2-1652752.el7u2.x86_64.rpm ${JUMP_USER}@${JUMP_MACHINE}:/home/admin/resources scp -i ${JUMP_CERT} ./taobao-tomcat-7.0.59.3.tar.gz ${JUMP_USER}@${JUMP_MACHINE}:/home/admin/resources scp -i ${JUMP_CERT} ./start.sh ${JUMP_USER}@${JUMP_MACHINE}:/home/admin/resources scp -i ${JUMP_CERT} ./shutdown.sh ${JUMP_USER}@${JUMP_MACHINE}:/home/admin/resources echo "upload success."

2.3 编写执行脚本:

本地办公环境通过 ssh 执行打包命令:

#!/bin/bash APP_NAME=my-pandora-boot-base NAMESPACE=app-base REPO=${APP_NAME} VERSION=$1 source "../../../../ssh-production.sh" if [ ! -n "${VERSION}" ]; then echo "Usage: ./build.sh version " echo "version is docker image version" exit 1 fi cd ../../../ cd APP-META/docker-config/ echo "复制需要包含的 jdk,sunfire,key,i18n等 on jump machine ${JUMP_USER}@${JUMP_MACHINE}" ssh -i ${JUMP_CERT} -t ${JUMP_USER}@${JUMP_MACHINE} "mkdir -p /home/admin/${APP_NAME}/dev-base/; \ cp /home/admin/resources/taobao-hsf.tgz /home/admin/${APP_NAME}/dev-base; \ cp /home/admin/resources/sunfire/crontabs-1.11.rpm /home/admin/${APP_NAME}/dev-base; \ cp /home/admin/resources/sunfire/cronie-1.4.11.rpm /home/admin/${APP_NAME}/dev-base; \ cp /home/admin/resources/sunfire/start-sunfire.sh /home/admin/${APP_NAME}/dev-base; \ cp /home/admin/resources/sunfire/tsar-2.1.33-1568425.82ced85.el7.x86_64.rpm /home/admin/${APP_NAME}/dev-base; \ cp /home/admin/resources/sunfire/sunfire-agent-1.0.10-20190916175607.noarch.rpm /home/admin/${APP_NAME}/dev-base; \ cp /home/admin/resources/jdk/ajdk-8_3_6-b129-8.3.6-1207912.alios7.x86_64.rpm /home/admin/${APP_NAME}/dev-base " echo "scp package scp -i ${JUMP_CERT} -r ./dev-base/ ${JUMP_USER}@${JUMP_MACHINE} " scp -i ${JUMP_CERT} -r ./dev-base/ ${JUMP_USER}@${JUMP_MACHINE}:/home/admin/${APP_NAME}/ scp -i ${JUMP_CERT} -r ./environment/ ${JUMP_USER}@${JUMP_MACHINE}:/home/admin/${APP_NAME}/ echo "exec : docker build on ${JUMP_USER}@${JUMP_MACHINE} --build-arg APP_NAME=${APP_NAME} --build-arg APPID=${APPID} --pull -f Dockerfile_base -t registry-vpc.cn-north-2-gov-1.aliyuncs.com/${NAMESPACE}/${REPO}:${VERSION} ." ssh -i ${JUMP_CERT} -t ${JUMP_USER}@${JUMP_MACHINE} "cd /home/admin/${APP_NAME}/;sudo docker build --build-arg APPNAME=${APP_NAME} --build-arg --pull -f ./dev-base/Dockerfile_base -t registry-vpc.cn-north-2-gov-1.aliyuncs.com/${NAMESPACE}/${REPO}:${VERSION} ." echo "exec : docker push registry-vpc.cn-north-2-gov-1.aliyuncs.com/${NAMESPACE}/${REPO}:${VERSION}" ssh -i ${JUMP_CERT} -t ${JUMP_USER}@${JUMP_MACHINE} "cd /home/admin/${APP_NAME}/;sudo docker push registry-vpc.cn-north-2-gov-1.aliyuncs.com/${NAMESPACE}/${REPO}:${VERSION}" echo "docker push done" 

2.4 dockerfile 编写:

# 基于centos 基础镜像 FROM centos:7.4.1708 LABEL name="pandoraBoot Base Image" \ vendor="alibaba" \ build-date="20181201" ENV LANG=en_US.UTF-8 \ JAVA_HOME=/opt/taobao/java \ TZ=PRC # 安装工具软件,建立目录等 RUN adduser admin && \ mkdir -p /home/admin/lightapi/ && \ yum install -y telnet && \ yum install -y less && \ mkdir -p /home/admin/logs/ && \ mkdir -p /home/admin/logs/$BUILD_APP_NAME && \ yum install -y sudo && \ yum install -y unzip && \ yum install -y which && \ yum install -y iproute iproute-doc # 增加中间件新提供的 pandora 包 taobao-hsf.sar COPY dev-base/taobao-hsf.tgz /home/admin/taobao-hsf.tgz COPY dev-base/ajdk-8_3_6-b129-8.3.6-1207912.alios7.x86_64.rpm /home/admin/ajdk-8_3_6-b129-8.3.6-1207912.alios7.x86_64.rpm COPY dev-base/sunfire-agent-1.0.10-20190916175607.noarch.rpm /home/admin/sunfire-agent-1.0.10-20190916175607.noarch.rpm COPY dev-base/tsar-2.1.33-1568425.82ced85.el7.x86_64.rpm /home/admin/tsar-2.1.33-1568425.82ced85.el7.x86_64.rpm COPY dev-base/cronie-1.4.11.rpm /home/admin/cronie-1.4.11.rpm COPY dev-base/crontabs-1.11.rpm /home/admin/crontabs-1.11.rpm # 解压安装 RUN rpm -ivh "/home/admin/ajdk-8_3_6-b129-8.3.6-1207912.alios7.x86_64.rpm" && \ ln -s /opt/taobao/install/ajdk-8_3_6-b129 /opt/taobao/java #测试环境 setenv.sh COPY dev-base/start-sunfire.sh /home/admin/start-sunfire.sh # 拷贝执行程序的 shell 文件 COPY environment/common/bin/ /home/admin/appconf/bin/ COPY dev-base/init /home/admin/ COPY dev-base/init.sh /home/admin/ # 增加国际化资源 COPY dev-base/srvcode_i18nResourcesFile /home/admin/logs/mcms/i18n/i18nResourcesFile # 安装sunfire监控agent USER root RUN rpm -ivh /home/admin/tsar-2.1.33-1568425.82ced85.el7.x86_64.rpm && \ rpm -ivh --nodeps /home/admin/cronie-1.4.11.rpm && \ rpm -ivh --nodeps /home/admin/crontabs-1.11.rpm && \ rpm -ivh /home/admin/sunfire-agent-1.0.10-20190916175607.noarch.rpm && \ echo "source '/home/admin/start-sunfire.sh' " >> /home/admin/start.sh && \ chmod -R a+x /home/admin/appconf/bin/ && \ chmod +x /home/admin/*.sh WORKDIR /home/admin/appconf/bin ENTRYPOINT ["/home/admin/start.sh" ] 
收藏 (0)

相关文章

    文章评论

    共有0条评论来说两句吧...