k8s部署java项目的实现

网友投稿 321 2022-09-06


k8s部署java项目的实现

下载jar的包

[root@master test]# wget https://dl.halo.run/release/halo-1.4.16.jar

[root@master ~]# ls

anaconda-ks.cfg flannel.yml halo-1.4.16.jar init

[root@master ~]#

编写dockerfile并制作镜像

[root@master ~]# mkdir -p test/files

[root@master ~]# mv halo-1.4.16.jar test/files/

[root@master ~]# cd test/

[root@master test]# touch Dockerfile

[root@master test]# ls

Dockerfile files

[root@master test]#

[root@master test]# cat Dockerfile

FROM centos

COPY files/halo-1.4.16.jar /usr/local/halo-1.4.16.jar

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

[root@master test]#

[root@master test]# docker build -t 3199560936/halo:v1 .

SendingqGNat build context to Docker daemon 79.63MB

Step 1/3 : FROM centos

---> 5d0da3dc9764

Step 2/3 : COPY files/halo-1.4.16.jar /usr/local/halo-1.4.16.jar

---> 099645e57a21

Step 3/3 : ENTRYPOINT ["java","-jar","/usr/local/halo-1.4.16.jar"]

---> Running in d1e44734578c

Removing intermediate container d1e44734578c

---> a38d07129607

Successfully built a38d07129607

Successfully tagged 3199560936/halo:v1

[root@master test]# docker images

REPOSITORY TAG IMAGE ID CREATED SIZE

3199560936/halo v1 a38d07129607 3 seconds ago 311MB

[root@master test]#

上传镜像到docker仓库

[root@master ~]# docker login

[root@master ~]# docker push 3199560936/halo:v1

The push refers to repository [docker.io/3199560936/halo]

5906a49ee250: Pushed

74ddd0ec08fa: Mounted from library/centos

v1: digest: sha256:fb8cb538526b4d73e1a16b9b1b8a3e4ab4b171f0dbaadfbf6673def9620367f2 size: 741

[root@master ~]#

编写k8s的资源清单

[root@master test]# cat halo.yml

apiVersion: apps/v1

kind: Deployment

metadata:

name: halo

labels:

app: halo

spec:

replicas: 1

selector:

matchLabels:

app: halo

templhttp://ate:

metadata:

name: halo

labels:

app: halo

spec:

containers:

- image: 3199560936/halo:v1

imagePullPolicy: IfNotPresent

name: halo

---

apiVersion: v1

kind: Service

metadata:

name: halo

spec:

ports:

- port: 8090

targetPort: 8090

nodePort: 32767

selector:

app: halo

type: NodePort

[root@master test]#

创建

[root@master test]# kubectl apply -f halo.yml

deployment.apps/halo created

service/halo created

查看

[root@master test]# kubectl get deploy,pod,svc

NAME READY UP-TO-DATqGNatE AVAILABLE AGE

deployment.apps/halo 1/1 1 1 32s

NAME READY STATUS RESTARTS AGE

pod/halo-6d4cb5dc7b-nzdpw 1/1 Running 0 32s

NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE

service/halo NodePort 10.106.13.87 8090:32767/TCP 32s

service/kubernetes ClusterIP 10.96.0.1 443/TCP 46h

使用本机IP:32767访问


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Python基础篇:常见常用且要常记得的数据类型--列表(python中常见的数据类型)
下一篇:Python认知篇:常见数据类型--字符串+元组(python元组是什么数据类型)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~