一般我们部署写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文章来源:https://www.toymoban.com/news/detail-791275.html
# 把旧镜像的名字,改成仓库要求的新版名字
docker tag donglin:v1.0 donglin/nginx:v1.0
最后生成的文件
文章来源地址https://www.toymoban.com/news/detail-791275.html
到了这里,关于使用脚本把springboot程序部署到k8s上的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!