nginx - Kubernetes aws-为 Nginx 设置 docroot 内容的最佳实践是什么
问题描述
我已经使用 ingress 在 aws eks 上使用 Nginx docker 容器实现了一个 Web 应用程序。目前我正在使用 docroot 内容创建 docker 映像并使用 Nginx 来提供它。如果我的根目录内容很大并且我想将其保留在图像之外,我该怎么做?请分享一些例子。
这是docker文件内容
FROM nginx
ADD . /usr/share/nginx/html/
COPY env.conf /etc/nginx/conf.d/
COPY nginx.conf /etc/nginx/
来自 env.conf 的内容
server {
listen 80 ;
server_name localhost;
root /usr/share/nginx/html;
index index.html;
large_client_header_buffers 4 32k;
#default_type text/html;
# CSS
location / {
add_header Cache-Control public;
# Equivalent to above:
expires 15m; # Indicate that the resource can be cached for 86400 seconds (24 hours)
etag on; # Add an ETag header with an identifier that can be stored by the client
rewrite ^/.*$ /index.html;
}
location ~ \/[^\/]*\.[^\/]*$ { }
location /ABC {
rewrite ^/abc(/|)$ /abc/index.html break;
rewrite ^/abc/.*$ /abc/index.html break;
}
}
这是 kubernetes yaml 文件。
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-dev4
namespace: abc
spec:
strategy:
type: Recreate
selector:
matchLabels:
app: nginx-dev4
replicas: 3 # tells deployment to run 1 pods matching the template
template: # create pods using pod definition in this template
metadata:
labels:
app: nginx-dev4
spec:
containers:
- name: nginx-dev4
image: XXXX.amazonaws.com/pcl-pv/dev4
ports:
- containerPort: 80
volumeMounts:
- mountPath: "/usr/share/nginx/html"
name: "task-pv-volume"
volumes:
- name: task-pv-volume
persistentVolumeClaim:
claimName: task-pv-claim
---
apiVersion: v1
kind: Service
metadata:
name: nginx-dev4
namespace: pv
labels:
app: nginx-dev4
spec:
ports:
- name: http
port: 9091
targetPort: 80
type: ClusterIP
selector:
app: nginx-dev4
---
# Please edit the object below. Lines beginning with a '#' will be ignored,
# and an empty file will abort the edit. If an error occurs while saving this file will be
# reopened with the relevant failures.
#
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
ingress.kubernetes.io/ssl-passthrough: "true"
ingress.kubernetes.io/ssl-redirect: "true"
name: nginx-dev4
namespace: pv
spec:
rules:
- host: XXXX.aws.com
http:
paths:
- path: /
backend:
serviceName: nginx-dev4
servicePort: 9091
添加了持久化卷,持久化卷声称可以实现这一点。
apiVersion: v1
kind: PersistentVolume
metadata:
name: task-pv-volume
namespace: pv
labels:
type: local
spec:
storageClassName: manual
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/home/ec2-user/nginx"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: task-pv-claim
namespace: pv
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 3Gi
解决方案
您可以使用 POD 挂载 NFS 或云存储作为服务器大型内容的选项。
这是一个很好的例子:https ://medium.com/grensesnittet/mounting-a-gcp-bucket-as-nfs-in-kubernetes-8f6d3faf4da3
您还可以根据需要使用 EFS、NFS 或云存储桶。
推荐阅读
- windows - Process Explorer 报告的不合理的巨大进程虚拟内存大小
- android - 在活动打开时每 1 秒循环一个线程是不好的做法吗?
- google-apps-script - 如果单元格为空白,则将单元格值还原为特定公式
- java - 为什么@Transactional 在某些情况下会忽略 Lazy fetch
- c# - 获得最小输出然后跟踪输入
- r - 如何将条形更改为降序?
- php - 错误:SQLSTATE [23000]:违反完整性约束:1048 列“用户名”不能为空
- html - 我在悬停时显示导航菜单有问题
- android - 查询 2 个 GeoPoints 之间的位置
- python-3.x - 从工作人员访问 SparkSession 的正确方法是什么