Kim-Baek 개발자 이야기

Kubernetes Pod 본문

개발/k8s

Kubernetes Pod

킴백 개발자 2020. 9. 1. 21:55

Kubernetes Pod

 

QwiklabsOrchestrating the Cloud with Kubernetes을 공부 하면서 정리한 내용이다.

 

Pod

Kubernetes의 Pod 개념은 중요하다.

  • 하나 또는 그 이상의 Container의 Collection
  • 관리와 Networking을 위해서 같이 묶여 있는 Continer의 Group이다.
  • Storage와 Network를 공유한다.

 

Creating Pod

 

Pod 생성을 위한 매니페스트 파일을 작성해주고, kubectl create -f 명령어를 통해 생성 할 수 있다.

 

kubectl create -f pods/[Manifest].yaml

 

또는 kubectl run 명령어를 통해 DeploymentPod를 함께 생성 할 수도 있다.

 

kubectl run hello-node --image=gcr.io/[PROJECT_ID]/node-app:0.01

Kubernetes for GCP 실습 에서 사용한 방법

 

생성 된 Podkubectl get pods 명령어를 통해 확인 가능하다.
(service, deployment, ingress.. 등등 다른 object, resource 역시 kubectl get 명령어를 사용 할 수 있다.)

 

Interacting with Pods

기본적으로 생성 된 Pod에 대한 접근은 private IP 주소를 통해서만 접근이 가능하며, 클러스터 외부에서는 접근이 불가능하다.

 

kubectl port-foward 명령어를 통해 local port와 pod내의 port와 맵핑이 가능하다.

kubectl port-forward monolith 10080:80

monolith 라는 pod가 생성되어 있을때

 

kubectl logs 명령어를 통해 Pod에 대한 로그들을 확인 할 수 있다.

kubectl logs monolith

kubectl logs -f monolith

 

kubectl exec 명령어를 통해 Pod에 직접 interaction도 가능하다.


docker exec 명령어를 통해 컨테이너 내부와 interaction 하는 개념이라고 생각하면 된다.

# Interacting pod
kubectl exec monolith --stdin --tty -c monolith /bin/sh

# Interacting container
docker exec -it ubuntu_bash bash

 

Adding Labels to Pods

뒤에 나올 Service에서도 사용하는 Label을 Pod에 추가하는 방법을 알아보자.

kubectl label 명령어를 통해 label을 추가할 수 있다.

# secure-monolith Pod에 secure=enabled 라벨 추가하기
kubectl label pods secure-monolith 'secure=enabled'

# secure-monolith Pod의 라벨 확인하기
kubectl get pods secure-monolith --show-labels

 

Reference

반응형

'개발 > k8s' 카테고리의 다른 글

Kubernetes StatefulSets  (0) 2020.09.20
Kubernetes Service, Deployment  (0) 2020.09.02
Comments