您好,登錄后才能下訂單哦!
這篇文章給大家分享的是有關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 . 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項目”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,讓大家可以學到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。