apiVersion: v1
kind: Service
metadata:
name: django-svc
spec:
selector:
type: backend
ports:
- port: 80
targetPort: 8000
apiVersion: v1
kind: Service
metadata:
name: mysql-svc
spec:
selector:
type: db
ports:
- port: 3306
targetPort: 3306
apiVersion: v1
kind: ConfigMap
metadata:
name: django-cm
data:
DBNAME: "web"
DBUSER: "root"
DBPASS: "qwer1234"
DBHOST: "mysql-svc"
DBPORT: "3306"
kind: ConfigMap
metadata:
name: mysql-cm
data:
MYSQL_ROOT_PASSWORD: "qwer1234"
apiVersion: v1
kind: Pod
metadata:
name: db-pod
labels:
type: db
spec:
containers:
- name: container
image: mysql:8.0.32-debian
envFrom:
- configMapRef:
name: mysql-cm
apiVersion: v1
kind: Pod
metadata:
name: backend-pod
labels:
type: backend
spec:
containers:
- name: container
image: ddarahakit2023/dj:1.2
envFrom:
- configMapRef:
name: django-cm
FROM nginx:latest
RUN rm -rf /usr/share/nginx/html/index.html
ADD build /usr/share/nginx/html/
RUN rm -rf /etc/nginx/conf.d/default.conf
ADD default.conf.template /etc/nginx/conf.d/default.conf.template
FROM python:3.9
ENV PYTHONUNBUFFERED 1
WORKDIR /app
COPY r.txt /app/r.txt
COPY . /app
RUN pip install -r r.txt # pip로 설치되어야할 것들 잘 있는지 확인해주기!!
# 여기서 migrate 안했으니깐 컨테이너 만들때 같이 실행해줘야한다!
apiVersion: v1
kind: Service
metadata:
name: frontend-svc
spec:
selector:
type: frontend
ports:
- port: 80
targetPort: 80
apiVersion: v1
kind: Service
metadata:
name: backend-svc
spec:
selector:
type: backend
ports:
- port: 8000
targetPort: 8000
apiVersion: v1
kind: Service
metadata:
name: db-svc
spec:
selector:
type: db
ports:
- port: 3306
targetPort: 3306
apiVersion: v1
kind: ConfigMap
metadata:
name: frontend-cm
data:
BACKEND_SVC_NAME: "backend-svc"
apiVersion: v1
kind: ConfigMap
metadata:
name: backend-cm
data:
DBNAME: "web"
DBUSER: "root"
DBPASS: "qwer1234"
DBHOST: "db-svc"
DBPORT: "3306"
apiVersion: v1
kind: ConfigMap
metadata:
name: db-cm
data:
MYSQL_ROOT_PASSWORD: "qwer1234"
apiVersion: v1
kind: Pod
metadata:
name: db-pod
labels:
type: db
spec:
containers:
- name: container
image: mysql:8.0.32-debian
envFrom:
- configMapRef:
name: db-cm
# create database web; web 데이터베이스를 만들어줘야한다.
apiVersion: v1
kind: Pod
metadata:
name: backend-pod
labels:
type: backend
spec:
containers:
- name: container
image: gugucone/back:1.2
command: ["/bin/sh", "-ec", "python manage.py migrate && gunicorn config.wsgi --bind 0.0.0.0:8000"]
envFrom:
- configMapRef:
name: backend-cm
apiVersion: v1
kind: Pod
metadata:
name: frontend-pod
labels:
type: frontend
spec:
containers:
- name: container
image: gugucone/front:1.1
command: ["/bin/sh", "-ec", "envsubst '$BACKEND_SVC_NAME' < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"]
envFrom:
- configMapRef:
name: frontend-cm
envsubst
이 명령어를 사용해야한다!우린 이제 서비스에 있는 클러스터 IP로 연결 할 수 있다.
backend:8000/dev/data
frontend:80/dev/data
frontend 연결 확인
ports:
- port: 9000
targetPort: 8000
nodePort: 30000
type: NodePort
포트번호를 받고 싶으면 지정해주면 되는데 30000이상으로 해줘야 한다.
service 타입을 nodeport로 변경해서 포트번호를 받았고
들어가지는데 어느 노드로 들어가도 접속이 가능하다 이건 k8s의 기능 포트번호만 알고 있으면 된다!
App.js 여기서 뭘 건드려야 포트번호 없이 들어가는지 모르겠다.