k8s部署java项目的实现
程序员文章站
2022-03-06 13:20:20
下载jar的包[root@master test]# wget https://dl.halo.run/release/halo-1.4.16.jar[root@master ~]# lsanacon...
下载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 . sending 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 template: 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-date 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 <none> 8090:32767/tcp 32s service/kubernetes clusterip 10.96.0.1 <none> 443/tcp 46h
使用本机ip:32767访问
到此这篇关于k8s部署java项目的实现的文章就介绍到这了,更多相关k8s部署java项目内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!
上一篇: 微信小程序虚拟列表的应用实例