본문 바로가기
DevOps 스터디 - 도커 & K8S

4주차. Pod, Replica Set, Deployment

by yeongki0944 2025. 4. 6.

Objects In Kubernetes

https://medium.com/devops-mojo/kubernetes-objects-resources-overview-introduction-understanding-kubernetes-objects-24d7b47bb018

Kubernetes — Objects (Resources/Kinds) Overview
https://medium.com/devops-mojo/kubernetes-objects-resources-overview-introduction-understanding-kubernetes-objects-24d7b47bb018


 

https://iximiuz.com/en/posts/kubernetes-api-structure-and-terminology/

Kubernetes API Basics - Resources, Kinds, and Objects
https://iximiuz.com/en/posts/kubernetes-api-structure-and-terminology/

 


https://jayendrapatil.com/kubernetes-components/

 


https://kubernetes.io/docs/concepts/overview/working-with-objects/

Understanding Kubernetes objects


Kubernetes objects are persistent entities in the Kubernetes system.

A Kubernetes object is a "record of intent"
의도의 기록 
--once you create the object, the Kubernetes system will constantly work to ensure that the object exists. 

By creating an object, you're effectively telling the Kubernetes system what you want your cluster's workload to look like; this is your cluster's desired state.

To work with Kubernetes objects—whether to create, modify, or delete them—you'll need to use the Kubernetes API.

 

Object spec and status

Almost every Kubernetes object includes two nested object fields that govern the object's configuration: the object spec and the object status. 

apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
namespace: default
spec: # 원하는 상태 (desired state)를 정의하는 중첩 객체 필드
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec: # 또 다른 중첩 객체 필드 (Pod 템플릿의 spec)
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
resources:
limits:
memory: "128Mi"
cpu: "500m"
status: # 현재 상태 (current state)를 나타내는 중첩 객체 필드
availableReplicas: 3
observedGeneration: 1
readyReplicas: 3
replicas: 3
updatedReplicas: 3
conditions:
- lastTransitionTime: "2023-04-01T10:00:00Z"
lastUpdateTime: "2023-04-01T10:00:00Z"
message: "Deployment has minimum availability."
reason: "MinimumReplicasAvailable"
status: "True"
type: "Available"

쿠버네티스 중첩 객체 필드 비교표

특성 spec status
정의 객체에 대해 원하는 상태를 정의하는 필드 객체의 현재 상태를 나타내는 필드
설정 주체 사용자가 직접 설정 쿠버네티스 시스템이 자동으로 설정 및 업데이트
목적 리소스가 어떤 상태가 되어야 하는지 선언 리소스의 실제 현재 상태 보고
변경 가능성 사용자가 언제든지 수정 가능 사용자가 직접 수정할 수 없음 (시스템만 업데이트)
시기 객체 생성 시 반드시 설정해야 함 객체 생성 후 시스템에 의해 자동 생성됨
예시 속성 (Deployment) replicas, selector, template availableReplicas, observedGeneration, conditions
관계 목표 상태를 정의 spec과의 차이에 따라 시스템이 조치를 취함
중첩 가능성 다른 객체의 spec을 포함할 수 있음 (예: Pod template의 spec) 다양한 상태 조건(conditions)을 포함할 수 있음



# Deployment 객체 예시에서의 계층 구조
Deployment
├── metadata
├── spec <-- 첫 번째 중첩 객체 필드
│ ├── replicas
│ ├── selector
│ └── template
│ ├── metadata
│ └── spec <-- 두 번째 중첩 객체 필드(Pod template의 spec)
│ └── containers
│ ├── name
│ ├── image
│ └── ...
└── status <-- 세 번째 중첩 객체 필드
├── availableReplicas
├── readyReplicas
├── replicas
└── conditions <-- 상태 내의 중첩 필드
├── type
├── status
├── reason
└── ...


https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#spec-and-status

 

Pause 컨테이너


159. [Kubernetes] Pause 컨테이너의 역할과 원리 (원문: The Almighty Pause Container)
https://blog.naver.com/alice_k106/221495126401


The Almighty Pause Container
https://www.ianlewis.org/en/almighty-pause-container

 

  • Pause 컨테이너의 목적:
    • 쿠버네티스 파드에서 모든 컨테이너의 "부모 컨테이너" 역할
    • 파드당 하나씩 실행됨 (docker ps 명령어로 확인 가능)
  • 핵심 기능 두 가지:
    • 네임스페이스 공유: 파드 내 모든 컨테이너가 공유할 네임스페이스 생성
    • 좀비 프로세스 수집: PID 1로서 고아 프로세스를 회수(reap)함
  • 구현 방식:
    • 극도로 단순한 C 프로그램으로 구현됨
    • 무한 루프로 "pause" 시스템 콜 실행
    • SIGCHLD 신호를 받으면 waitpid() 호출로 좀비 제거




 

 

Pod

출처 : 시작하세요! 도커/쿠버네티스 - 6. 쿠버네티스 시작하기(p.292)

  • apiVersion : 오브젝트의 API 버전
  • kind : 오브젝트 종류

 

 

Replica Set

https://kubernetes.io/docs/concepts/workloads/controllers/replicaset/

출처 : 시작하세요! 도커/쿠버네티스 - 6. 쿠버네티스 시작하기(p.304)

 

  • spec.template 
    • Pod를 생성할 때 사용하는 템플릿

 

https://velog.io/@gentledev10/kubernetes-replicaset

 

 

 

https://www.goglides.dev/nirajpdn/deployment-object-in-kubernetes-why-deployment-object-over-replicaset-2cnf

 

https://www.goglides.dev/nirajpdn/deployment-object-in-kubernetes-why-deployment-object-over-replicaset-2cnf

 

 

Deployment 

출처 : 쿠버네티스 안내서 (https://subicura.com/k8s/guide/deployment.html#deployment-%E1%84%86%E1%85%A1%E1%86%AB%E1%84%83%E1%85%B3%E1%86%AF%E1%84%80%E1%85%B5)







   

 

 

What component uses ReplicaSet

https://www.learnsteps.com/basics-on-kubernetes-what-exactly-is-a-replicaset/

 

 

 

 

Reference

Deployment Object in Kubernetes. Why Deployment object over ReplicaSet?
https://www.goglides.dev/nirajpdn/deployment-object-in-kubernetes-why-deployment-object-over-replicaset-2cnf

 

Deployment 만들기
https://subicura.com/k8s/guide/deployment.html#deployment-%E1%84%86%E1%85%A1%E1%86%AB%E1%84%83%E1%85%B3%E1%86%AF%E1%84%80%E1%85%B5