利用k8s部署Java项目
构建镜像
[root@master kubenetres]# docker build -f Dockerfile -t test3:1.0 .
Sending build context to Docker daemon 74.54MB
Step 1/3 : FROM openjdk:18-jdk-alpine3.15
---> dfg56hghg6h6
Step 2/3 : COPY halo-1.3.1.jar /usr/local/halo-1.3.1.jar
---> fdg5yokbhk03
Step 3/3 : ENTRYPOINT ["java","-jar","/usr/local/halo-1.3.1.jar"]
---> Running in 4h456f4h84g4
Removing intermediate container 4h456f4h84g4
---> 525hfh4fhe8h4
Successfully built 525hfh4fhe8h4
Successfully tagged test3:1.0
[root@master kubenetres]# docker tag test3:1.0 yunjisuanlp/javatest:v0.1
[root@master kubenetres]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
yunjisuanlp/javatest v0.1 15g54f6d6d7h 57 minutes ago 410MB
[root@master kubenetres]# cat test.yml
---
apiVersion: v1
kind: Pod
metadata:
name: test01
labels:
app: test01
spec:
containers:
- image: yunjisuanlp/javatest:v0.1
name: java
---
apiVersion: v1
kind: Service
metadata:
name: java
namespace: default
spec:
ports:
- port: 8090
protocol: TCP
targetPort: 8090
selector:
app: test01
type: NodePort
构建查看
[root@master kubenetres]# kubectl apply -f test.yml
pod/test01 created
service/java created
[root@master kubenetres]# kubectl get pod,svc
NAME READY STATUS RESTARTS AGE
pod/test01 0/1 ContainerCreating 0 23s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/java NodePort 10.22.84.22 <none> 8090:31880/TCP 25s
service/kubernetes ClusterIP 10.22.0.1 <none> 443/TCP 3d