how to serve static files from EKS cluster for Django?

您所在的位置:网站首页 半画幅和全画幅照片对比区别在哪 how to serve static files from EKS cluster for Django?

how to serve static files from EKS cluster for Django?

2023-01-20 20:04| 来源: 网络整理| 查看: 265

January 12, 2022 Django Leave a comment how to serve static files from EKS cluster for Django? Issue

I am new to Kubernetes. By reading some blogs and documentation I have successfully created the EKS cluster. I am using ALB(layer 7 load balancing) for my Django app. For controlling the routes/paths I am using the ALB ingress controller. But I am unable to serve my static contents for Django admin. I know that I need a webserver(Nginx) to serve my static files. I’m not sure how to configure to serve static files. note: (I don’t want to use whitenoise)

apiVersion: extensions/v1beta1 kind: Ingress metadata: name: "backend-ingress" annotations: kubernetes.io/ingress.class: alb alb.ingress.kubernetes.io/scheme: internet-facing alb.ingress.kubernetes.io/subnets: subnet-1, subnet-2, subnet-3 alb.ingress.kubernetes.io/certificate-arn: arn:aws:acm:ap-southeast-1:***:certificate/* alb.ingress.kubernetes.io/listen-ports: '[{"HTTP": 80}, {"HTTPS":443}]' alb.ingress.kubernetes.io/actions.ssl-redirect: '{"Type": "redirect", "RedirectConfig": { "Protocol": "HTTPS", "Port": "443", "StatusCode": "HTTP_301"}}' labels: app: stage spec: rules: - host: *.somedomain.com http: paths: - path: /* backend: serviceName: backend-service servicePort: 8000

this is the ingress yaml i am using. But whenever i am trying to visit my Django admin it’s not loading the css and js files.

Deployment file:

apiVersion: apps/v1 kind: Deployment metadata: name: server-dashboard-backend labels: app: backend spec: replicas: 2 selector: matchLabels: app: backend template: metadata: labels: app: backend spec: volumes: - name: staticfiles emptyDir: {} containers: - name: server-dashboard image: *.dkr.ecr.ap-southeast-1.amazonaws.com/*:4 volumeMounts: - name: staticfiles mountPath: /data lifecycle: postStart: exec: command: ["/bin/sh", "-c" , "cp -r /static /data/"] - name: nginx image: nginx:stable ports: - containerPort: 80 volumeMounts: - name: staticfiles mountPath: /data

Solution

I have solved the problem. i removed the command ["/bin/sh", "-c", "cp -r /path/to/staticfiles /data/"]

I was mounting in the wrong path. So the new deployment file is:

apiVersion: apps/v1 kind: Deployment metadata: name: server-dashboard-backend labels: app: backend spec: replicas: 2 selector: matchLabels: app: backend template: metadata: labels: app: backend spec: volumes: - name: staticfiles emptyDir: {} containers: - name: server-dashboard image: *.dkr.ecr.ap-southeast-1.amazonaws.com/*:4 volumeMounts: - name: staticfiles mountPath: /usr/src/code/static - name: nginx image: nginx:stable ports: - containerPort: 80 volumeMounts: - name: staticfiles mountPath: /usr/share/nginx/html/static/

Answered By – Raisul

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Related Posts November 2, 2022 Django ORM multiple chained JOIN equivalent and aggregation November 2, 2022 How to manage multiple websites with 1 django project November 2, 2022 Dockerized Django app and MySQL with docker-compose using .env

Programming Buddy



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3