Skip to main content

Deployment


Deployment

Deployment and RollingUpdate

ReplicaSet은 아래와 같은 spec을 가지고 있습니다.

  • Pod 집합을 식별하기 위한 .spec.selector
  • 유지하고 싶은 Pod 수를 지정하는 .spec.replicas
  • 새로 생성될 Pod 정보인 .spec.template

DeploymentReplicaSet을 생성하고 컨트롤하는 데 사용되는 리소스입니다. Deployment에 의해 생성된 ReplicaSet은 사용자가 직접 관리하면 안됩니다.

apiVersion: apps/v1
kind: Deployment
metadata:
name: my-deployment
spec:
replicas: 3 # 유지하고 싶은 Pod 수
minReadySeconds: 10 # readinessProbe 성공 후 최소 준비 시간, 의도적으로 업데이트 속도를 늦출 수 있음
strategy:
type: RollingUpdate # RollingUpdate(default)|Recreate
rollingUpdate:
# replicas - maxUnavailable <= 사용 가능 Pod <= replicas + maxSurge
maxSurge: 25% # 정수 또는 비율(%, ceil(replicas * maxSurge))
maxUnavailable: 25% # 정수 또는 비율(%, floor(replicas * maxUnavailable))
selector: # 관리하고 싶은 Pod의 정보
matchLabels:
app: my-app
template: # 새로 생성될 Pod
metadata:
labels: # .spec.selector에 의해 선택 될 수 있도록 설정
app: my-app
spec:
containers:
- image: [<url>/]<image>[:tag]
name: my-app
ports:
- name: http # Pod 내에서 특별해야하며, service에 의해 참조될 수 있음
containerPort: 8080
protocol: TCP # TCP(default)|UDP|SCTP

label

info

.metadata.annotation은 label처럼 selector 같은 것은 없지만 상대적으로 긴 값을 설정할 수 있습니다. 새로운 기능을 추가하기 전, spec에 추가할 값을 우선 annotation에 추가해서 테스트 해보는 경우가 있습니다.

namespace

.metadata.namespace는 클러스터 내에서 리소스 그룹을 격리하는 기능입니다. 사용자가 적은 경우 label만으로 충분 할 수 있습니다.

kubectl config set-context --current --namespace <namespace> 명령어를 통해 현재 컨텍스트의 기본 namespace를 변경할 수 있습니다.

rollout

kubectl rollout <subcommand> <resource> <name>
  • <subcommand>
    • pause: 일시 중지
    • resume: 일시 중지 해제
    • restart: 재시작
    • status: rollout이 완료될 때까지 진행 상태를 출력
    • history: revision 목록, --revision <int>을 설정하면 자세한 정보를 확인 할 수 있음
    • undo: 이전 revision 로 되돌리기, --to-revision <int>을 설정하면 해당 revision으로 되돌릴 수 있음
  • <resource>
    • deployment
    • statefulset
    • daemonset