Kubernetes aws-what';这是为Nginx设置docroot内容的最佳实践

Kubernetes aws-what';这是为Nginx设置docroot内容的最佳实践,nginx,kubernetes,amazon-eks,Nginx,Kubernetes,Amazon Eks,我已经使用ingress在aws eks上使用Nginx docker容器实现了一个web应用程序。目前,我正在使用docroot内容创建docker映像,并使用Nginx提供服务。如果我的do root内容很大,并且我想将其保留在图像之外,我该如何做?请分享一些例子 这是docker文件的内容 FROM nginx ADD . /usr/share/nginx/html/ COPY env.conf /etc/nginx/conf.d/ COPY nginx.conf /etc/ng

我已经使用ingress在aws eks上使用Nginx docker容器实现了一个web应用程序。目前,我正在使用docroot内容创建docker映像,并使用Nginx提供服务。如果我的do root内容很大,并且我想将其保留在图像之外,我该如何做?请分享一些例子

这是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或云存储,以服务大型内容

下面是一个很好的例子:


您还可以根据需要使用EFS、NFS或云存储桶。

如果您可以共享示例docker文件或不获取太多上下文。您可以启动webapp pod并使用入口将流量转发到其中。@HarshManvar:我已经更新了我的问题,请看一看。也许您可以使用NFS存储文档根内容,pod将装载在NFS或云存储桶上。在AWS上,您可以将内容保存在S3中。您可以直接从S3提供服务,而不使用容器,也可以设置nginx来代理对S3的请求。它看起来不像本地文件,但对于这个用例,您不一定需要它。您决定了任何解决方案吗?
NFS
似乎是一种很好的方法。多亏了Harsh,我能够使用持久性卷和持久性卷声明来实现这一点。@NikhilBharati如果答案有用,请更新问题的状态。如果问题已解决,请向上投票。您可以将其标记为已接受。