您好,登錄后才能下訂單哦!
這篇文章給大家分享的是有關(guān)k8s如何部署java項(xiàng)目的內(nèi)容。小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過(guò)來(lái)看看吧。
下載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 ~]#
編寫(xiě)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倉(cāng)庫(kù)
[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 ~]#
編寫(xiě)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]#
創(chuàng)建
[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
使用本機(jī)IP:32767訪問(wèn)
感謝各位的閱讀!關(guān)于“k8s如何部署java項(xiàng)目”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。