一般我们部署写4个文件就行了
首先分别写
- Dockerfile
- 1package.sh
- 2build.sh
- docker_push.sh
Dockerfile
# 基于jdk1.8
FROM openjdk:8-jdk-alpine
RUN echo "Asia/Shanghai" > /etc/timezone
RUN mkdir /app
WORKDIR /app
COPY ./monitor-flink-1.0.jar /app
EXPOSE 8080
CMD ["java","-jar","/app/monitor-flink-1.0.jar"]
springboot打包
<build>
<finalName>monitor-flink-1.0</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.5.14</version>
<configuration>
<mainClass>com.donglin.MonitorApplication</mainClass>
<!-- <skip>true</skip>-->
</configuration>
<executions>
<execution>
<id>repackage</id>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
1package.sh
从github上拉下来,打成jar包
#!/bin/bash
export JAVA_HOME=/data/xxx/jdk/jdk1.8.0_141
export PATH=${JAVA_HOME}:$PATH
cd /data/flink-monitor
rm -rf /data/flink-monitor/monitor-flink
export http_proxy=http://xxx.xxx.xxx.xxx:3128
export https_proxy=https://xxx.xxx.xxx.xxx:3128
git clone https://GitHub上生成的ssh密钥@github.com/lidonglin/flink-monitor.git
cd /data/flink-monitor/monitor-flink
git checkout main
sh /data/xxx/maven/maven-3.6.3/bin/mvn clean
sh /data/xxx/maven/maven-3.6.3/bin/mvn -P dev -Dmaven.test.skip=true package
mv /data/flink-monitor/monitor-flink/target/monitor-flink-1.0.jar /data/flink-monitor/monitor-flink-1.0.jar
2build.sh
#!/bin/bash
sudo docker build -t flink-monitor:latest
docker_push.sh
将docker镜像推送到k8s
#!/bin/bash
VERSION=latest
sudo docker login xxxxxx.com --username xxxxxx --password xxxxxx
sudo docker tag flink-monitor:$VERSION xxxx/xxxx/flink-monitor:$VERSION
sudo docker push xxxx/xxx/flink-monitor:$VERSION
export https_proxy=
export http_proxy=
kubectl rollout restart deployment flink-monitor --namespace=app
tips
# 把旧镜像的名字,改成仓库要求的新版名字
docker tag donglin:v1.0 donglin/nginx:v1.0
最后生成的文件