POD

호제로·2022년 9월 25일
0

Container

목록 보기
1/4

— example yaml

apiVersion: v1
kind: Pod
metadata:
  name: nginx
  labels:
    app: nginx
    tier: frontend
spec:
  containers:
  - name: nginx
    image: nginx

— pod create

# yaml 파일을 통해 생성하는 방법
$ kubectl apply -f pod.yml

# image를 직접 불러와 pod를 생성하는 방법
$ kubectl run {pod-name} —image=nginx —port=443

# pod를 생성하지 않고 Yaml로 추출하는 방법 
# --dry-run=client  => 해당 옵션은 실제 리소스를 생성하지 않고 테스트목적으로 실행할것을 명시하는 옵션
$ kubectl run redis --image=redis123 --dry-run=client -o yaml > pod.yaml

— pod 상세 조회
$ kubectl describe pod {newpods-x7tkz}
$ kubectl get pod --all-namespaces
= kubectl get pod -A
— pod 변경 방법(1)

$ kubectl edit pod {pod_name} 

# 만약 edit 과정에서 실패가 나는경우 수동으로 Replace 하는 방법(POD가 Running 중일때 안되는 경우도 있음)
$ kubectl edit pod {pod_name} 
  —-> failed.. /tmp/kube~~.yaml  확인

$ kubectl replace --force -f /tmp/kube~~.yaml  —> 존재하는 POD를 삭제하고 재생성 (force를 꼭 붙여야 성공함 !!) 

— POD yaml 다운 및 변경(2)

$ kubectl get pod webapp -o yaml > my-new-pod.yaml

$ vi my-net-pod.yaml —> 내용수정
$ kubectl delete pod webapp
$ kubectl create -f my-new-pod.yaml

— pod 삭제

$ kubectl delete pod webapp

Static Pod

  • Pod 중에는 노드에서 직접 생성한 Static POD가 있음(해당 POD는 POD 삭제 명령어를 통해 삭제해도 재생성 도미)
  • Static POD는 노드의 특정 위치에 Yaml 형태로 있기때문에 생성, 삭제하려면 파일을 생성, 삭제필요
(static-pod 기본 위치)
$ ls /etc/kubernetes/manifests  
  ==> static-pod.yaml들 존재
  • 간혹가다 Kubelet 설정에 따라 Static-Pod 위치가 달라질 수 있음 ( Kubelet 설정 위치: /var/lib/kubelet/config.yaml )
$ vi /var/lib/kubelet/config.yaml 
…
staticPodPath=/etc/kubernetes/manifests  ==> 위치가 달라질 수 있음 
…

— Container Shell(Exec) 접속

$ kubectl exec -it {pod-name} -- {command} 
$ kubectl exec -it webapp-mysql-84fbfc644f-6tdrc -n gamma -- /bin/sh    # ssh 접속
ex) kubectl exec -it elastic-stack -- cat /log/app.log

— Init Container 사용

  • POD내에 Init Container를 통해서 실제 Container 수행이전에 수행해야할 작업들을 지정할 수 있음
  • initContainers key 사용
apiVersion: v1
kind: Pod
metadata:
  name: red
spec:
  containers:
  - command:
    - sh
    - -c
    - echo The app is running! && sleep 3600
    image: busybox:1.28
    name: red-container
  initContainers:
  - command:
    - sh
    - -c
    - sleep 20
    image: busybox

— Static POD 에 명령어 추가하여 생성(Imperative 방법)

$ k run static-busybox --image busybox -o yaml --dry-run=client --command -- sleep 1000 > static-busybox.yaml
profile
Cloud Infra Structure & Developer

0개의 댓글