4 minute read

일지

특이사항 없음

주요 키워드

Pod
Lable
Selector
Annotation
Namespace

오늘의 할일

  • 220519 TIL 작성
  • AWS 스터디 진행

수업 정리

Pod

파드의 생명주기 / Probe

파드의 내부 항목 중 .status.phase : 현재 파드의 상태 표시

파드의 상태 종류 Pending 스케줄링 되기 전 파드가 스케줄러에 의해 승인은 되었으나 아직 실행 전 스케줄링 후 생성되었으나 이미지 pull 중인 상태 Running 현재 정상적으로 실행중인 상태 컨테이너가 구동중인 상태 시작된 상태 / 재시작중인 상태 Succeeded 재시작되도록 지정되지 않은 파드가 정상적으로 종료되었을 때 Failed 정상적이 아닌 상태로 종료되었을 때 Unknown 파드의 상태를 파악할 수 없을 때(노드와의 통신 오류 등)

파드 내 컨테이너의 상태 Waiting Running, Terminated이 아닌 상태 만들어지는 중 Reason 항목에 세부 이유 표시됨 Running 실행중 Terminated 오류 등에 의하여 중지 된 상태 Reason 항목에 세부 이유 표시됨

재시작 정책 apiVersion: v1 kind: Pod metadata: name: test-pod spec: restartPolicy: Always containers:

  • image: c1t1d0s7/myweb name: test-pod-container ports:
    • protocol: TCP containerPort: 8080 apiVersion: v1 kind: Pod metadata: name: hello-world spec: containers:
  • name: hello-world-container image: hello-world apiVersion: v1 kind: Pod metadata: name: hello-world2 spec: restartPolicy: Never containers:
  • name: hello-world-container image: hello-world apiVersion: v1 kind: Pod metadata: name: hello-world3 spec: restartPolicy: OnFailure containers:
  • name: hello-world-container image: hello-world apiVersion: v1 kind: Pod metadata: name: false-pod spec: containers:
  • name: false-pod-container image: ubuntu command: [“false”] restartPolicy: OnFailure

기본 파드의 정상/비정상 판단 방식 컨테이너의 프로세스가 정상적으로 종료/실행중 : 정상 컨테이너의 프로세스가 비정상종료: 비정상

사용자의 설정에 따른 정상 비정상 판단 방식 : Probe

Probe의 종류 Liveness Probe Readiness Probe Startup Probe

Liveness Probe 현재 파드가 정상 동작하고있는가 판단하는 Probe 별도의 판단기준을 설정하여 정상 여부를 체크 (다른 probe도 동일) 특정 경로로 http GET 요청 전송 2xx, 3xx 등의 응답을 수신할 경우 정상 httpGet TCP Socket 연결을 통해 정상 여부를 체크 3way handshake 과정이 정상적으로 수립되는지 확인 tcpSocket 테스트를 위한 명령을 별도로 수행 명령 실행의 종료상태에 따라 확인 exec

Liveness Probe 예시 apiVersion: v1 kind: Pod metadata: name: pod-liveness-1 spec: containers:

  • name: pod-liveness-1-container image: ghcr.io/c1t1d0s7/go-myweb ports:
    • containerPort: 8080 protocol: TCP Liveness Probe 미적용

apiVersion: v1 kind: Pod metadata: name: pod-liveness-2 spec: containers:

  • name: pod-liveness-2-container image: ghcr.io/c1t1d0s7/go-myweb ports:
    • containerPort: 8080 protocol: TCP livenessProbe: httpGet: path: /health port: 8080 Liveness Probe 적용

apiVersion: v1 kind: Pod metadata: name: pod-liveness-3 spec: containers:

  • name: pod-liveness-3-container image: ghcr.io/c1t1d0s7/go-myweb ports:
    • containerPort: 8080 protocol: TCP livenessProbe: httpGet: path: /health?code=404 port: 8080 Liveness Probe 적용

실습용 컨테이너 이미지 활용 curl -v 192.168.9.70:8080/health // health check용으로 200 응답 curl -v 192.168.9.70:8080/health?code=404 // 지정한 code 응답

Startup Probe 컨테이너 구동 후 시작된 상태임을 체크하는 probe startup probe의 테스트를 통과한 이후에야 컨테이너가 구동중으로 판단 startup probe 테스트 통과 전까지 다른 probe가 동작하지 않음

