CKA 자격증 준비 과정에서 Udemy의 Certified Kubernetes Administrator (CKA) with Practice Tests 강의를 수강하고 정리한 내용입니다. 대부분의 자료는 해당 강의의 자료이며, 이외 레퍼런스는 관련 내용 상단에 표기하였으니 참고 바랍니다.
1. ReplicaSet이란?
하나의 앱이 장애가 발생하더라도, 동일한 다른 앱은 정상 작동하여 장애가 발생하지 않은 것처럼 동작하기 위한 오브젝트가 ReplicaSet 또는 Replication Controller입니다.
ReplicaSet과 Replication Controller는 동일한 목적을 가지고 있지만 일부의 차이가 있는데요.
두 오브젝트의 목적은 Load Balancing과 Scaling입니다.
ReplicaSet과 Replication Controller는 동일한 Pod를 여러개 복제하고, 유저들이 여러 Pod 중 하나에 분배되어 접근하도록 하며(Load Balancing), 항상 정해진 수만큼 Pod가 실행 중이도록 유지합니다.
Pod의 복제(replicas) 수를 조정하여 실행 중인 Pod를 줄이거나 늘릴 수도 있습니다. (Scaling)
2. ReplicaSet vs Replication Controller
두 오브젝트의 목적은 동일하지만 세부적인 기능에는 차이가 있습니다.
결론을 먼저 말하자면, ReplicaSet이 Replication Controller를 대체하는 최신 개념이기 때문에 ReplicaSet만 사용하면 됩니다.
두 가지 오브젝트는 Pod를 관리할 수 있는 범위에서 차이가 있습니다.
- Replication Controller:
Equality-based Selectors
- ==, =!과 같은 연산자만 사용 가능
- e.g) environment = production
- ReplicaSet:
Set-based Selectors
- In, NotIn, Exists, DoesNotExist 와 같은 연산자를 사용 가능
- e.g) environment in (prod, dev)
3. Example
Replication Controller
apiVersion: v1
kind: ReplicationController
metadata:
name: myapp-rc
labels:
app: myapp
type: front-end
spec:
template: # template 아래에 Pod에 대한 내용이 담긴다.
metadata:
name: myapp-pod
labels:
app: myapp
type: front-end
spec:
containers:
- name: nginx-container
image: nginx
**replicas: 3**
selector:
app: myapp
ReplicaSet
- ReplicaSet은 selector 정의가 반드시 필요하다.
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: myapp-replicaset
labels:
app: myapp
type: front-end
spec:
template:
metadata:
name: myapp-pod
labels:
app: myapp
type: front-end
spec:
containers:
- name: nginx-container
image: nginx
replicas: 3
selector: # selector를 정의하면, 특정 label의 Pod 장애를 ReplicaSet에게 맡길 수 있다.
matchLabels:
app: myapp
# or
selector:
matchExpressions:
- key: app
operator: In
values:
- myapp
- yourapp
4. Command
ReplicaSet 관련 Commands
# ReplicaSet에 대한 설명
kubectl explain replicaset
# 생성
kubectl create replicaset replicaset-test --image=nginx --dry-run=client -o yaml > replicaset-test.yaml
kubectl create -f replicaset-definition.yaml
# 리스트
kubectl get replicaset # rs
# 삭제
kubectl delete replicaset myapp-replicaset
# 수정 or 업데이트
kubectl replace -f replicaset-definition.yaml
# 스케일
kubectl scale --replicas=6 -f replicaset-definition.yaml
## ReplicaSet의 replicas를 업데이트하는 방법
## Imperative 방식
# definition 파일의 replicas를 6으로 수정 후 반영
kubectl replace -f replicaset-definition.yaml
# kubectl scale 사용
kubectl scale —replicas=6 -f replicaset-definition.yaml
kubectl scale —replicas=6 replicaset myapp-replicaset
## Declarative 방식 (yaml 파일의 replicas를 6으로 수정)
kubectl apply -f replicaset-definition.yaml
'스터디 > DevOps' 카테고리의 다른 글
[DevOps] Jupyterhub에서 Copilot&Copilot Chat 사용하기 (1) | 2023.12.24 |
---|---|
[Kubernetes] #3 Pod (2) | 2022.10.08 |
[Kubernetes] #2 Kubernetes Architecture (0) | 2022.09.29 |
[Kubernetes] #1 Kubernetes(쿠버네티스) 개요 및 가상화 기술 (0) | 2022.09.29 |
[Kubernetes] 쿠버네티스(Kubernetes)에서 주피터허브(JupyterHub)에 Random Port 설정하기 (0) | 2022.04.17 |