KILLERCODA - CKAD - ReadinessProbe 오답노트

hyereen·2025년 1월 31일

Kubernetes

목록 보기
40/53

2
Make the Deployment ready.
Exec into the Pod and create file /tmp/ready .
Observe that the Pod is ready.

정답

controlplane $ cat space.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: space-alien-welcome-message-generator
  name: space-alien-welcome-message-generator
spec:
  replicas: 1
  selector:
    matchLabels:
      app: space-alien-welcome-message-generator
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: space-alien-welcome-message-generator
    spec:
      containers:
      - image: httpd:alpine
        name: httpd
        resources: {}
        readinessProbe:
          exec:
            command:
            - stat
            - /tmp/ready
          initialDelaySeconds: 10
          periodSeconds: 5
status: {}
controlplane $ k get po
NAME                                                     READY   STATUS    RESTARTS   AGE
space-alien-welcome-message-generator-676884c5db-9vsts   0/1     Running   0          21m
controlplane $ k exec space-alien-welcome-message-generator-676884c5db-9vsts -- touch /tmp/ready
controlplane $ k get po
NAME                                                     READY   STATUS    RESTARTS   AGE
space-alien-welcome-message-generator-676884c5db-9vsts   1/1     Running   0          22m

풀이

  • Deployment에서 ReadinessProbe는 /tmp/ready라는 파일을 찾기 위해 stat 명령을 사용하고 있음
  • stat는 리눅스/유닉스 시스템에서 파일이나 디렉토리의 상태 정보를 출력하는 명령어
  • initialDelaySeconds: 10은 Pod가 시작된 후 10초 동안 기다린 후 ReadinessProbe를 실행하라는 의미
  • periodSeconds: 5는 이후에 5초마다 ReadinessProbe를 실행하여 /tmp/ready 파일이 존재하는지 확인
  • "Make the Deployment ready." 라는 말은, Deployment에 속한 Pod가 준비 상태가 되도록 해야 한다는 의미 -> Pod 안에 /tmp/ready라는 파일이 존재해야 함 그 파일이 ReadinessProbe에 의해 확인되면, Pod는 준비 상태로 간주됨
  • kubectl exec 명령을 사용하여 해당 Pod에 접속 -> 접속한 후, /tmp/ready라는 파일을 생성해야 함
  • exec는 Kubernetes에서 Pod 내부에서 명령어를 실행하는 데 사용되는 명령어
    • 사용법: kubectl exec <Pod 이름> -- <명령어>
  • touch는 지정한 경로에 파일이 없으면 새로운 빈 파일을 생성

0개의 댓글