学海无涯
go,go,go

k8s部署java项目-tomcat的基础镜像和harbor准备(二)

#在LB01节点上安装docker
#上传k8s-node.tar.gz的安装包
#解压
tar zxvf k8s-node.tar.gz
tar zxvf docker-18.09.6.tgz

#把docker命令移动到/usr/bin下面做为执行命令
mv /tools/docker/* /usr/bin
mkdir /etc/docker -p
#修改仓库地址
cat >/etc/docker/daemon.json<<'EOF'
{
"registry-mirrors": ["https://x4h14tji.mirror.aliyuncs.com","https://registry.docker-cn.com"],
"insecure-registries": ["192.168.2.194"]
}
EOF
mv docker.service /usr/lib/systemd/system
systemctl start docker
systemctl enable docker
systemctl restart docker.service

#上传安装包harbor-offline-installer-v1.6.1.tgz
#解压安装包
tar xf harbor-offline-installer-v1.6.1.tgz


#安装docker-compose
mv docker-compose /bin/docker-compose
chmod +x /bin/docker-compose

#配置harbor的地址
hostname = 192.168.2.194

#生成域配置的环境
./prepare

#install安装harbor
./install.sh

#启动harbo
cd /tools/harbor/
docker-compose up -d

#在harbor创建镜像仓库
账号:admin
密码:Harbor12345
仓库名称:project
#每个node节点添加可信任
cat >/etc/docker/daemon.json<<'EOF'
{
"registry-mirrors": ["https://x4h14tji.mirror.aliyuncs.com","https://registry.docker-cn.com"],
"insecure-registries": ["192.168.2.194"]
}
EOF

#所有node节点重启docker
systemctl restart docker

#做演示用的github地址:https://github.com/lizhenliang/,下载zip安装包进行上传
unzip tomcat-java-demo-master.zip


#上传安装包
apache-maven-3.5.0-bin.tar.gz
jdk-8u45-linux-x64.tar.gz

#安装apache-maven-3.5.0-
tar -xf apache-maven-3.5.0-bin.tar.gz
tar -xf jdk-8u45-linux-x64.tar.gz
mv apache-maven-3.5.0 /usr/local/maven
mv jdk1.8.0_45/ /usr/local/jdk

#配置环境变量
cat >>/etc/profile<<'EOF'
JAVA_HOME=/usr/local/jdk
PATH=$PATH:$JAVA_HOME/bin
export JAVA_HOME PATH
EOF
source /etc/profile

#检查
[root@k8s-lb01 tools]# java -version
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)


#进入项目目录对java的源码进行编译
cd /tools/tomcat-java-demo-master/
#对java代码进行构建
[root@k8s-lb01 tomcat-java-demo-master]# /usr/local/maven/bin/mvn clean package
ownloading: https://repo.maven.apache.org/maven2/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.pom
Downloaded: https://repo.maven.apache.org/maven2/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.pom (13 kB at 6.6 kB/s)
Downloading: https://repo.maven.apache.org/maven2/ch/qos/logback/logback-parent/1.2.3/logback-parent-1.2.3.pom
Downloaded: https://repo.maven.apache.org/maven2/ch/qos/logback/logback-parent/1.2.3/logback-parent-1.2.3.pom (18 kB at 11 kB/s)
Downloading: https://repo.maven.apache.org/maven2/ch/qos/logback/logback-core/1.2.3/logback-core-1.2.3.pom
Downloaded: https://repo.maven.apache.org/maven2/ch/qos/logback/logback-core/1.2.3/logback-core-1.2.3.pom (4.2 kB at 3.9 kB/s)
Downloading: https://repo.maven.apache.org/maven2/org/slf4j/slf4j-api/1.7.25/slf4j-api-1.7.25.pom
[INFO] Packaging webapp
[INFO] Assembling webapp [ly-simple-tomcat] in [/tools/tomcat-java-demo-master/target/ly-simple-tomcat-0.0.1-SNAPSHOT]
[INFO] Processing war project
[INFO] Webapp assembled in [321 msecs]
[INFO] Building war: /tools/tomcat-java-demo-master/target/ly-simple-tomcat-0.0.1-SNAPSHOT.war
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 10:38 min
[INFO] Finished at: 2019-11-12T16:58:26+08:00
[INFO] Final Memory: 33M/193M
[INFO] ------------------------------------------------------------------------

#java代码构建完成
[root@k8s-lb01 tomcat-java-demo-master]# ls target/ly-simple-tomcat-0.0.1-SNAPSHOT.war 
target/ly-simple-tomcat-0.0.1-SNAPSHOT.war


#执行dockerfile构建镜像
[root@k8s-lb01 tomcat-java-demo-master]# cat Dockerfile 
FROM lizhenliang/tomcat   使用的基础镜像
LABEL at1358@qq.com
RUN rm -rf /usr/local/tomcat/webapps/*   删除基础镜像默认的代码
ADD target/*.war /usr/local/tomcat/webapps/ROOT.war   上传编译好的代码

#执行dockerfile构建镜像
docker build -t 192.168.2.194/project/java-demo:v1 .
[root@k8s-lb01 tomcat-java-demo-master]# docker build -t 192.168.2.194/project/java-demo:v1 .
Sending build context to Docker daemon  44.08MB
Step 1/4 : FROM lizhenliang/tomcat
latest: Pulling from lizhenliang/tomcat
a02a4930cb5d: Pull complete 
12ac6c660ca4: Pull complete 
675ab56ce773: Pull complete 
Digest: sha256:3bd83236a4b6cf4152d0384981ce9ed55063bc5fd5259d206bfdfdb877651db0
Status: Downloaded newer image for lizhenliang/tomcat:latest
 ---> 143035d83fdc
Step 2/4 : LABEL maintainer www.ctnrs.com
 ---> Running in 4ef0b04b52fc
Removing intermediate container 4ef0b04b52fc
 ---> be3342dc7e6b
Step 3/4 : RUN rm -rf /usr/local/tomcat/webapps/*
 ---> Running in e0bc62f3d868
Removing intermediate container e0bc62f3d868
 ---> d4927dcb20eb
Step 4/4 : ADD target/*.war /usr/local/tomcat/webapps/ROOT.war
 ---> 229df453c0e2
Successfully built 229df453c0e2
Successfully tagged 192.168.2.195/project/java-demo:v1

#登陆harbor
[root@k8s-lb01 tomcat-java-demo-master]# docker login 192.168.2.194
Username: admin
Password: Harbor12345
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded

#打包成功的镜像
[root@k8s-lb01 tomcat-java-demo-master]# docker images
REPOSITORY                        TAG                 IMAGE ID            CREATED             SIZE
192.168.2.195/project/java-demo   v1                  229df453c0e2        12 minutes ago      406MB

#上传镜像
[root@k8s-lb01 tomcat-java-demo-master]# docker push 192.168.2.194/project/java-demo:v1
The push refers to repository [192.168.2.195/project/java-demo]
9aac44be7870: Pushed 
de69e25c3616: Pushed 
ceead5ca823f: Pushed 
2353c173a26a: Pushed 
071d8bd76517: Pushed 
v1: digest: sha256:7b170a6d3590c4290bc46d364b0e9fe6be5578e432817191bdbb033ac30bb8c3 size: 1371
赞(0) 打赏
未经允许不得转载:YYQ运维技术博客_运维的工作学习之路 » k8s部署java项目-tomcat的基础镜像和harbor准备(二)
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

运维devops

联系我们关于本博客

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