This commit is contained in:
14
k8s/00-registry-secret.yaml
Executable file
14
k8s/00-registry-secret.yaml
Executable file
@@ -0,0 +1,14 @@
|
||||
# ⚠️ 이 파일은 직접 kubectl로 적용합니다 (ArgoCD에서 관리 X)
|
||||
# Gitea Registry 인증 정보를 K8s에 등록하는 Secret
|
||||
#
|
||||
# 아래 명령어로 생성하세요 (파일 대신 명령어 사용 권장):
|
||||
#
|
||||
# kubectl create secret docker-registry gitea-registry-secret \
|
||||
# --namespace=web-portal \
|
||||
# --docker-server=192.168.x.x:3000 \
|
||||
# --docker-username=<gitea계정> \
|
||||
# --docker-password=<gitea패스워드> \
|
||||
# --docker-email=<이메일>
|
||||
#
|
||||
# 생성 확인:
|
||||
# kubectl get secret gitea-registry-secret -n web-portal
|
||||
4
k8s/01-namespace.yaml
Executable file
4
k8s/01-namespace.yaml
Executable file
@@ -0,0 +1,4 @@
|
||||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
name: web-portal
|
||||
65
k8s/02-postgres.yaml
Executable file
65
k8s/02-postgres.yaml
Executable file
@@ -0,0 +1,65 @@
|
||||
apiVersion: v1
|
||||
kind: PersistentVolumeClaim
|
||||
metadata:
|
||||
name: postgres-pvc
|
||||
namespace: web-portal
|
||||
spec:
|
||||
accessModes: [ReadWriteOnce]
|
||||
resources:
|
||||
requests:
|
||||
storage: 1Gi
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: postgres
|
||||
namespace: web-portal
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: postgres
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: postgres
|
||||
spec:
|
||||
containers:
|
||||
- name: postgres
|
||||
image: postgres:15-alpine
|
||||
env:
|
||||
- name: POSTGRES_DB
|
||||
value: portaldb
|
||||
- name: POSTGRES_USER
|
||||
value: portaluser
|
||||
- name: POSTGRES_PASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: portal-secrets
|
||||
key: db-password
|
||||
ports:
|
||||
- containerPort: 5432
|
||||
volumeMounts:
|
||||
- name: postgres-data
|
||||
mountPath: /var/lib/postgresql/data
|
||||
readinessProbe:
|
||||
exec:
|
||||
command: [pg_isready, -U, portaluser, -d, portaldb]
|
||||
initialDelaySeconds: 5
|
||||
periodSeconds: 5
|
||||
volumes:
|
||||
- name: postgres-data
|
||||
persistentVolumeClaim:
|
||||
claimName: postgres-pvc
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: postgres-service
|
||||
namespace: web-portal
|
||||
spec:
|
||||
selector:
|
||||
app: postgres
|
||||
ports:
|
||||
- port: 5432
|
||||
targetPort: 5432
|
||||
9
k8s/03-secrets.yaml
Executable file
9
k8s/03-secrets.yaml
Executable file
@@ -0,0 +1,9 @@
|
||||
apiVersion: v1
|
||||
kind: Secret
|
||||
metadata:
|
||||
name: portal-secrets
|
||||
namespace: web-portal
|
||||
type: Opaque
|
||||
stringData:
|
||||
db-password: "portalpass"
|
||||
jwt-secret: "your-super-secret-jwt-key-change-this-in-production"
|
||||
68
k8s/04-backend.yaml
Executable file
68
k8s/04-backend.yaml
Executable file
@@ -0,0 +1,68 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: backend
|
||||
namespace: web-portal
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: backend
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: backend
|
||||
spec:
|
||||
imagePullSecrets:
|
||||
- name: gitea-registry-secret
|
||||
containers:
|
||||
- name: backend
|
||||
image: 192.168.x.x:3000/username/portal-backend:latest
|
||||
imagePullPolicy: Always
|
||||
ports:
|
||||
- containerPort: 8000
|
||||
env:
|
||||
- name: DB_HOST
|
||||
value: postgres-service
|
||||
- name: DB_PORT
|
||||
value: "5432"
|
||||
- name: DB_NAME
|
||||
value: portaldb
|
||||
- name: DB_USER
|
||||
value: portaluser
|
||||
- name: DB_PASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: portal-secrets
|
||||
key: db-password
|
||||
- name: JWT_SECRET
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: portal-secrets
|
||||
key: jwt-secret
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: /health
|
||||
port: 8000
|
||||
initialDelaySeconds: 20
|
||||
periodSeconds: 5
|
||||
failureThreshold: 6
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /health
|
||||
port: 8000
|
||||
initialDelaySeconds: 60
|
||||
periodSeconds: 15
|
||||
failureThreshold: 5
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: backend-service
|
||||
namespace: web-portal
|
||||
spec:
|
||||
selector:
|
||||
app: backend
|
||||
ports:
|
||||
- port: 8000
|
||||
targetPort: 8000
|
||||
43
k8s/05-frontend.yaml
Executable file
43
k8s/05-frontend.yaml
Executable file
@@ -0,0 +1,43 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: frontend
|
||||
namespace: web-portal
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: frontend
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: frontend
|
||||
spec:
|
||||
imagePullSecrets:
|
||||
- name: gitea-registry-secret
|
||||
containers:
|
||||
- name: frontend
|
||||
image: 192.168.x.x:3000/username/portal-frontend:latest
|
||||
imagePullPolicy: Always
|
||||
ports:
|
||||
- containerPort: 80
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: /
|
||||
port: 80
|
||||
initialDelaySeconds: 5
|
||||
periodSeconds: 5
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: frontend-service
|
||||
namespace: web-portal
|
||||
spec:
|
||||
type: NodePort
|
||||
selector:
|
||||
app: frontend
|
||||
ports:
|
||||
- port: 80
|
||||
targetPort: 80
|
||||
nodePort: 30090
|
||||
20
k8s/06-argocd-app.yaml
Executable file
20
k8s/06-argocd-app.yaml
Executable file
@@ -0,0 +1,20 @@
|
||||
apiVersion: argoproj.io/v1alpha1
|
||||
kind: Application
|
||||
metadata:
|
||||
name: web-portal
|
||||
namespace: argocd
|
||||
spec:
|
||||
project: default
|
||||
source:
|
||||
repoURL: http://192.168.x.x:3000/username/k8s-portal.git
|
||||
targetRevision: main
|
||||
path: k8s
|
||||
destination:
|
||||
server: https://kubernetes.default.svc
|
||||
namespace: web-portal
|
||||
syncPolicy:
|
||||
automated:
|
||||
prune: true
|
||||
selfHeal: true
|
||||
syncOptions:
|
||||
- CreateNamespace=true
|
||||
299
k8s/portal.yaml
Executable file
299
k8s/portal.yaml
Executable file
@@ -0,0 +1,299 @@
|
||||
# ============================================================
|
||||
# 1. Namespace
|
||||
# ============================================================
|
||||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
name: web-portal
|
||||
|
||||
---
|
||||
# ============================================================
|
||||
# 2. PostgreSQL - PersistentVolumeClaim
|
||||
# ============================================================
|
||||
apiVersion: v1
|
||||
kind: PersistentVolumeClaim
|
||||
metadata:
|
||||
name: postgres-pvc
|
||||
namespace: web-portal
|
||||
spec:
|
||||
accessModes: [ReadWriteOnce]
|
||||
resources:
|
||||
requests:
|
||||
storage: 2Gi
|
||||
|
||||
---
|
||||
# ============================================================
|
||||
# 3. PostgreSQL - Secret
|
||||
# ============================================================
|
||||
apiVersion: v1
|
||||
kind: Secret
|
||||
metadata:
|
||||
name: postgres-secret
|
||||
namespace: web-portal
|
||||
type: Opaque
|
||||
stringData:
|
||||
POSTGRES_DB: portaldb
|
||||
POSTGRES_USER: portaluser
|
||||
POSTGRES_PASSWORD: portalpass
|
||||
|
||||
---
|
||||
# ============================================================
|
||||
# 4. PostgreSQL - ConfigMap (init SQL)
|
||||
# ============================================================
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: postgres-init-sql
|
||||
namespace: web-portal
|
||||
data:
|
||||
init.sql: |
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
id SERIAL PRIMARY KEY,
|
||||
username VARCHAR(100) UNIQUE NOT NULL,
|
||||
password_hash TEXT NOT NULL,
|
||||
is_admin BOOLEAN DEFAULT FALSE,
|
||||
created_at TIMESTAMP DEFAULT NOW()
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS webpages (
|
||||
id SERIAL PRIMARY KEY,
|
||||
name VARCHAR(200) NOT NULL,
|
||||
url TEXT NOT NULL,
|
||||
description TEXT DEFAULT '',
|
||||
icon VARCHAR(10) DEFAULT '🌐',
|
||||
created_at TIMESTAMP DEFAULT NOW()
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS user_webpages (
|
||||
user_id INTEGER REFERENCES users(id) ON DELETE CASCADE,
|
||||
webpage_id INTEGER REFERENCES webpages(id) ON DELETE CASCADE,
|
||||
PRIMARY KEY (user_id, webpage_id)
|
||||
);
|
||||
-- admin / admin1234
|
||||
INSERT INTO users (username, password_hash, is_admin)
|
||||
VALUES ('admin', '$2b$12$LQv3c1yqBWVHxkd0LHAkCOYz6TtxMQJqhN8/LewKyNiAYMxRmfvym', TRUE)
|
||||
ON CONFLICT (username) DO NOTHING;
|
||||
-- user1 / user1234
|
||||
INSERT INTO users (username, password_hash, is_admin)
|
||||
VALUES ('user1', '$2b$12$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', FALSE)
|
||||
ON CONFLICT (username) DO NOTHING;
|
||||
INSERT INTO webpages (name, url, description, icon) VALUES
|
||||
('Google', 'https://www.google.com', '구글 검색 엔진', '🔍'),
|
||||
('GitHub', 'https://github.com', '소스코드 저장소', '🐙'),
|
||||
('Notion', 'https://notion.so', '문서 협업 툴', '📝')
|
||||
ON CONFLICT DO NOTHING;
|
||||
|
||||
---
|
||||
# ============================================================
|
||||
# 5. PostgreSQL - Deployment
|
||||
# ============================================================
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: postgres
|
||||
namespace: web-portal
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: postgres
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: postgres
|
||||
spec:
|
||||
containers:
|
||||
- name: postgres
|
||||
image: postgres:15-alpine
|
||||
ports:
|
||||
- containerPort: 5432
|
||||
envFrom:
|
||||
- secretRef:
|
||||
name: postgres-secret
|
||||
volumeMounts:
|
||||
- name: data
|
||||
mountPath: /var/lib/postgresql/data
|
||||
- name: init-sql
|
||||
mountPath: /docker-entrypoint-initdb.d
|
||||
resources:
|
||||
requests:
|
||||
memory: "256Mi"
|
||||
cpu: "100m"
|
||||
limits:
|
||||
memory: "512Mi"
|
||||
cpu: "500m"
|
||||
volumes:
|
||||
- name: data
|
||||
persistentVolumeClaim:
|
||||
claimName: postgres-pvc
|
||||
- name: init-sql
|
||||
configMap:
|
||||
name: postgres-init-sql
|
||||
|
||||
---
|
||||
# ============================================================
|
||||
# 6. PostgreSQL - Service
|
||||
# ============================================================
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: postgres-service
|
||||
namespace: web-portal
|
||||
spec:
|
||||
selector:
|
||||
app: postgres
|
||||
ports:
|
||||
- port: 5432
|
||||
targetPort: 5432
|
||||
|
||||
---
|
||||
# ============================================================
|
||||
# 7. Backend - Secret (JWT)
|
||||
# ============================================================
|
||||
apiVersion: v1
|
||||
kind: Secret
|
||||
metadata:
|
||||
name: backend-secret
|
||||
namespace: web-portal
|
||||
type: Opaque
|
||||
stringData:
|
||||
JWT_SECRET: "change-this-to-a-secure-random-string-in-production"
|
||||
|
||||
---
|
||||
# ============================================================
|
||||
# 8. Backend - Deployment
|
||||
# ============================================================
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: backend
|
||||
namespace: web-portal
|
||||
spec:
|
||||
replicas: 2
|
||||
selector:
|
||||
matchLabels:
|
||||
app: backend
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: backend
|
||||
spec:
|
||||
initContainers:
|
||||
- name: wait-for-db
|
||||
image: busybox
|
||||
command: ['sh', '-c', 'until nc -z postgres-service 5432; do echo waiting for postgres; sleep 2; done']
|
||||
containers:
|
||||
- name: backend
|
||||
image: web-portal-backend:latest
|
||||
imagePullPolicy: Never # Docker Desktop 로컬 이미지 사용
|
||||
ports:
|
||||
- containerPort: 8000
|
||||
env:
|
||||
- name: DB_HOST
|
||||
value: postgres-service
|
||||
- name: DB_PORT
|
||||
value: "5432"
|
||||
- name: DB_NAME
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: postgres-secret
|
||||
key: POSTGRES_DB
|
||||
- name: DB_USER
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: postgres-secret
|
||||
key: POSTGRES_USER
|
||||
- name: DB_PASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: postgres-secret
|
||||
key: POSTGRES_PASSWORD
|
||||
- name: JWT_SECRET
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: backend-secret
|
||||
key: JWT_SECRET
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /api/health
|
||||
port: 8000
|
||||
initialDelaySeconds: 10
|
||||
periodSeconds: 10
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: /api/health
|
||||
port: 8000
|
||||
initialDelaySeconds: 5
|
||||
periodSeconds: 5
|
||||
resources:
|
||||
requests:
|
||||
memory: "128Mi"
|
||||
cpu: "100m"
|
||||
limits:
|
||||
memory: "256Mi"
|
||||
cpu: "500m"
|
||||
|
||||
---
|
||||
# ============================================================
|
||||
# 9. Backend - Service
|
||||
# ============================================================
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: backend-service
|
||||
namespace: web-portal
|
||||
spec:
|
||||
selector:
|
||||
app: backend
|
||||
ports:
|
||||
- port: 8000
|
||||
targetPort: 8000
|
||||
|
||||
---
|
||||
# ============================================================
|
||||
# 10. Frontend (Nginx) - Deployment
|
||||
# ============================================================
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: frontend
|
||||
namespace: web-portal
|
||||
spec:
|
||||
replicas: 2
|
||||
selector:
|
||||
matchLabels:
|
||||
app: frontend
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: frontend
|
||||
spec:
|
||||
containers:
|
||||
- name: frontend
|
||||
image: web-portal-frontend:latest
|
||||
imagePullPolicy: Never # Docker Desktop 로컬 이미지 사용
|
||||
ports:
|
||||
- containerPort: 80
|
||||
resources:
|
||||
requests:
|
||||
memory: "64Mi"
|
||||
cpu: "50m"
|
||||
limits:
|
||||
memory: "128Mi"
|
||||
cpu: "200m"
|
||||
|
||||
---
|
||||
# ============================================================
|
||||
# 11. Frontend - Service (NodePort - 외부 접속용)
|
||||
# ============================================================
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: frontend-service
|
||||
namespace: web-portal
|
||||
spec:
|
||||
type: NodePort
|
||||
selector:
|
||||
app: frontend
|
||||
ports:
|
||||
- port: 80
|
||||
targetPort: 80
|
||||
nodePort: 30080 # http://localhost:30080 으로 접속
|
||||
Reference in New Issue
Block a user