您好,登錄后才能下訂單哦!
今天小編給大家分享一下springboot項目怎么部署到k8s上的相關知識點,內容詳細,邏輯清晰,相信大部分人都還太了解這方面的知識,所以分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后有所收獲,下面我們一起來了解一下吧。
springboot項目打包鏡像部署到鏡像倉庫
登錄私有鏡像倉庫,拉去鏡像
創建deployment
暴露服務訪問端口
登錄私有倉庫需要創建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
創建好之后,后續需要掛載到pod上
快速創建一個deployment,導出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.修改副本數量為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 服務端口 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,安全組需開放該端口才能訪問
到這里我們服務部署就算完成了,看一下所有的節點
~$ 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上”這篇文章的所有內容,感謝各位的閱讀!相信大家閱讀完這篇文章都有很大的收獲,小編每天都會為大家更新不同的知識,如果還想學習更多的知識,請關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。