Jay's Cookbook
Menu
  • Tags
  • Categories
  • Projects
Computer Science
OS
Network
Data Structure
Algorithm
Language
Code Architecture
Python
Javascript
Typescript
Java
Backend
Backend Theory
TypeORM
Node.js
NestJS
FastAPI
Frontend
HTML/CSS
React
Next.js
Data Engineering
DE Theory
MySQL
MongoDB
Elastic
Redis
Kafka
Spark
Airflow
AI
Basic
Pytorch
NLP
Computer Vision
Data Analytics
Statistics
Pandas
Matplotlib
DevOps
Git
Docker
Kubernetes
AWS
Kubernetes Series [Part7]: Pod로 배우는 kubectl 명령어
devops
kubernetes

Kubernetes Series [Part7]: Pod로 배우는 kubectl 명령어

Jay Kim
Jay Kim 29 Jan 2022
Kubernetes Series [Part6]: Volume Kubernetes Series [Part8]: Replicaset로 배우는 kubectl 명령어

Table of Contents

  • 환경변수
  • 네트워크
    • 파드내에 컨테이너끼리 통신
    • 서로 다른 파드의 컨테이너간 통신
  • 라벨링
  • 배포할 노드 지정
  • 파드 삭제하기

환경변수

apiVersion: v1
kind: Pod
metadata:
  name: hello-app
spec:
  containers:
  - name: hello-app-con
    image: yoonjeong/hello-app:1.0
    ports:
    - containerPort: 8080
    resources:
      limits:
        memory: "128Mi"
        cpu: "100m"
kubectl apply -f ./hello-app/pod.yaml
kubectl get pods -o wide

kubectl exec -it hello-app -- /bin/sh
env

apiVersion: v1
kind: Pod
metadata:
  name: hello-app
spec:
  containers:
  - name: hello-app-con
    image: yoonjeong/hello-app:1.0
    ports:
    - containerPort: 8080
    env:
      - name: MY_NAME
        value: "Jay"
    resources:
      limits:
        memory: "128Mi"
        cpu: "100m"
env

kubectl get pod hello-app -o json
  • 크게 metadata, spec, status 항목이 있음

apiVersion: v1
kind: Pod
metadata:
  name: hello-app
spec:
  containers:
  - name: hello-app-con
    image: yoonjeong/hello-app:1.0
    ports:
    - containerPort: 8080
    env:
      - name: MY_NAME
        value: "Jay"
      - name: POD_IP
        valueFrom:
          fieldRef:
            fieldPath: status.podIP
      - name: NODE_IP
        valueFrom:
          fieldRef:
            fieldPath: status.hostIP
      - name: NODE_NAME
        valueFrom:
          fieldRef:
            fieldPath: spec.nodeName
    resources:
      limits:
        memory: "128Mi"
        cpu: "100m"
env

네트워크

파드내에 컨테이너끼리 통신

apiVersion: v1
kind: Pod
metadata:
  name: blue-green-app # Pod의 호스트명
spec:
  containers:
  - name: blue-app
    image: yoonjeong/blue-app:1.0
    ports:
    - containerPort: 8080
    resources:
      limits:
        memory: "64Mi"
        cpu: "100m"
kubectl apply -f blue-green-app/pod.yaml
kubectl logs blue-green-app -c blue-app

kubectl exec -it blue-green-app -c blue-app -- /bin/sh
# 블루 앱에서 그린 앱에 localhost로 통신
curl -vs localhost:8081/tree

서로 다른 파드의 컨테이너간 통신

kubectl apply -f red-app/pod.yaml
kubectl get pods -o wide

export RED_POD_IP=$(kubectl get pod red-app -o jsonpath="{.status.podIP}")
echo $RED_POD_IP
----------------------
10.100.1.3
kubectl exec blue-green-app -c blue-app -- curl -vs $RED_POD_IP:8080/rose

kubectl port-forward blue-green-app 8080:8080
URL: localhost:8080/sky

라벨링

apiVersion: v1
kind: Pod
metadata:
  name: red-app
  labels:
    category: nature
    app: rose
spec:
  containers:
  - name: red-app
    image: yoonjeong/red-app:1.0
    ports:
    - containerPort: 8080
    resources:
      limits:
        memory: "64Mi"
        cpu: "100m"
kubectl get pods --show-labels

# (라벨간에 띄어쓰기 허용 x)
kubectl get pod -L app,category

# --selector 대신 -l 써도됨
kubectl get pod --selector app=rose -L app

kubectl get pod -l 'app in (rose,sky-and-tree)' -L app

배포할 노드 지정

# 노드 목록과 레이블 확인
kubectl get nodes
# 노드에 Label 추가
# -- 첫번째, 세번째 노드에 soil=moist
# -- 두번째 노드에 soil=dry
kubectl label node <1번째 노드> <3번째 노드> soil=moist
kubectl label node <2번째 노드> soil=dry

# soil 노드 레이블 확인
kubectl get node -L soil

apiVersion: v1
kind: Pod
metadata:
  name: red-app
spec:
  nodeSelector:
    soil: moist
  containers:
  - name: red-app
    image: yoonjeong/red-app:1.0
    ports:
    - containerPort: 8080
    resources:
      limits:
        memory: "64Mi"
        cpu: "100m"

파드 삭제하기

kubectl delete pod --all
kubectl delete pod -l app=rose
Kubernetes Series [Part6]: Volume Kubernetes Series [Part8]: Replicaset로 배우는 kubectl 명령어

You may also like

See all kubernetes
01 Feb 2022 Kubernetes Series [Part18]: Kafka on Kubernetes
devops
kubernetes

Kubernetes Series [Part18]: Kafka on Kubernetes

01 Feb 2022 Kubernetes Series [Part17]: Spark on Kubernetes
devops
kubernetes

Kubernetes Series [Part17]: Spark on Kubernetes

01 Feb 2022 Kubernetes Series [Part16]: MongoDB on Kubernetes
devops
kubernetes

Kubernetes Series [Part16]: MongoDB on Kubernetes

Jay Kim

Jay Kim

Web development, data engineering for human for the Earth. I share posts, free resources and inspiration.

Rest
Lifestyle
Hobby
Hobby
Hobby
Hobby
2025 © Jay's Cookbook. Crafted & Designed by Artem Sheludko.