Django, PHP등의 WAS는 프로그램 결과는 전송하지만 이미지나 CSS등은 처리가 되지 않아 보통 nginx를 통해 전송합니다.
이미지등의 처리는 AWS S3등의 클라우드 스토리지를 통해 많이 사용하지만 Ingress를 통해 전송하는 방식을 정리해보았습니다.
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: was
spec:
replicas: 1
selector:
matchLabels:
app: was
template:
metadata:
labels:
app: was
spec:
volumes:
- name: staticfiles
containers:
# was의 파일을 nginx를 통해 전송
- name: nginx
image: nginx:stable
ports:
- containerPort: 80
volumeMounts:
- name: staticfiles
mountPath: /usr/share/nginx/html/static/
- name: was
image: myimage
imagePullPolicy: Always
ports:
- containerPort: 8000
volumeMounts:
- name: staticfiles
mountPath: /static
lifecycle:
postStart:
exec:
# was내의 파일을 다른곳으로 복사
command: ["/bin/sh", "-c", "cp -r /usr/src/app/static /"]
---
apiVersion: v1
kind: Service
metadata:
name: was-svc
labels:
app: was-svc
spec:
selector:
app: was
type: NodePort
ports:
- port: 8000
targetPort: 8000
name: was
- port: 80
targetPort: 80
name: nginx
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: "was-ing"
annotations:
cert-manager.io/cluster-issuer: "letsencrypt-production"
nginx.ingress.kubernetes.io/force-ssl-redirect: "false"
nginx.ingress.kubernetes.io/ssl-passthrough: "true"
nginx.ingress.kubernetes.io/ssl-redirect: "false"
spec:
ingressClassName: nginx
tls:
- hosts:
- mydomain.com
secretName: was-tls
rules:
- host: mydomain.com
http:
paths:
- path: /static
pathType: Prefix
backend:
service:
name: was-svc
port:
number: 80
- path: /
pathType: Prefix
backend:
service:
name: was-svc
port:
number: 8000
반응형
'IT > Kubernetes' 카테고리의 다른 글
Gitlab에서 CI/CD 를 이용하여 쿠버네티스 배포하기 (0) | 2022.03.12 |
---|---|
CrashLoopBackOff 로 Pod이 시작되지 않을 때 처리 (0) | 2022.03.11 |
Elastic Cloud on Kubernetes (ECK) 설치 (1) | 2022.03.07 |