使用脚本把springboot程序部署到k8s上

一般我们部署写4个文件就行了

首先分别写

Dockerfile

java 复制代码
# 基于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打包

java 复制代码
    <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包

java 复制代码
#!/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

java 复制代码
#!/bin/bash
sudo docker build -t flink-monitor:latest

docker_push.sh

将docker镜像推送到k8s

java 复制代码
#!/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

csharp 复制代码
# 把旧镜像的名字,改成仓库要求的新版名字
docker tag donglin:v1.0 donglin/nginx:v1.0

最后生成的文件

相关推荐
张忠琳5 分钟前
【NVIDIA】 NVIDIA Container Toolkit v1.19.1 — OCI 模块超深度分析之三
云原生·容器·架构·kubernetes·nvidia
ttwuai1 小时前
Cursor 生成 CRUD 后,Go 后台接口别只测 200:JWT、RBAC 和 tenant_id 怎么验
开发语言·后端·golang
用户8356290780511 小时前
Python 实现 Excel 页面布局与打印设置自动化
后端·python
用户9931441579841 小时前
微服务框架中获取用户信息
后端
xuanWb1 小时前
手写一个 LLM API 网关:Anthropic 与 OpenAI 协议转换的完整实现
后端
苍何1 小时前
给 Codex 换皮肤这门生意,被我开源了
后端
用户8356290780511 小时前
Python 实现 Excel 命名范围(Named Range)的创建与管理
后端·python
程序员David2 小时前
我让 Claude 从架构文档一路干到代码,踩了三个坑才摸清边界
后端
Zane19942 小时前
并发 vs 并行:别再傻傻分不清了,一文讲透 Java 并发编程的第一课
java·后端