apiVersion: apps/v1
kind: Deployment
metadata:
name: tomcat-deployment # 部署的名称
spec:
replicas: 3 # 副本数量,可以根据需求进行调整
selector:
matchLabels:
app: tomcat-app # 用于选择要管理的Pod的标签
template:
metadata:
labels:
app: tomcat-app # Pod的标签
spec:
containers:
- name: tomcat-container # 容器的名称
image: tomcat:latest # Tomcat镜像,可以根据需要指定版本
ports:
- containerPort: 8080 # 容器内部监听的端口
volumeMounts:
- name: tomcat-data # 挂载的持久卷的名称
mountPath: /usr/local/tomcat/webapps # 挂载路径,用于存储应用程序数据
volumes:
- name: tomcat-data # 持久卷的名称
emptyDir: {} # 使用空目录作为持久卷,适用于临时数据存储
---
apiVersion: v1
kind: Service
metadata:
name: tomcat-service # Service的名称
spec:
selector:
app: tomcat-app # 选择要关联的Pod的标签
ports:
- protocol: TCP
port: 80 # Service暴露的端口
targetPort: 8080 # 与Pod中容器的端口对应
type: ClusterIP # Service的类型,这里使用ClusterIP作为默认类型
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: tomcat-ingress # Ingress的名称
spec:
rules:
- host: example.com # 替换为实际的域名,用于路由流量到Ingress对应的Service
http:
paths:
- path: / # 访问路径
pathType: Prefix
backend:
service:
name: tomcat-service # 与Ingress关联的Service的名称
port:
number: 80 # 与Service暴露的端口一致
分享一个k8s案例
最新推荐文章于 2024-04-07 17:50:38 发布