Kubernetes가 안정적으로 동작하는 가장 큰 이유 중 하나는 Controller 기반 구조입니다.
Kubernetes는 단순히 Container를 실행하는 시스템이 아니라 현재 상태(Current State)를 원하는 상태(Desired State)로 유지하는 자동 관리 플랫폼입니다.
예:
사용자가 원하는 상태:
Web Pod 3개 실행
↓
현재 상태:
Web Pod 2개 실행
↓
Controller 감지
↓
새로운 Pod 생성
↓
원하는 상태 복구
이러한 자동 복구와 상태 관리를 담당하는 핵심 Component가 Kubernetes Controller Manager입니다.
| 구성 요소 | 역할 |
|---|---|
| Controller Manager | Cluster 상태 유지 |
| Deployment Controller | Pod Replica 관리 |
| Node Controller | Node 상태 감시 |
| Job Controller | Batch 작업 관리 |
| Endpoint Controller | Service 연결 관리 |
Controller Manager 구조를 이해하면 Kubernetes 자동화 원리와 장애 복구 방식을 깊게 이해할 수 있습니다.
Kubernetes Controller Manager란?
Controller Manager는 Kubernetes Cluster 내부에서 여러 Controller를 실행하는 Control Plane Component입니다.
주요 역할:
현재 상태 확인
↓
Desired State 비교
↓
차이 발견
↓
필요한 작업 수행
이 과정을 반복합니다.
이를 Control Loop라고 합니다.
Kubernetes Desired State와 Controller Loop
Kubernetes의 핵심 개념은 Desired State입니다.
예:
Deployment 설정:
Replica:
3
현재:
Running Pod:
2
Controller:
차이 발견
↓
Pod 1개 생성
↓
Replica 3개 유지
이 반복적인 확인 과정이 Kubernetes 자동 관리의 핵심입니다.
Kubernetes Controller Manager Architecture
구조:
User
↓
API Server
↓
etcd
↓
Controller Manager
↓
Resource 상태 확인
↓
Object 변경
↓
API Server 반영
Controller는 직접 Node를 제어하지 않고 API Server를 통해 Cluster 상태를 관리합니다.
Kubernetes Controller Manager와 API Server 관계
Controller Manager는 API Server와 통신합니다.
흐름:
Controller Manager
↓
API Server 조회
↓
etcd 데이터 확인
↓
현재 상태 분석
↓
변경 요청
↓
API Server 저장
모든 상태 변경은 API Server를 통해 이루어집니다.
Kubernetes 주요 Controller 종류
Controller Manager 내부에는 여러 Controller가 존재합니다.
| Controller | 역할 |
|---|---|
| Node Controller | Node 상태 관리 |
| Replication Controller | Replica 유지 |
| Deployment Controller | Deployment 관리 |
| StatefulSet Controller | Stateful Pod 관리 |
| Job Controller | Batch 실행 |
| CronJob Controller | 예약 작업 |
| Endpoint Controller | Service Endpoint 관리 |
| Namespace Controller | Namespace 관리 |
각 Controller가 특정 Resource를 담당합니다.
Kubernetes Node Controller
Node Controller는 Worker Node 상태를 관리합니다.
역할:
Node 상태 확인
↓
Heartbeat 확인
↓
문제 감지
↓
Node 상태 변경
예:
Node 장애
↓
NotReady 상태 변경
앞서 학습한 Node NotReady 문제와 연결됩니다.
Kubernetes Deployment Controller
Deployment Controller는 Application 배포 상태를 관리합니다.
예:
Desired:
Replica 5개
현재:
Replica 3개
Controller:
↓
ReplicaSet 생성
↓
Pod 추가
↓
5개 유지
Rolling Update와 Rollback도 Deployment Controller와 관련됩니다.
Kubernetes ReplicaSet Controller
ReplicaSet은 Pod 개수를 유지합니다.
구조:
Deployment
↓
ReplicaSet
↓
Pod
Pod 삭제:
↓
ReplicaSet 감지
↓
새로운 Pod 생성
항상 원하는 개수를 유지합니다.
Kubernetes StatefulSet Controller
Stateful Application을 관리합니다.
특징:
- 고유 Pod 이름
- 순서 보장
- Stable Network Identity
예:
Database Cluster
↓
StatefulSet Controller
↓
mysql-0
mysql-1
mysql-2
Database 운영에서 중요합니다.
Kubernetes Job Controller
Job Controller는 일회성 작업을 관리합니다.
예:
Data Migration
↓
Job 생성
↓
Pod 실행
↓
완료 상태 기록
Batch 작업 운영에 사용됩니다.
Kubernetes CronJob Controller
CronJob Controller는 예약 작업을 관리합니다.
예:
매일 새벽 Backup 실행
구조:
CronJob
↓
Job 생성
↓
Pod 실행
↓
작업 완료
자동화 작업에 활용됩니다.
Kubernetes Service Endpoint Controller
Service와 Pod 연결을 관리합니다.
구조:
Service
↓
Selector 확인
↓
Pod 검색
↓
Endpoint 생성
Service 연결 문제가 발생하면 Endpoint 상태를 확인해야 합니다.
Kubernetes Controller Manager 장애 분석
Controller 문제가 발생하면 Resource 자동 복구가 동작하지 않습니다.
확인:
Controller 상태:
kubectl get pods -n kube-system
Log 확인:
kubectl logs kube-controller-manager-pod -n kube-system
확인 항목:
- API Server 연결
- Certificate
- etcd 연결
- Permission
Control Plane 상태를 확인해야 합니다.
Kubernetes Controller Manager High Availability
Production 환경에서는 Control Plane도 고가용성이 필요합니다.
구조:
Control Plane 1
Control Plane 2
Control Plane 3
↓
Controller Manager 실행
↓
Leader Election
하나의 Controller만 실제 작업을 수행합니다.
Kubernetes Leader Election
여러 Controller Manager가 있어도 동시에 같은 작업을 수행하지 않습니다.
방식:
Controller Manager 여러 개 실행
↓
Leader 선택
↓
Leader만 Active
↓
장애 발생
↓
새 Leader 선택
고가용성을 제공합니다.
Kubernetes Controller Manager와 Monitoring
운영 환경에서는 Controller 상태를 감시해야 합니다.
확인:
- Controller Error
- API Request
- Reconciliation 실패
- Resource 생성 실패
Prometheus Monitoring과 연결할 수 있습니다.
Kubernetes Controller Manager와 자동 복구
Kubernetes 자동 복구 흐름:
Application 장애
↓
Controller 감지
↓
Desired State 비교
↓
새 Resource 생성
↓
서비스 복구
이 구조가 Kubernetes Self-Healing의 핵심입니다.
Kubernetes Controller Manager 운영 전략
Production 환경에서는:
Resource 설계
↓
Controller 동작 이해
↓
Monitoring 구성
↓
Alert 설정
↓
장애 대응 준비
자동 운영 환경을 구축할 수 있습니다.
Kubernetes Controller Manager 장점
| 장점 | 설명 |
|---|---|
| 자동 복구 | 상태 유지 |
| 운영 자동화 | 수동 관리 감소 |
| 확장성 | 대규모 Cluster 지원 |
| 안정성 | Desired State 유지 |
Controller 구조는 Kubernetes의 핵심 철학입니다.
자주 묻는 질문
Controller Manager가 Container를 실행하나요?
아닙니다.
Controller Manager는 상태 관리 역할을 하고 실제 실행은 kubelet이 담당합니다.
Controller가 없으면 Kubernetes가 동작하지 않나요?
기본적인 API 동작은 가능하지만 자동 복구와 상태 유지 기능이 사라집니다.
Deployment와 Controller Manager는 같은 것인가요?
아닙니다.
Deployment는 Resource이고 Deployment Controller가 이를 관리합니다.
마무리
Kubernetes Controller Manager는 Cluster의 원하는 상태를 유지하고 자동 복구를 수행하는 핵심 Control Plane Component입니다.
| 구성 요소 | 역할 |
|---|---|
| Controller Manager | Controller 실행 |
| Deployment Controller | 배포 관리 |
| Node Controller | Node 상태 관리 |
| Job Controller | Batch 관리 |
| Endpoint Controller | Service 연결 |
Controller 구조를 이해하면 Kubernetes가 어떻게 자동으로 Application 상태를 유지하는지 이해할 수 있습니다.
다음 글에서는 Kubernetes 데이터를 저장하는 가장 중요한 Component인 Kubernetes etcd 완벽 가이드! Cluster 상태 저장소와 Backup 구조 이해하기를 진행하겠습니다.