티스토리 뷰
웹 애플리케이션 배포
Pod, ReplicaSet, Deployment, Service를 이용하여 기본적인 웹 애플리케이션을 배포합니다.
subicura.com
wordpress 배포
wordpress.yml
apiVersion: apps/v1
kind: Deployment # mysql 파드
metadata:
name: wordpress-mysql
labels:
app: wordpress
spec:
selector: # Deployment 에서 selector 에는 관리할 pod 을 명시한다
matchLabels: # 즉 app:wordpress,tier:mysql 레이블을 갖는 pod 를 이 deployment 가 관리한다는 뜻
app: wordpress
tier: mysql
template: # matchLabels 에 해당하는 pod 없으면 template 에 명시된 내용에 따라 pod 생성함
metadata:
labels:
app: wordpress
tier: mysql
spec:
containers:
- image: mariadb:10.7
name: mysql
env:
- name: MYSQL_DATABASE
value: wordpress
- name: MYSQL_ROOT_PASSWORD
value: password
ports:
- containerPort: 3306 # 컨테이너가 listen 할 포트
name: mysql
---
apiVersion: v1
kind: Service # mysql 접속 위한 ClusterIP 서비스
metadata:
name: wordpress-mysql # 서비스가 내부 DNS 에 해당 이름으로 도메인 등록
labels:
app: wordpress
spec: # 타입 지정 안하면 ClusterIP
ports:
- port: 3306 # 3306 포트로 요청
# Service에서 selector는 서비스가 트래픽을 라우팅할 파드들의 레이블을 명시한다.
# 여기서는 Deployment 와 동일 레이블을 명시해서 해당 deployment가 관리하는(생성하는) 파드
selector:
app: wordpress
tier: mysql
---
apiVersion: apps/v1
kind: Deployment # wordpress app 파드
metadata:
name: wordpress
labels:
app: wordpress
spec:
selector:
matchLabels:
app: wordpress
tier: frontend
template:
metadata:
labels:
app: wordpress
tier: frontend
spec:
containers:
- image: wordpress:5.9.1-php8.1-apache
name: wordpress
env:
- name: WORDPRESS_DB_HOST # 서비스가 등록한 도메인으로 설정
value: wordpress-mysql
- name: WORDPRESS_DB_NAME
value: wordpress
- name: WORDPRESS_DB_USER
value: root
- name: WORDPRESS_DB_PASSWORD
value: password
ports:
- containerPort: 80
name: wordpress
---
apiVersion: v1
kind: Service # 외부 노출 위한 NodePort 서비스
metadata:
name: wordpress
labels:
app: wordpress
spec:
type: NodePort
ports:
- port: 80
nodePort: 30000 # 노드에 오픈되는 포트
selector: # 아래 레이블을 갖는 파드와 연결
app: wordpress
tier: frontend
selector
- Deployment 의 selector 는 관리할 pod 를 명시한다
- Service에서 selector는 서비스가 트래픽을 라우팅할 파드들의 레이블을 명시한다
apply
Vote
vote.yml
# deployment/vote
apiVersion: apps/v1
kind: Deployment
metadata:
name: vote
spec:
selector:
matchLabels:
service: vote
template:
metadata:
labels:
service: vote
spec:
containers:
- name: vote
image: ghcr.io/subicura/voting/vote
env:
- name: REDIS_HOST
value: "redis"
- name: REDIS_PORT
value: "6379"
livenessProbe: # 컨테이너 헬스체크
httpGet:
path: /
port: 80
readinessProbe:
httpGet:
path: /
port: 80
ports:
- containerPort: 80
protocol: TCP
--- # deployment/vote 를 외부에서 접근 하기위한 NodePort 서비스
apiVersion: v1
kind: Service
metadata:
name: vote
spec:
type: NodePort
ports:
- port: 80
nodePort: 31000
protocol: TCP
selector:
service: vote
--- # deployment/result
apiVersion: apps/v1
kind: Deployment
metadata:
name: result
spec:
selector:
matchLabels:
service: result
template:
metadata:
labels:
service: result
spec:
containers:
- name: result
image: ghcr.io/subicura/voting/result
env:
- name: POSTGRES_HOST # Postgres 접속 위한 환경변수
value: "db"
- name: POSTGRES_PORT
value: "5432"
livenessProbe:
httpGet:
path: /
port: 80
readinessProbe:
httpGet:
path: /
port: 80
ports:
- containerPort: 80
protocol: TCP
--- # deployment/result 외부 접속 용 NodePort
apiVersion: v1
kind: Service
metadata:
name: result
spec:
type: NodePort
ports:
- port: 80
nodePort: 31001
protocol: TCP
selector:
service: result
--- # deployment/worker
apiVersion: apps/v1
kind: Deployment
metadata:
name: worker
spec:
selector:
matchLabels:
service: worker
template:
metadata:
labels:
service: worker
spec:
containers:
- name: worker
image: ghcr.io/subicura/voting/worker
env: # worker 는 redis, postgres 모두 접근 해야함
- name: REDIS_HOST
value: "redis"
- name: REDIS_PORT
value: "6379"
- name: POSTGRES_HOST
value: "db"
- name: POSTGRES_PORT
value: "5432"
--- # deployment/redis
apiVersion: apps/v1
kind: Deployment
metadata:
name: redis
spec:
selector:
matchLabels:
service: redis
template:
metadata:
labels:
service: redis
spec:
containers:
- name: redis
image: redis
ports:
- containerPort: 6379
protocol: TCP
--- # redis 접근용 ClusterIP
apiVersion: v1
kind: Service
metadata:
name: redis
spec:
ports:
- port: 6379
protocol: TCP
selector:
service: redis
--- # deployment/db
apiVersion: apps/v1
kind: Deployment
metadata:
name: db
spec:
selector:
matchLabels:
service: db
template:
metadata:
labels:
service: db
spec:
containers:
- name: db
image: postgres:9.4
env:
- name: POSTGRES_USER
value: "postgres"
- name: POSTGRES_PASSWORD
value: "postgres"
ports:
- containerPort: 5432
protocol: TCP
--- # deployment/db 접근용 ClusterIP
apiVersion: v1
kind: Service
metadata:
name: db
spec:
ports:
- port: 5432
protocol: TCP
selector:
service: db
apply
클러스터 ip:31000
클러스터 ip:31001
정리
해보니까 결국 실제로는 Deployment 와 Service 이 두개를 가장 많이 정의할것 같다.
Deployment
# deployment/vote
# kubernetes 의 api 버전을 정의한다.
apiVersion: apps/v1
# Deployment, Service, Pod ...
kind: Deployment
metadata:
name: vote
spec:
# Deployment 에서의 selector 는 내가 (deployment) 가 관리할 pod 를 의미한다
selector:
# 레이블 service:vote 인 pod를 관리한다
matchLabels:
service: vote
# selector 에서 정의한 pod 가 없다면 template 에 정의된 스펙에 따라 새로 만든다
template:
metadata:
labels:
service: vote
spec:
containers:
- name: vote
image: ghcr.io/subicura/voting/vote
env:
- name: REDIS_HOST
value: "redis"
- name: REDIS_PORT
value: "6379"
livenessProbe: # 컨테이너 헬스체크
httpGet:
path: /
port: 80
readinessProbe:
httpGet:
path: /
port: 80
ports:
- containerPort: 80
protocol: TCP
Service
--- # deployment/vote 를 외부에서 접근 하기위한 NodePort 서비스
apiVersion: v1
kind: Service
metadata:
name: vote
spec:
# ClusterIP, NodePort... type 정의 하지 않으면 기본 ClusterIP
type: NodePort
ports:
# 클러스터 내에서 서비스에 엑세스할 포트 번호
- port: 80
# 노드들인 이 포트 번호로 외부에서 접근 가능하다
nodePort: 31000
protocol: TCP
selector:
service: vote
'Web > Kubernetes' 카테고리의 다른 글
Kubernetes Ingress (0) | 2024.01.08 |
---|---|
minikube addons enable ingress 시 MK_ADDON_ENABLE 에러 (0) | 2024.01.08 |
Kubernetes Service (ClusterIP, NodePort, Load Balanacer) (0) | 2024.01.06 |
Kubernetes Deployment (0) | 2024.01.06 |
Kubernetes ReplicaSet (0) | 2024.01.05 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 자료구조
- MVC
- recursion
- Stack
- Tree
- 이분탐색
- greedy
- two pointer
- Kruskal
- Implementation
- C
- BFS
- DP
- 재귀
- floyd warshall
- Dijkstra
- binary search
- Brute Force
- C++
- dfs
- Python
- db
- permutation
- 조합
- back tracking
- graph
- Spring
- CSS
- Unity
- priority queue
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
글 보관함