공부합시다!/Kubernetes

Kubernetes (K8S): App이 실행되지 않는 image(Centos, Ubuntu등) 실행

간서치 2022. 12. 28. 00:12
728x90

container 기술들과는 다르게 K8S에서는 Application들이 실행되지 않는 - docker 에서는 -it 옵션으로 실행 - image를 실행하기 위해서는 별도의 작업이 필요하게 됩니다. 흡사 App 실행되는 것처럼 while문을 이용해서 무한루프를 발생시키는 작업입니다.

 

while true; do sleep 1000; done

1000초에 한번씩 아무작업 없이 실행하라는 의미입니다.

process가 계속 실행중이기 때문에 app처럼 kubernetes 속이는 작업을 하게 됩니다.

 

1. centos.yml 작성

# vi centos.yml

apiVersion: v1
kind: Pod
metadata:
  name: os
spec:
  containers:
  - name: centos
    image: centos:7
    command: ["/bin/bash","-c","while true; do sleep 1000; done"]
    imagePullPolicy: IfNotPresent

 

2. 실행 및 test

# kubectl apply -f centos.yml
# kubectl get pod
# kubectl describe pod os

 

3. kubectl 명령어로 실행

 3.1. 명령어 실행은 의외로 간단합니다.

# kubectl run centos -it --image=centos:7 -- bash
# exit
# kubectl get pod
# kubectl exec centos -it -- bash
# hostname
# exit
# kubectl get pod

 

4. pod 삭제가 안될때

 4.1. 간혹 장시간에 걸쳐 pod가 삭제 되지 않을 경우

# kubectl -n <namespace> delete pods --grace-period=0 --force <pod_name>

 

 

728x90