apiVersion: v1 kind: Pod metadata: name: pod-startup spec: containers:

  • name: pod-startup-container image: ubuntu command: [“sleep”,”infinity”] ports:
    • containerPort: 8080 protocol: TCP livenessProbe: exec: command: [“test”, “-f”, “/tmp/test2”] startupProbe: exec: command: [“test”, “-f”, “/tmp/test1”] Liveness Probe + Startup Probe 적용 kubectl exec pod-startup – touch /etc/test1 kubectl exec pod-startup – touch /etc/test2 // 체크에 사용되는 파일 생성 후에는 파드 이상없이 Running 동작

참고) HTTP Method 현재 가장 많이 사용되고 있는 HTTP 1.1 버전

HTTP 요청시 사용한 방식 : Method GET 서버에게 요청한 페이지를 달라고 할 경우 요청하고자 하는 서버의 페이지 정보를 요청(경로) 보낼 내용을 URL의 파라미터로 전송 POST 서버에게 데이터를 전달할 경우 요청을 전송하고 응답 받음 보낼 내용을 HTTP BODY에 필요한 내용을 집어넣어 전송 HEAD 서버의 응답 헤더만을 요청할 경우

HTTP Status code 404 - Not Found

1xx : continue 2xx : 정상 처리된 경우(200, OK) 3xx : 일시적/영구적 변경이 있을 경우 4xx : 에러(클라이언트 에러)- 요청이 잘못됨(없는 자원 요청, 권한없음) 5xx : 에러(서버 에러) - DB연결 에러, DB 처리 에러

컨트롤러 파드 단위로 관리하는 것이 아닌, 컨트롤러를 통해 파드를 관리 파드의 복제본을 생성하여 다수의 파드를 관리

컨트롤러 레플리케이션 컨트롤러 Replication Contoller 레플리카셋 ReplicaSet 데몬셋 DaemonSet 잡 Job 크론잡 CronJob 디플로이먼트 Deployment 스테이트풀셋 StatefulSet

레플레이케이션 컨트롤러 앞으로는 없어질 예정 레플리카셋이 그 자리를 대체 파드의 복제본을 생성 파드의 개수를 유지하는 동작

레플리케이션 컨트롤러 예시 apiVersion: v1 kind: ReplicationController metadata: name: test-rc spec: replicas: 3 selector: app: myweb template: metadata: labels: app: myweb spec: containers: - name: myweb-container image: ghcr.io/c1t1d0s7/go-myweb ports: - containerPort: 8080 protocol: TCP

레플리케이션 컨트롤러 레이블 테스트 testpod.yaml apiVersion: v1 kind: Pod metadata: name: testpod labels: app: myweb spec: containers:

  • name: testpod-container image: c1t1d0s7/myweb

레플리카셋 (ReplicaSet) 레플리케이션 컨트롤러와 동일한 동작을 수행 차이점: 셀렉터 조건이 다름 레플리케이션 컨트롤러: 일치성 기준 <키>=<값> 레플리카셋: 일치성 기준 + 존재유무 + 집합성기준

레플리카셋 apiVersion: apps/v1 kind: ReplicaSet metadata: name: test-rs spec: replicas: 3 template: metadata: labels: app: myweb spec: containers: - name: myweb-container image: ghcr.io/c1t1d0s7/go-myweb ports: - containerPort: 8080 protocol: TCP apiVersion: apps/v1 kind: ReplicaSet metadata: name: test-rs spec: replicas: 3 selector: matchLabels: app: myweb template: metadata: labels: app: myweb spec: containers: - name: myweb-container image: ghcr.io/c1t1d0s7/go-myweb ports: - containerPort: 8080 protocol: TCP

셀렉터 형식

일반적인 키=값 일치성 조건 selector: matchlabels: 키 존재유무 (키가 있을 때) selector: matchExpressions: - key: <키> operator: Exists // 키가 존재할 때 키 존재유무 (키가 없을 때) selector: matchExpressions: - key: <키> operator: DoesNotExists // 키가 존재할 때 레이블의 집합성 조건 만족여부 (대상 중 포함될 때) selector: matchExpressions: - key: <키> operator: In values: - <값1> - <값2> - … 레이블의 집합성 조건 만족여부 (대상 중 포함되지 않을 때) selector: matchExpressions: - key: <키> operator: NotIn values: - <값1> - <값2> - …

matchExpressions 사용시 여러 조건을 AND(&)의 형식으로 함께 적용 가능 selector: matchExpressions:

<첫 번째="" 조건=""> <두 번째="" 조건="">

Categories:

Updated:

Leave a comment