k8s实战案例之部署nginx+Tomcat+nfs实现动静分离
apiVersion: v1
kind: Service
metadata:
name: nfs-service
spec:
ports:
- port: 30443
targetPort: 80
selector:
app: nfs-web
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nfs-web
spec:
replicas: 2
selector:
matchLabels:
app: nfs-web
template:
metadata:
labels:
app: nfs-web
spec:
containers:
- name: nfs-web
image: nginx:1.17
ports:
- containerPort: 80
volumeMounts:
- name: nfs-storage
mountPath: /usr/share/nginx/html
volumes:
- name: nfs-storage
nfs:
server: 192.168.1.100
path: /data/web
---
apiVersion: v1
kind: Service
metadata:
name: tomcat-service
spec:
ports:
- port: 3080
targetPort: 8080
selector:
app: tomcat-app
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: tomcat-app
spec:
replicas: 2
selector:
matchLabels:
app: tomcat-app
template:
metadata:
labels:
app: tomcat-app
spec:
containers:
- name: tomcat-app
image: tomcat:8.5-jre8-alpine
ports:
- containerPort: 8080
这个示例中,我们定义了两个Service,分别用于对外暴露Nginx和Tomcat服务。Deployment部署了Nginx和Tomcat的Pod,并挂载了NFS存储卷。这样,Nginx服务器用于处理静态内容,而Tomcat服务器处理动态内容,实现了动静分离。
评论已关闭