首先準(zhǔn)備 SpringBoot 測試鏡像,略次和。
模板文件
準(zhǔn)備一個模板文件 testspringboot-rc.yaml
apiVersion: v1
kind: ReplicationController
metadata:
name: testspringboot #必選豌注,資源名稱
spec:
# 節(jié)點數(shù)兔仰,設(shè)置為多個可以實現(xiàn)負(fù)載均衡效果
replicas: 1
selector:
app: testspringboot
template:
metadata:
labels:
app: testspringboot
spec:
containers:
- name: demo
#鏡像名
image: testspringboot
#本地有鏡像就不會去倉庫拉取
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8080
配置說明:
kind:
資源類型领猾,詳情見附A
metadata:
元數(shù)據(jù),用于備注資源信息
spec:
specification of the resource content 指定該資源的內(nèi)容
selector:
選擇器陷嘴,將選擇具有l(wèi)abel標(biāo)簽的資源作為管理范圍
template:
資源模版定義
containerPort:
容器暴露給 K8S 的端口
部署到 K8S 集群
執(zhí)行命令 kubectl create -f testspringboot-rc.yaml
或者在 Web UI (dashboard) 執(zhí)行
暴露對外端口
- 創(chuàng)建 SVC 模板文件
testspringboot-svc.yaml
- 創(chuàng)建 SVC 模板文件
apiVersion: v1
kind: Service
metadata:
name: testsvc
spec:
type: NodePort
ports:
- port: 8080
targetPort: 8080
# 節(jié)點暴露給外部的端口(范圍必須為30000-32767)
nodePort: 30001
selector:
app: testspringboot
- 創(chuàng)建 Service
kubectl create -f testspringboot-svc.yaml
-
訪問測試
-
附A:資源類型
類別 | 名稱 |
---|---|
資源對象 | Pod映砖、ReplicaSet、ReplicationController灾挨、Deployment啊央、StatefulSet、DaemonSet涨醋、Job瓜饥、CronJob、HorizontalPodAutoscaling |
配置對象 | Node浴骂、Namespace乓土、Service、Secret溯警、ConfigMap趣苏、Ingress、Label梯轻、ThirdPartyResource食磕、 ServiceAccount |
存儲對象 | Volume、Persistent Volume |
策略對象 | SecurityContext喳挑、ResourceQuota彬伦、LimitRange |