werwer.txt

<aside> ๐Ÿšง TAB์„ ์‚ฌ์šฉํ•˜์—ฌ ๋ช…๋ น์–ด ์ž๋™์™„์„ฑ ์„ค์ •

# ์Šคํฌ๋ฆฝํŠธ ๋‹ค์šด
cd ; curl -sSL <http://down.cloudshell.kr/down/k8slab.sh> | bash

# alias์— ๋‹จ์ถ•ํ‚ค ๋“ฑ๋ก
cd k8s ; sh ./kubelet_alias_bash_completion.sh

</aside>

<aside> ๐Ÿ“Œ nginx pod์„ ๋งŒ๋“ค์–ด์„œ k8s์— ๋ฐฐํฌํ•˜๊ธฐ

Master์—์„œ ์ž‘์—…

# mynginx pod์„ deployment ๋ช…๋ น์–ด๋กœ ๋งŒ๋“ฌ
k create deployment mynginx --image=nginx

Untitled

โœ… ํ™•์ธ๋ฐฉ๋ฒ•

<aside> ๐Ÿšจ node2๊ฐ€ ๋ฌธ์ œ๋ฐœ์ƒ !

โœ… master์—์„œ curl 10.36.0.1 ๋ช…๋ น์–ด๋กœ pod๊ณผ ํ†ต์‹ ์ด ๋Š๊ธฐ๋Š” ๊ฒƒ์„ ํ™•์ธ

**# ์ƒˆ๋กœ์šด node๋กœ ์‹คํ–‰๋˜๊ณ  ๊ธฐ์กด node2 pod์€ ์ž๋™์ข…๋ฃŒ๋˜๋Š” ๊ฒƒํ™•์ธ**
k get pod -o wide

</aside>

</aside>

<aside> ๐Ÿ’ก pod ๊ฐฏ์ˆ˜ ๋Š˜๋ฆฌ๊ธฐ

# deployments.apps ํŒŒ์ผ์„ ์ˆ˜์ •
k edit rs deployments.apps [pod name]
k edit rs deployments.apps mynginx
# replicas : 1 -> 4๋กœ ์ˆ˜์ •
spec:
   replicas : 4
# pod 4๊ฐœ๊ฐ€ running
k get pod -o wide

</aside>

<aside> ๐Ÿ“Œ IP์ •๋ฆฌ ๋‚ด IP : 192.168.0.50/59

<aside> ๐Ÿ“Œ kubernetes ๋ช…๋ น์–ด ์ •๋ฆฌ

# kubectl edit [object] [object_name]
## ๋…ธ๋“œํฌํŠธ ๋ฒˆํ˜ธ๋ฅผ 30111๋กœ ์ˆ˜์ •ํ•˜๊ณ  ์ €์žฅํ•˜๊ณ  ๋น ์ ธ๋‚˜์˜จ๋‹ค
kubectl edit svc mygosmall1

## ๋…ธ๋“œํฌํŠธ ๋ฒˆํ˜ธ๊ฐ€ ์ˆ˜์ •๋œ ๊ฒƒ์„ ์•Œ ์ˆ˜ ์žˆ๋‹ค
kubectl get svc -o wide

## replicas๋ฅผ 2๋กœ ์ˆ˜์ •ํ•˜๊ณ  ์ €์žฅํ•˜๊ณ  ๋น ์ ธ๋‚˜์˜จ๋‹ค
kubectl edit deployment mygosmall1

## pod์ด 2๊ฐœ๋กœ ์ค„์–ด๋“ค์—ˆ๋‹ค๋Š” ๊ฒƒ์„ ์•Œ ์ˆ˜ ์žˆ๋‹ค
kubectl get pod -o wide

</aside>

<aside> ๐Ÿ“‘ YAML

โ€œ๋ฐ์ดํ„ฐ ์ค‘์‹ฌโ€

</aside>

<aside> ๐Ÿ“‘ Deployment ๋ฐ pod์„ exposeํ•˜์—ฌ ์ ‘์†

Untitled

k edit svc poly2

# ์ˆ˜์ •
selector:
	**run**: poly2

Untitled

<aside> ๐Ÿ“‘ Deployment ์ƒ์„ฑ ๋ฐ ๋…ธ์ถœ

# deployment ๋งŒ๋“ค๊ธฐ
k create deployment poly3 --image httpd --replicas 2

# NodePort type์œผ๋กœ ๋…ธ์ถœ์‹œํ‚ค๊ธฐ
k expose deployment poly3 --type NodePort --port 80

</aside>

</aside>

<aside> ๐Ÿ’ก Pod ๋‹ค๋ฃจ๊ธฐ

<aside> ๐Ÿ’ก Namespace

k8s ํŒŒ์ผ์—์„œ

# ๋ฐฉ๋ฒ• 1
k create ns globalvision

# yamlํŒŒ์ผ๋กœ ๋งŒ๋“ค๊ธฐ
k apply -f namespace.yaml

# ํ™•์ธ
k get ns
# ์ƒ์„ฑํ•œ namespace๋กœ pod ๋งŒ๋“ค๊ธฐ
k run myhome --image nginx --port 80 -n globalvision
k run mygame --image pengbai/docker-supermario --port 8080 -n globalvision

# pod ๋…ธ์ถœ
k expose pod mygame --type NodePort --port 8080 -n globalvision

# ํ™•์ธ
k get pod -n globalvision
# deployment ๋งŒ๋“ค๊ธฐ
k create deployment myhouse --image httpd --port 80 --replicas 5 -n metallb-system

# ํ™•์ธ
k get pod -n globalvision
k get all -n globalvision

<aside> โš ๏ธ namespace๋ฅผ ์ง€์šธ๋•Œ ์œ ์˜!!

