Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e7e274241d | ||
|
|
60be5bda29 | ||
|
|
dad481d5f6 |
78
.deploy/deployment.yml
Normal file
78
.deploy/deployment.yml
Normal file
@@ -0,0 +1,78 @@
|
||||
## k8s默认是访问不了外部服务的,需要代理,以mysql和redis为例,代理myservice名称到192.168.0.100,配置文件中对应的ip修改为myservice
|
||||
#apiVersion: v1
|
||||
#kind: Endpoints
|
||||
#metadata:
|
||||
# name: myservice
|
||||
#subsets:
|
||||
# - addresses:
|
||||
# - ip: 192.168.0.100
|
||||
# ports:
|
||||
# - port: 6379
|
||||
# protocol: TCP
|
||||
# name: redis
|
||||
# - port: 3306
|
||||
# protocol: TCP
|
||||
# name: mysql
|
||||
#---
|
||||
#apiVersion: v1
|
||||
#kind: Service
|
||||
#metadata:
|
||||
# name: myservice
|
||||
#spec:
|
||||
# ports:
|
||||
# - port: 6379
|
||||
# targetPort: 6379
|
||||
# protocol: TCP
|
||||
# name: redis
|
||||
# - port: 3306
|
||||
# targetPort: 3306
|
||||
# protocol: TCP
|
||||
# name: mysql
|
||||
#
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: myk3s-test
|
||||
spec:
|
||||
replicas: 2
|
||||
revisionHistoryLimit: 3
|
||||
selector:
|
||||
matchLabels:
|
||||
app: myk3s-test
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: myk3s-test
|
||||
spec:
|
||||
containers:
|
||||
- image: ${env.REGISTRY}/${env.IMAGE_NAME}:${steps.datetime.outputs.datetime}
|
||||
name: myk3s-test
|
||||
imagePullPolicy: Always
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: /actuator/health
|
||||
port: 9090
|
||||
initialDelaySeconds: 1
|
||||
successThreshold: 5
|
||||
ports:
|
||||
- containerPort: 9090
|
||||
imagePullSecrets:
|
||||
- name: dockerhub-id
|
||||
|
||||
---
|
||||
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: myk3s-test
|
||||
spec:
|
||||
type: NodePort
|
||||
externalTrafficPolicy: Local
|
||||
ports:
|
||||
- name: http-8080
|
||||
protocol: TCP
|
||||
port: 9090
|
||||
nodePort: 30099
|
||||
selector:
|
||||
app: myk3s-test
|
||||
@@ -13,14 +13,15 @@ on:
|
||||
env:
|
||||
PATH: /opt/node/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||
REGISTRY: registry.cn-chengdu.aliyuncs.com
|
||||
IMAGE_NAMESPACE: bamanker
|
||||
IMAGE_NAME: myk3stest
|
||||
APP_NAME: myk3s-test
|
||||
IMAGE_NAME: bamanker/myk3stest
|
||||
CONTAINER_NAME: myk3stest
|
||||
|
||||
jobs:
|
||||
# 构建 Job
|
||||
build:
|
||||
runs-on: host
|
||||
outputs: # 声明作业的输出变量,方便在其他 Job 引用
|
||||
datetime: ${{ steps.datetime.outputs.datetime }}
|
||||
steps:
|
||||
# 下载仓库源码,依赖java环境,因此构建服务器本地需要下载安装java并设置环境变量
|
||||
- name: Checkout repository code
|
||||
@@ -37,20 +38,10 @@ jobs:
|
||||
# e.g. refs/tags/v1.0.0
|
||||
run: |
|
||||
echo "version=${GITHUB_REF/refs\/tags\/v}" >> $GITHUB_OUTPUT
|
||||
# - name: Check java version
|
||||
# run: java -version
|
||||
|
|
||||
echo "APP_TAG=${{ steps.get_version.outputs.version }}"
|
||||
- name: Set Env Var
|
||||
run: |
|
||||
cat ./deployment.yml && export APP_TAG="${{ steps.get_version.outputs.version }}"
|
||||
# export APP_TAG=$env.TAG
|
||||
# echo APP_TAG=${{ env.TAG }} |
|
||||
# export APP_NAME=${{ env.APP_NAME }} |
|
||||
# echo APP_NAME=${{ env.APP_NAME }} |
|
||||
- name: Inject Env Var
|
||||
run: |
|
||||
envsubst < ./deployment.yml
|
||||
- name: Check java version
|
||||
run: java -version
|
||||
- name: Show now path
|
||||
run: echo $(pwd);ls
|
||||
- name: Build with Maven
|
||||
# 设置Maven执行权限,使用maven绝对路径执行打包命令
|
||||
run: /usr/local/maven/bin/mvn clean package -DskipTests -Pprod
|
||||
@@ -80,24 +71,18 @@ jobs:
|
||||
platforms: linux/amd64
|
||||
file: Dockerfile
|
||||
push: true
|
||||
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAMESPPACE }}/${{ env.IMAGE_NAME }}:${{ env.TAG }}
|
||||
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.TAG }}
|
||||
|
||||
|
||||
- name: k8s Check and Apply New Deployment
|
||||
uses: http://139.9.216.111:3000/bamanker/steevchen-kubectl@master
|
||||
with:
|
||||
config: ${{ secrets.KUBE_CONFIG }}
|
||||
command: apply -f http://139.9.216.111:3000/bamanker/myk3sTest/raw/branch/master/.deploy/deployment.yml
|
||||
- name: k8s Check Pods Health
|
||||
uses: http://139.9.216.111:3000/bamanker/steevchen-kubectl@master
|
||||
with:
|
||||
config: ${{ secrets.KUBE_CONFIG }}
|
||||
command: get pod -n default -l app=${{ env.APP_NAME }}
|
||||
|
||||
- name: k8s Update Deployment
|
||||
uses: http://139.9.216.111:3000/bamanker/steevchen-kubectl@master
|
||||
env:
|
||||
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
|
||||
with:
|
||||
command: rollout restart deployment ${{ env.APP_NAME }}-${{ gitea.ref_name }}
|
||||
command: apply -f http://139.9.216.111:3000/bamanker/myk3sTest/src/branch/master/.deploy/deployment.yml
|
||||
# - name: k8s Update Deployment
|
||||
# uses: http://139.9.216.111:3000/bamanker/kubectl@master
|
||||
# env:
|
||||
# KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
|
||||
# with:
|
||||
# args: rollout restart deployment ${{ env.CONTAINER_NAME }}-${{ gitea.ref_name }}
|
||||
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
labels:
|
||||
app: $APP_NAME
|
||||
version: $APP_TAG
|
||||
name: $APP_NAME
|
||||
namespace: default
|
||||
spec:
|
||||
progressDeadlineSeconds: 600
|
||||
replicas: 1
|
||||
revisionHistoryLimit: 2
|
||||
selector:
|
||||
matchLabels:
|
||||
app: $APP_NAME
|
||||
strategy:
|
||||
rollingUpdate:
|
||||
maxSurge: 50%
|
||||
maxUnavailable: 50%
|
||||
type: RollingUpdate
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: $APP_NAME
|
||||
version: $APP_TAG
|
||||
spec:
|
||||
containers:
|
||||
- image: $REGISTRY/$IMAGE_NAMESPACE/$IMAGE_NAME:$APP_TAG
|
||||
name: $APP_NAME
|
||||
imagePullPolicy: Always
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: /actuator/health
|
||||
port: 9090
|
||||
initialDelaySeconds: 1
|
||||
timeoutSeconds: 10
|
||||
failureThreshold: 30
|
||||
successThreshold: 5
|
||||
ports:
|
||||
- containerPort: 9090
|
||||
imagePullSecrets:
|
||||
- name: dockerhub-id
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
labels:
|
||||
app: $APP_NAME
|
||||
name: $APP_NAME
|
||||
namespace: default
|
||||
spec:
|
||||
type: NodePort
|
||||
externalTrafficPolicy: Local
|
||||
ports:
|
||||
- name: http
|
||||
protocol: TCP
|
||||
port: 9090
|
||||
nodePort: 9090
|
||||
selector:
|
||||
app: $APP_NAME
|
||||
30
pom.xml
30
pom.xml
@@ -8,10 +8,9 @@
|
||||
<version>4.0.1</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
<groupId>com.bamanker</groupId>
|
||||
<artifactId>myk3sTest</artifactId>
|
||||
<version>v1.1.9</version>
|
||||
<version>0.0.1</version>
|
||||
<name>myk3sTest</name>
|
||||
<description>myk3sTest</description>
|
||||
<url/>
|
||||
@@ -29,13 +28,11 @@
|
||||
</scm>
|
||||
<properties>
|
||||
<java.version>25</java.version>
|
||||
<app.version>${version}</app.version>
|
||||
<app.name>${artifactId}</app.name>
|
||||
|
||||
<maven.compiler.source>25</maven.compiler.source>
|
||||
<maven.compiler.target>25</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
@@ -62,27 +59,7 @@
|
||||
|
||||
<build>
|
||||
<finalName>myk3sTest</finalName>
|
||||
<!--指定filtering=true.maven的占位符解析表达式就可以用于它里面的文件-->
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<!--支持yaml读取pom的参数-->
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>3.2.0</version>
|
||||
<configuration>
|
||||
<encoding>UTF-8</encoding>
|
||||
<delimiters>
|
||||
<delimiter>@</delimiter>
|
||||
</delimiters>
|
||||
<useDefaultDelimiters>false</useDefaultDelimiters>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
@@ -100,11 +77,13 @@
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
</configuration>
|
||||
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
|
||||
<excludes>
|
||||
<exclude>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
@@ -115,4 +94,5 @@
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
|
||||
Reference in New Issue
Block a user