—- 사용:, # , { , }, [ 등이 포함되면 따옴표로 감싸는게 안전.apiVersion: <그룹/버전> # 예: apps/v1, v1, route.openshift.io/v1
kind: <오브젝트종류> # 예: Deployment, Service, Route, ConfigMap, Secret ...
metadata:
name: <이름>
namespace: <네임스페이스> # 생략 시 현재 컨텍스트 네임스페이스
labels: # 선택: 검색/선택/그룹화에 핵심
app.kubernetes.io/name: myapp
app.kubernetes.io/instance: myapp
app.kubernetes.io/part-of: mysuite
annotations: # 선택: 메타 정보(도구/오퍼레이터가 읽음)
spec: # 각 리소스별 “동작 정의”의 핵심
# status: # 컨트롤 플레인이 채움(사용자가 작성 X)
oc -n <ns> 로 지정apiVersion: v1
kind: Pod
metadata:
name: hello-pod
labels:
app.kubernetes.io/name: hello
spec:
serviceAccountName: default
restartPolicy: Always
terminationGracePeriodSeconds: 30
nodeSelector: # 선택: 특정 노드에 스케줄 고정
node-role.kubernetes.io/worker: ""
tolerations: # 선택: taint가 있는 노드에 허용
- key: "dedicated"
operator: "Equal"
value: "batch"
effect: "NoSchedule"
securityContext: # Pod 레벨 보안(파일권한, FS ReadOnly 등)
runAsNonRoot: true
imagePullSecrets: # 프라이빗 레지스트리 사용 시
- name: regcred
containers:
- name: app
image: registry.example.com/team/hello:1.0
imagePullPolicy: IfNotPresent
ports:
- name: http
containerPort: 8080
env: # 단일 키-값
- name: LOG_LEVEL
value: "info"
envFrom: # ConfigMap/Secret 전체를 환경변수로
- configMapRef:
name: hello-config
- secretRef:
name: hello-secret
resources: # 리소스 요청/제한(스케줄링/품질에 중요)
requests:
cpu: "100m"
memory: "128Mi"
limits:
cpu: "500m"
memory: "256Mi"
readinessProbe: # 트래픽 받기 전 헬스체크
httpGet:
path: /healthz
port: http
initialDelaySeconds: 3
periodSeconds: 5
livenessProbe: # 프로세스 살펴보고 필요 시 재시작
httpGet:
path: /live
port: http
initialDelaySeconds: 10
periodSeconds: 10
startupProbe: # 느린 스타트업 보호(선택)
httpGet:
path: /start
port: http
failureThreshold: 30
periodSeconds: 5
volumeMounts:
- name: data
mountPath: /data
volumes:
- name: data
persistentVolumeClaim:
claimName: mypvc
중요 포인트
containers[].porots[].name을 Service targetPort(이름) 로 참조하면 포트 번호 변경에도 안전”resource.requests는 스케줄러가 자리 배정할 때 중요”