Kubernetes

[Minikube] Pod 생성

uuuhhh 2022. 11. 12. 14:14

⚠️ Local Minikube 환경에서 진행하였습니다. ⚠️

 

▪︎ Pod 생성


apiVersion: v1
kind: Pod
metadata:
  name: cn-app-pod
  labels:
    name: cn-app-pod
spec:
  containers:
  - name: cn-app
    image: uh2959/cn-action
    resources:
      limits:
        memory: "128Mi"
        cpu: "500m"

 

  • YAML 매니페스트 파일로 파드 생성

 

  • 근데 갑자기 Error 떴다가.. Running이 되었다가.. 오락가락..

 

  • log를 보려고 했는데 갑자기 자바 버전이 안 맞는다고 에러..
  • 이젠 또 파드 상태가 CrashLoopBackOff ?
💡 CrashLoopBackOff : 파드가 시작과 비정상 종료를 연속해서 반복하는 상태

 

 

  • 자바 버전 매칭표를 찾아보았다. (17 = 61)

 

  • 흠.. 나는 자바 17로 컴파일을 하였는데 도커 빌드 파일은 JDK 버전 15로 작성했..
FROM openjdk:17
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","app.jar"]

 

  • Git Action으로 성공적으로 빌드 마치고
  • logs 명령어를 치니 관련 에러 미발생

 

  • 그래도 아직 오락가락 상태는 여전..

 

  • describe 명령어를 이용해 파드의 정보 확인
  • OOMKilled 로 인해 강제 종료당한 것을 확인
💡 OOMKilled : Out Of Memory Killed ( 메모리 사용 초과 )
$ k describe pod cn-app-pod
Name:         cn-app-pod
Namespace:    default
Priority:     0
Node:         minikube/192.168.49.2
Start Time:   Sun, 18 Sep 2022 22:26:37 +0900
Labels:       name=cn-app-pod
Annotations:  <none>
Status:       Running
IP:           172.17.0.5
IPs:
  IP:  172.17.0.5
Containers:
  cn-app:
    Container ID:   docker://ff60572d7d3a845506447e4ed05a6067907581b36fb57cabe10b202375200d88
    Image:          uh2959/cn-action
    Image ID:       docker-pullable://uh2959/cn-action@sha256:17b35c7aa23fea81687dd8e4884fba472edbecd3ad22a67c039aeee83e268f74
    Port:           <none>
    Host Port:      <none>
    State:          Waiting
      Reason:       CrashLoopBackOff
      Last State:   Terminated
      Reason:       OOMKilled
      Exit Code:    137
      Started:      Sun, 18 Sep 2022 22:30:24 +0900
      Finished:     Sun, 18 Sep 2022 22:30:33 +0900
    Ready:          False
    Restart Count:  5
    Limits:
      cpu:     500m
      memory:  128Mi
    Requests:
      cpu:        500m
      memory:     128Mi
    Environment:  <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-p98cg (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             False
  ContainersReady   False
  PodScheduled      True
Volumes:
  kube-api-access-p98cg:
    Type:                    Projected (a volume that contains injected data from multiple sources)
    TokenExpirationSeconds:  3607
    ConfigMapName:           kube-root-ca.crt
    ConfigMapOptional:       <nil>
    DownwardAPI:             true
QoS Class:                   Guaranteed
Node-Selectors:              <none>
Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                             node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type     Reason     Age                   From               Message
  ----     ------     ----                  ----               -------
  Normal   Scheduled  6m11s                 default-scheduler  Successfully assigned default/cn-app-pod to minikube
  Normal   Pulled     6m8s                  kubelet            Successfully pulled image "uh2959/cn-action" in 2.457064459s
  Normal   Pulled     5m56s                 kubelet            Successfully pulled image "uh2959/cn-action" in 2.431473667s
  Normal   Pulled     5m28s                 kubelet            Successfully pulled image "uh2959/cn-action" in 3.378104626s
  Normal   Started    4m49s (x4 over 6m8s)  kubelet            Started container cn-app
  Normal   Pulled     4m49s                 kubelet            Successfully pulled image "uh2959/cn-action" in 2.501880876s
  Normal   Pulling    4m (x5 over 6m11s)    kubelet            Pulling image "uh2959/cn-action"
  Normal   Created    3m57s (x5 over 6m8s)  kubelet            Created container cn-app
  Normal   Pulled     3m57s                 kubelet            Successfully pulled image "uh2959/cn-action" in 2.635003668s
  Warning  BackOff    66s (x18 over 5m46s)  kubelet            Back-off restarting failed container

 

  • 그래서 메모리 / CPU 할당을 두 배로 늘림 + 자원 요청 값도 추가
apiVersion: v1
kind: Pod
metadata:
  name: cn-app-pod
  labels:
    name: cn-app-pod
spec:
  containers:
  - name: cn-app
    image: uh2959/cn-action
	resources:
		 limits:
		   memory: "256Mi"
		   cpu: "500m"
	     requests:
	       memory: "128Mi"
	       cpu: "250m"

 

  • 잘 살아있음