Notice
Recent Posts
Recent Comments
Link
«   2024/09   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
Tags
more
Archives
Today
Total
관리 메뉴

클라우드 엔지니어 꿈나무

Kubernetes(K8S) 따배쿠 kubectl command / pod 생성하기 본문

kubernetes

Kubernetes(K8S) 따배쿠 kubectl command / pod 생성하기

새싹싹이 2023. 10. 9. 15:57

kubectl [command] [TYPE] [NAME] [flags]

command = 자원에 실행할 명령 ex) create, get, delete, edit ...

TYPE = 자원의 타임 ex) node, pod, service ...

NAME = 자원의 이름

flags = 부가적으로 설정할 옵션 ex) --help, -o options

 

kubectl --help]

kubectl command --help

kubectl run <자원 이름> <옵션>

kubectl create -f obj.yml

kubectl apply -f obj.yml

kubectl get <자원 이름> <객체 이름>

kubectl describe <자원 이름> <객체 이름>

kubectl delete pod main

 

- 시스템 5 계열의 command option

-- bsd 계열의 명령 옵션 (명령어, 옵션을 좀 풀어서 씀)

 

kubectl delete pod webserver --grace-period=0 --force => pod 강제 종료 --grace-period 삭제되기 전까지 대기 시간

kubectl run webser --image nginx --port 80

kubectl get pods -o wide 

curl 10.36.0.1

elinks 10.36.0.1(:80) 

<<참고>>

elinks 다운로드  (메뉴 베이스의 웹 브라우저)  

yum install -y elinks

yum install -y update

 

kubectl get pods webser -o yaml

kubectl get pods webser -o json

 

 

kubectl create deployment http --image httpd --replicas 3

 

index.html 수정하기

kubectl exec webserver -it -- /bin/bash

cd /usr/share/nginx/html/

# echo "KANG web" > index.html

# exit

# curl 10.36.0.1

# kubectl logs webserver => 로그 확인가능 

 

# kubectl port-forward webserver 8080:80 => 쿠버네티스 외부 사용자들이  접속할 수 있도록 port forwarding 

하기 상태로 정지해있음

master 새 창 열어 # curl localhost:8080

 

Replicas 개수 바꾸기

# kubectl edit deployment http => 동작 중인 객체 수정

하기 창에서 replicas 5개로 수정

<<참고>>

# kubectl edit 동작 중인 object 수정

 

# kubectl run webserver --image nginx --port 80 --dry-run => dry-run이 실행 가능한지 확인

# kubectl run webserver --image nginx --port 80 --dry-run -o yaml => yaml 포맷으로도 볼 수 있음 

# kubectl run webserver --image nginx --port 80 --dry-run -o yaml > webser-pod.yaml => yaml 파일로 저장

# vi webser-pod.yaml

하기와 같이 생성된 것 확인 가능

상기 vi 파일 중 불필요 부분 제거 및 이름 수정 

apiVersion: v1
kind: Pod
metadata:
  labels:
    run: web
  name: webs
spec:
  containers:
  - image: nginx
    name: webs
    ports:
    - containerPort: 80

# kubectl create -f webser-pod.yaml  => yaml 파일로 파드 생성

 

<<참고>>

dd 명령 반복할 때는 . 으로 대체 가능 (repeat)

 

 

<<참고 영상>>

youtube 따라 배우는 쿠버네티스 참고

https://youtu.be/QGF7igBYSEI?si=rS-S_5UOEc_v7x3p