您好,登錄后才能下訂單哦!
今天小編給大家分享一下springboot項目怎么部署到k8s上的相關(guān)知識點,內(nèi)容詳細,邏輯清晰,相信大部分人都還太了解這方面的知識,所以分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后有所收獲,下面我們一起來了解一下吧。
springboot項目打包鏡像部署到鏡像倉庫
登錄私有鏡像倉庫,拉去鏡像
創(chuàng)建deployment
暴露服務(wù)訪問端口
登錄私有倉庫需要創(chuàng)建secret,存儲docker registry的認證信息
~$ kubectl create secret docker-registry fdf-docker-secret --docker-server=registry.cn-chengdu.aliyuncs.com --docker-username=17602117026 --docker-password=用戶密碼 secret/fdf-docker-secret created ~$ ~$ ~$ kubectl get secret NAME TYPE DATA AGE fdf-docker-secret kubernetes.io/dockerconfigjson 1 15s
創(chuàng)建好之后,后續(xù)需要掛載到pod上
快速創(chuàng)建一個deployment,導(dǎo)出yaml文件
~$ kubectl create deployment k8sdemo --image=registry.cn-chengdu.aliyuncs.com/fandf/k8s-test:1.0.0 --dry-run=client -o yaml > k8sdemo.yaml ~$ cat k8sdemo.yaml apiVersion: apps/v1 kind: Deployment metadata: creationTimestamp: null labels: app: k8sdemo name: k8sdemo spec: replicas: 1 selector: matchLabels: app: k8sdemo strategy: {} template: metadata: creationTimestamp: null labels: app: k8sdemo spec: containers: - image: registry.cn-chengdu.aliyuncs.com/fandf/k8s-test:1.0.0 name: k8s-test resources: {} status: {} ~$
修改k8sdemo.yaml文件
#1.修改副本數(shù)量為2 #2.掛在secret apiVersion: apps/v1 kind: Deployment metadata: creationTimestamp: null labels: app: k8sdemo name: k8sdemo spec: replicas: 2 selector: matchLabels: app: k8sdemo strategy: {} template: metadata: creationTimestamp: null labels: app: k8sdemo spec: imagePullSecrets: - name: fdf-docker-secret containers: - image: registry.cn-chengdu.aliyuncs.com/fandf/k8s-test:1.0.0 name: k8s-test resources: {} status: {}
~$ kubectl apply -f k8sdemo.yaml deployment.apps/k8sdemo created ~$ kubectl get deploy NAME READY UP-TO-DATE AVAILABLE AGE k8sdemo 0/2 2 0 12s ~$ kubectl get deploy NAME READY UP-TO-DATE AVAILABLE AGE k8sdemo 2/2 2 2 24s ~$ kubectl get pod NAME READY STATUS RESTARTS AGE k8sdemo-65d45fb49f-l4kx5 1/1 Running 0 28s k8sdemo-65d45fb49f-pqsjw 1/1 Running 0 28s
#port 服務(wù)端口 target-port pod端口 ~$ kubectl expose deploy k8sdemo --port=9001 --target-port=9001 --type=NodePort service/k8sdemo exposed ~$ ~$ kubectl get svc k8sdemo NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE k8sdemo NodePort 10.96.10.79 <none> 9001:31921/TCP 12s ~$ curl http://127.0.0.1:31921/api/v1/user/name zhangsan
可以看到serviced的ip為10.96.10.79 對外端口為 31921,安全組需開放該端口才能訪問
到這里我們服務(wù)部署就算完成了,看一下所有的節(jié)點
~$ kubectl get secret,pod,svc,deploy NAME TYPE DATA AGE secret/fdf-docker-secret kubernetes.io/dockerconfigjson 1 52m NAME READY STATUS RESTARTS AGE pod/k8sdemo-65d45fb49f-l4kx5 1/1 Running 0 39m pod/k8sdemo-65d45fb49f-pqsjw 1/1 Running 0 39m NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/k8sdemo NodePort 10.96.10.79 <none> 9001:31921/TCP 5m51s service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 301d NAME READY UP-TO-DATE AVAILABLE AGE deployment.apps/k8sdemo 2/2 2 2 39m ~$
以上就是“springboot項目怎么部署到k8s上”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家閱讀完這篇文章都有很大的收獲,小編每天都會為大家更新不同的知識,如果還想學(xué)習(xí)更多的知識,請關(guān)注億速云行業(yè)資訊頻道。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。