Replication Controller vs ReplicaSet -> ReplicaSet 을 권장한다
apiVersion: v1
kind: ReplicationController
metadata:
	name: myapp-rc
	labels: 
		app: myapp
		type: front-end
spec:
	# POD template
POD template에 들어가는 내용 - 이전 게시물# pod-definition.yml apiVersion: v1 # pod kind: Pod metadata: name: myapp-pod labels: app: myapp type: front-end spec: containers # Pod안에 컨테이너가 여러개이므로 - name: nginx-container # -: 1st 항목 image: nginx
# rc-definition.yml
apiVersion: v1
kind: ReplicationController
metadata: # Replication Controller
	name: myapp-rc
	labels: 
		app: myapp
		type: front-end
spec: # Replication Controller
	template: # pod template
			metadata: # pod
				name: myapp-pod
				labels:
					app: myapp
					type: front-end
			spec: # pod
				containers # Pod안에 컨테이너가 여러개이므로
					- name: nginx-container # -: 1st 항목
						image: nginx
	replicas: 3 # Replication Controller에 필요한 복제본 수
	
$kubectl create -f rc-definition.yml
$kubectl get replicationcontroller # Replication Controller 리스트
$kubectl get pods # Replication Controller로 생성된 Pod를 보고싶을 때. 
replicas: 3 으로 설정했으므로 kubectl get pods 명령어 실행 시 3개가 나옴myapp-rc로 시작됨# replicaset-definition.yml
apiVersion: apps/v1
kind: ReplicaSet
metadata: 
	name: myapp-replicaset
	labels:
		app: myapp
		type: front-end
spec:
	# POD tempalte
# replicaset-definition.yml
apiVersion: apps/v1
kind: ReplicaSet
metadata: 
	name: myapp-replicaset
	labels:
		app: myapp
		type: front-end
spec:
	template: # pod template
			metadata: # pod
				name: myapp-pod
				labels:
					app: myapp
					type: front-end
			spec: # pod
				containers # Pod안에 컨테이너가 여러개이므로
					- name: nginx-container # -: 1st 항목
						image: nginx
	replicas: 3 # 유지해야 하는 pod 개수
	selector:
		matchLabels:
			type: front-end
spec.template.metadata.labels.app 에 적은 내용들을 기본값으로 사용
Labels.tier로 획득가능한 pod를 식별하므로, yaml파일안 pod의 labels.tier정보와 맞춰줘야함
현재 파일을 가지고 create 하면 오류발생
$kubectl create -f replicaset-definition.yml
$kubectl get replicaset # 생성된 replica를 확인
$kubectl get pods
💡 replicaset을 3개 → 6개로 update하려면? (방법 3가지)
replicaset-definition.yml의 replica: 3 → 6으로 수정 후 $kubectl replace -f replicaset-definition.yml 명령어 실행
기존에 생성된 Pod들이 삭제되고 새로운 Pod들이 생성
kubectl scale --replicas=6 -f replicaset-definition.yml 명령어 실행
기존의 3개 복제본을 유지하고 새로운 3개 복제본을 생성
kubectl apply -f replicaset-definition.yml명령어 실행시 다시 3개의 복제본으로 돌아감
kubectl scale --replicas=6 replicaset mypp-replicaset 명령어 실행
$kubectl scale —replicas=6 [type] [name]
2번과 3번 방법은 어떤게 다른가요? (Answer by chatgpt)
kubectl scale --replicas=6 -f replicaset-definition.yml은 파일 내의 ReplicaSet 정의를 기반으로 변경하며,kubectl scale --replicas=6 replicaset myapp-replicaset은 ReplicaSet의 이름을 명시적으로 지정하여 변경합니다.
$kubectl create -f replicaset-definition.yml
$kubectl get replicaset
$kubectl delete replicaset myapp-replicaset
$kubectl replace -f replicaset-definition.yml
$kubectl scale -replicas=6 -f replicaset-definition.yml