k8s springboot 文件_K8S 部署 SpringBoot 项目
首先准备 SpringBoot 测试镜像,略。模板文件准备一个模板文件 testspringboot-rc.yamlapiVersion: v1kind: ReplicationControllermetadata:name: testspringboot#必选,资源名称spec:# 节点数,设置为多个可以实现负载均衡效果replicas: 1selector:app: testspringb..
首先准备 SpringBoot 测试镜像,略。
模板文件
准备一个模板文件 testspringboot-rc.yaml
apiVersion: v1
kind: ReplicationController
metadata:
name: testspringboot #必选,资源名称
spec:
# 节点数,设置为多个可以实现负载均衡效果
replicas: 1
selector:
app: testspringboot
template:
metadata:
labels:
app: testspringboot
spec:
containers:
- name: demo
#镜像名
image: testspringboot
#本地有镜像就不会去仓库拉取
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8080
配置说明:
kind:资源类型,详情见附A
metadata: 元数据,用于备注资源信息
spec: specification of the resource content 指定该资源的内容
selector: 选择器,将选择具有label标签的资源作为管理范围
template: 资源模版定义
containerPort: 容器暴露给 K8S 的端口
部署到 K8S 集群
执行命令 kubectl create -f testspringboot-rc.yaml
或者在 Web UI (dashboard) 执行
暴露对外端口
创建 SVC 模板文件 testspringboot-svc.yaml
apiVersion: v1
kind: Service
metadata:
name: testsvc
spec:
type: NodePort
ports:
- port: 8080
targetPort: 8080
# 节点暴露给外部的端口(范围必须为30000-32767)
nodePort: 30001
selector:
app: testspringboot
创建 Service
kubectl create -f testspringboot-svc.yaml
访问测试
K8S 集群任意IP
附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
更多推荐
所有评论(0)