๊ด€๋ จ๋œ yamlํŒŒ์ผ๊นŒ์ง€ ๋‹ค ์‚ญ์ œ๋˜๋‹ˆ ์กฐ์‹ฌ!

<aside> ๐Ÿ“Œ Namespace ๋‹จ์œ„๋กœ Resource Quota ์ƒ์„ฑ

#
kubectl create namespace quota-mem-cpu-example

#
wget <http://down.cloudshell.kr/k8s/lab/quota-mem-cpu.yaml>

#
cat quota-mem-cpu.yaml

Untitled

# namespace๋ฅผ yaml์— ์ ์šฉ
k apply -f quota-mem-cpu.yaml -n quota-mem-cpu-example

Untitled

# ์ƒˆ๋กœ์šด yamlํŒŒ์ผ
cat quota-mem-cpu-**pod**.yaml

# ์ƒˆ๋กœ์šด yamlํŒŒ์ผ namespace๋กœ ์ ์šฉ
kubectl apply -f quota-mem-cpu-pod.yaml -n quota-mem-cpu-example

Untitled

# ์ž˜ ๋Œ๊ณ  ์žˆ๋Š”์ง€ ํ™•์ธ
kubectl get pod quota-mem-cpu-demo -n quota-mem-cpu-example

# resource quota์— ๋Œ€ํ•œ ์ •๋ณด ํ™•์ธ
kubectl get resourcequota mem-cpu-demo -n quota-mem-cpu-example -o yaml

</aside>

</aside>

</aside>

<aside> ๐Ÿ’ก yaml Field

</aside>

<aside> ๐Ÿ”ฅ Pod

Master 2๊ฐœ

# 2์ดˆ๋งˆ๋‹ค pod ํ™•์ธ
watch k get pod -o wide

# nginx mypod pod ์ƒ์„ฑ
kubectl run mypod-cli --image=nginx:1.14 --port 80

Untitled

# deployment๋ฅผ ํ†ตํ•ด ์—ฌ๋Ÿฌ๊ฐœ์˜ mypod ์ƒ์„ฑ
kubectl create deployment mypod --image=nginx:1.14 --replicas=4

Untitled

# pod-nginx.yaml๋กœ mypod ๋งŒ๋“ค๊ธฐ
kubectl apply -f <http://down.cloudshell.kr/k8s/lab/pod-nginx.yaml>

Untitled

# ํ•˜๋‚˜์˜ Pod์— ์—ฌ๋Ÿฌ ๊ฐœ์˜ container๊ฐ€ ๋™์ž‘ํ•˜๋Š” pod ์ƒ์„ฑ

cat pod-multicon.yaml

# pod-multicon.yaml ํŒŒ์ผ๋กœ pod ์ƒ์„ฑ
kubectl apply -f pod-multicon.yaml

Untitled

# ๋‘ ๊ฐœ์˜ container์— ์ ‘์†ํ•˜๊ธฐ
kubectl exec pod-multicon **-c nginx-container** -it -- /bin/bash
kubectl exec pod-multicon **-c centos-container** -it -- /bin/bash

**-> ๋™์ผํ•œ IP**
# ์‹คํ–‰์ค‘์ธ nginx-container์˜ log ๋ณด๊ธฐ
kubectl logs pod-multicon **-c nginx-container

200 -> ์ •์ƒ์ ‘์†
500 -> ์ ‘์†๋ถˆ๊ฐ€
404 -> ์—†๋Š” ํŒŒ์ผ์— ์ ‘์†**

<aside> ๐Ÿ” ๊ฐ์ข… Probe๋ฅผ ํ†ตํ•œ container ์ง„๋‹จ

  1. livenessProbe : container์˜ ๊ฑด๊ฐ•๊ฒ€์ง„

  2. readinessProbe

  3. startupProbe

# ๋™์ž‘์ค‘์ธ Pod์˜ ์ƒํƒœ๋ฅผ yaml ํŒŒ์ผ๋กœ ๋ณด๊ธฐ
kubectl get pod mypod-livenessprobe **-o yaml**

# ๋‚˜๋งŒ์˜ yamlํŒŒ์ผ ๋งŒ๋“ค๊ธฐ ๊ฐ€๋Šฅ
****kubectl get pod mypod-livenessprobe **-o yaml > yslee.yaml

-> failureThreshold : ๋ช‡๋ฒˆ๊นŒ์ง€ ๊ดœ์ฐฎ์€์ง€**

Untitled

# pod-liveness.yaml ํŒŒ์ผ๋กœ ์‹คํ–‰
kubectl apply -f pod-liveness.yaml

# ์‹คํ–‰ํ›„ 110์ดˆ ํ›„
kubectl describe pod pod-liveness

Untitled

# busybox-liveness.yaml ํŒŒ์ผ๋กœ ์‹คํ–‰
kubectl apply -f busybox-liveness.yaml

k get pod 

kubectl exec busybox-liveness -it -- ls /tmp
-> ์•ˆ์— healthy ํŒŒ์ผ ์žˆ๋Š”์ง€ ํ™•์ธ

Untitled

# contaniers ๋ช…๋ น์–ด์— 30์ดˆ ๋’ค ์‚ญ์ œ 
cat busybox-liveness.yaml

Untitled

k describe pod busybox-liveness

Untitled

</aside>

</aside>

<aside> ๐Ÿ“Œ ๋‹ค์–‘ํ•œ container

<aside> ๐Ÿ“Œ Pod ๊ตฌ์„ฑํ˜•ํƒœ

</aside>

<aside> ๐Ÿ“Œ ํŠน์ •ํ•œ node์— pod ๋ฐฐํฌ

</aside>