k8s发布hello.jar(springboot ) 20250511
1、hello.jar 本地运行 (springboot )
2、 hello.jar 生成镜像Image
docker build -t hello-jar .
3、 k8s-master镜像 hello-jar:latest 推送到私库harbor的springboot项目
注:私库harbor 192.168.177.128:8001
3.1
docker tag hello-jar:latest 192.168.177.128:8001/springboot/hello-jar:latest
#######镜像hello-jar:latest
#######私库192.168.177.128:8001/springboot/ 镜像位置
3.2
docker push 192.168.177.128:8001/springboot/hello-jar:latest
3.3
3.4 节点拉取docker pull 192.168.177.128:8001/springboot/hello-jar:latest
注:可以验证一下私库harbor的地址是否可用
4、k8s deployment发布
4.1
boot-deploy-hello.yaml
#deploy
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello
spec:
selector:
matchLabels:
app: hello
replicas: 1
strategy: {}
template:
metadata:
labels:
app: hello
spec:
containers:
- name: hello-jar
image: 192.168.177.128:8001/springboot/hello-jar:latest # 镜像地址harbor
ports:
- containerPort: 8080 # 容器端口
---
#service
apiVersion: v1
kind: Service
metadata:
name: hello
spec:
ports:
- port: 8080
protocol: TCP
targetPort: 8080
nodePort: 30080 # 指定NodePort端口,范围30000-32767
selector:
app: hello
type: NodePort
4.2
kubectl apply -f boot-deploy-hello.yaml
4.3 curl localhost:30080/hello
4.4 k8s-master-->http://192.168.177.129:30080/