Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 이메일인증
- 롤토체스 꿀팁
- Database
- 자바스크립트
- 스프링
- jQuery
- 롤
- Python
- LOL
- 리그오브레전드
- 마이바티스
- tomcat
- MSI
- 쿠버네티스
- 다국어처리
- 롤토체스
- Java
- 테이블
- 쿠버네티스 어나더 클래스
- jdk
- SQL
- 파이썬
- 회원가입
- Spring
- k8s
- 일프로
- kubernetes
- oracle
- NoSQL
- 데이터베이스
Archives
- Today
- Total
웹쟁이의 일상
[Kubernetes] Object 그려보며 이해하기 본문
◎쿠버네티스 Object의 계층 구조
1. Cluster
- 클러스터 전체에 걸쳐 적용되는 오브젝트.
- 특정 namespace에 종속되지 않음.
- Namespace: 클러스터 내에서 리소스를 논리적으로 분리하는 단위
# namespace 생성 yaml
apiVersion: v1
kind: Namespace
metadata:
name: anotherclass-123
labels:
part-of: k8s-anotherclass
managed-by: dashboard
- PersistentVolume(PV): 관리자가 프로비저닝하거나 스토리지 클래스를 통해 동적으로 프로비저닝된 클러스터의 스토리지
2. namespace
- 특정 namespace 내에서만 유효한 오브젝트
- Deployment: Pod를 선언적으로 관리하기 위한 오브젝트
# Deployment 생성 yaml
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: anotherclass-123
name: api-tester-1231
labels:
part-of: k8s-anotherclass
component: backend-server
name: api-tester
instance: api-tester-1231
version: 1.0.0
managed-by: dashboard
spec:
selector:
matchLabels:
part-of: k8s-anotherclass
component: backend-server
name: api-tester
instance: api-tester-1231
replicas: 2 //pod 생성 갯수
strategy: //업데이트 방식
type: RollingUpdate
template: //pod 생성 시 적용될 템플릿
metadata:
labels:
part-of: k8s-anotherclass
component: backend-server
name: api-tester
instance: api-tester-1231
version: 1.0.0
spec:
nodeSelector:
kubernetes.io/hostname: k8s-master
containers:
- name: api-tester-1231
image: 1pro/api-tester:v1.0.0
ports:
- name: http
containerPort: 8080
envFrom: //configMap과 연결. 환경변수 값을 제공
- configMapRef:
name: api-tester-1231-properties
startupProbe: //기동체크 후 실패 시 재기동
httpGet:
path: "/startup"
port: 8080
periodSeconds: 5
failureThreshold: 36
readinessProbe: // 트래픽 연결 결정
httpGet:
path: "/readiness"
port: 8080
periodSeconds: 10
failureThreshold: 3
livenessProbe: //서비스 관리. 정상이 아니라면 재시작.
httpGet:
path: "/liveness"
port: 8080
periodSeconds: 10
failureThreshold: 3
resources: //pod의 cpu, memory 할당 설정. limit을 설정해야 누수를 막을 수 있음.
requests:
memory: "100Mi"
cpu: "100m"
limits:
memory: "200Mi"
cpu: "200m"
volumeMounts:
- name: files //PVC와 name 매칭되어 연결
mountPath: /usr/src/myapp/files/dev //pod 내부에 만들어지는 디렉토리
- name: secret-datasource
mountPath: /usr/src/myapp/datasource
volumes:
- name: files
persistentVolumeClaim:
claimName: api-tester-1231-files
- name: secret-datasource
secret:
secretName: api-tester-1231-postgresql
- Service: Pod 집합에 대한 네트워크 액세스 정책을 정의
# Service
apiVersion: apps/v1
apiVersion: v1
kind: Service
metadata:
namespace: anotherclass-123
name: api-tester-1231
labels:
part-of: k8s-anotherclass
component: backend-server
name: api-tester
instance: api-tester-1231
version: 1.0.0
managed-by: dashboard
spec:
selector:
part-of: k8s-anotherclass
component: backend-server
name: api-tester
instance: api-tester-1231
ports:
- port: 80
targetPort: http
nodePort: 31231
type: NodePort
- ConfigMap/Secret: 설정 정보와 민감한 정보를 관리
# configMap
apiVersion: v1
kind: ConfigMap
metadata:
namespace: anotherclass-123
name: api-tester-1231-properties
labels:
part-of: k8s-anotherclass
component: backend-server
name: api-tester
instance: api-tester-1231
version: 1.0.0
managed-by: dashboard
data:
spring_profiles_active: "dev"
application_role: "ALL"
postgresql_filepath: "/usr/src/myapp/datasource/postgresql-info.yaml"
---
apiVersion: v1
kind: Secret
metadata:
namespace: anotherclass-123
name: api-tester-1231-postgresql
labels:
part-of: k8s-anotherclass
component: backend-server
name: api-tester
instance: api-tester-1231
version: 1.0.0
managed-by: dashboard
stringData:
postgresql-info.yaml: |
driver-class-name: "org.postgresql.Driver"
url: "jdbc:postgresql://postgresql:5431"
username: "dev"
password: "dev123"
- PersistentVolumeClaim(PVC): 사용자가 PV에 대한 요청을 정의
# PVC, PV
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
namespace: anotherclass-123
name: api-tester-1231-files
labels:
part-of: k8s-anotherclass
component: backend-server
name: api-tester
instance: api-tester-1231
version: 1.0.0
managed-by: kubectl
spec:
resources:
requests:
storage: 2G
accessModes:
- ReadWriteMany
selector:
matchLabels:
part-of: k8s-anotherclass
component: backend-server
name: api-tester
instance: api-tester-1231-files
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: api-tester-1231-files
labels:
part-of: k8s-anotherclass
component: backend-server
name: api-tester
instance: api-tester-1231-files
version: 1.0.0
managed-by: dashboard
spec:
capacity:
storage: 2G
volumeMode: Filesystem
accessModes:
- ReadWriteMany
local:
path: "/root/k8s-local-volume/1231"
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- {key: kubernetes.io/hostname, operator: In, values: [k8s-master]}
- HorizontalPodAutoscaler(HPA): 부하에 따라 Pod 수를 자동으로 조정
# HPA
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
namespace: anotherclass-123
name: api-tester-1231-default
labels:
part-of: k8s-anotherclass
component: backend-server
name: api-tester
instance: api-tester-1231
version: 1.0.0
managed-by: dashboard
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: api-tester-1231
minReplicas: 2
maxReplicas: 4
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 60
behavior:
scaleUp:
stabilizationWindowSeconds: 120
'k8s' 카테고리의 다른 글
[Kubernetes] 쿠버네티스가 편한 이유 (0) | 2025.04.07 |
---|---|
[Kubernetes] 쿠버네티스 빠르고 쉽게 설치하기(Silicon Mac) (0) | 2025.04.04 |
[Kubernetes] 컨테이너 한방 정리 (1) | 2025.04.04 |
Comments