K8s编排部署java应用

K8s编排部署java应用

创建Dockerfile文件并提前下载jar包

[root@master kubenetres]# ls
Dockerfile  halo-1.3.1.jar 
[root@master kubenetres]# vim Dockerfile 
[root@master kubenetres]# cat Dockerfile 
FROM openjdk:18-jdk-alpine3.15

COPY halo-1.3.1.jar /usr/local/halo-1.3.1.jar 

ENTRYPOINT ["java","-jar","/usr/local/halo-1.3.1.jar"]

制作镜像

[root@master kubenetres]# docker build -f Dockerfile -t test3:1.0 .
Sending build context to Docker daemon  75.21MB
Step 1/3 : FROM openjdk:18-jdk-alpine3.15
 ---> c89120dcca4c
Step 2/3 : COPY halo-1.3.1.jar /usr/local/halo-1.3.1.jar
 ---> adcaca1f84da
Step 3/3 : ENTRYPOINT ["java","-jar","/usr/local/halo-1.3.1.jar"]
 ---> Running in 735e9129e585
Removing intermediate container 735e9129e585
 ---> 77fc7bd4fe43
Successfully built 77fc7bd4fe43
Successfully tagged test3:1.0

#更改镜像名称
[root@master kubenetres]# docker tag test3:1.0 1225514226/javatest:v0.1

[root@master kubenetres]# docker images
REPOSITORY                                                        TAG                 IMAGE ID       CREATED          SIZE
1225514226/javatest                                                 v0.1                77fc7bd4fe43   52 minutes ago   404MB

Deployment,Service的yaml文件

[root@master kubenetres]# vim test.yml 
[root@master kubenetres]# cat test.yml 
---
apiVersion: v1
kind: Pod
metadata:
  name: test01
  labels:
    app: test01
spec:
  containers:
  - image: 1225514226/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.107.92.77    <none>        8090:31839/TCP   23s
service/kubernetes   ClusterIP   10.96.0.1       <none>        443/TCP          6d
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值