Kubernetes Basics

Kubernetes ๋ž€?

  • ์‚ฌ์šฉ์ž์—๊ฒŒ ๋ถ„์‚ฐํ˜• ์‹œ์Šคํ…œ์„ ์•ˆ์ •์ ์œผ๋กœ ์šด์˜ ํ•  ์ˆ˜ ์žˆ๋Š” framework๋ฅผ ์ œ๊ณต

  • ์„œ๋น„์Šค์˜ ํ™•์žฅ ์š”๊ตฌ, ์žฅ์•  ์กฐ์น˜ ๋น› ๋ฐฐํฌ ํŒจํ„ด์„ ์ฒ˜๋ฆฌํ•จ

    • ex) ์นด๋‚˜๋ฆฌ์•„ ๋ฐฐํฌ

Kubernetes ๊ฐ€ ํ•  ์ˆ˜ ์žˆ๋Š” ์ผ

  • Service discovery and load balancing

  • Storage orchestration

  • Automated rollouts and rollbacks

  • Automatic bin packing

  • Self-healing

  • Secret and configuration management

Kubernetes์˜ ๊ตฌ์„ฑ ์š”์†Œ

  • master node๋Š” kubernetes ์ „์ฒด๋ฅผ ํ†ต์ œ/๊ด€๋ฆฌ

  • worker node๋Š” ์‹ค์ œ ์‚ฌ์šฉ์ž์˜ application ๋ฐฐํฌ

Running app on Kubernetes

Kubernetes Object

Object Spec & Status

  • Spec

    • ํ•ด๋‹น object ๊ฐ€ ๊ฐ€์ ธ์•ผ ํ•  ์š”๊ตฌ๋˜๋Š” ์ƒํƒœ(desired status)์™€ ํŠน์ง•์„ ์„œ์ˆ ํ•˜๋Š” ๊ณณ

    • ์šฐ๋ฆฌ๊ฐ€ ์กฐ์ •ํ•˜๋Š” ๊ฒƒ

  • Status

    • object์˜ ์‹ค์ œ ์ƒํƒœ๋ฅผ ๊ธฐ์ˆ ํ•˜๊ณ  kubernetes system์— ์˜ํ•ด update ๋จ

kubernetes object ๊ฐœ๋…๋„

1. Pods

Pod ๋ž€?

  • Application์˜ ์ตœ์†Œ ์‹คํ–‰ ๋‹จ์œ„

  • Application container (ํ•˜๋‚˜ ํ˜น์€ ๋‹ค์ˆ˜), storage, network ๋“ฑ์˜ ์ •๋ณด๋ฅผ ํฌํ•จ

Pod์˜ ํŠน์ง•

  • Pod ์—๋Š” ๊ฐ๊ฐ ๊ณ ์œ ํ•œ private IP ํ• ๋‹น

  • Pod ์•ˆ์— ์žˆ๋Š” container๋Š” pod ์˜ IP๋ฅผ local host ๋กœ ๊ณต์œ 

  • Pod ๋Š” ์‚ฌ์‹ค์ƒ Pod๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” virtual machine์ด๋ผ๊ณ  ํ•  ์ˆ˜ ์žˆ์Œ

2. Deployments

  • ReplicaSet ๋ณด๋‹ค ์ƒ์œ„์— ํ•ด๋‹นํ•˜๋Š” resource

  • Application ๋ฐฐํฌ์˜ ๊ธฐ๋ณธ ๋‹จ์œ„

Deployments yml file ์˜ ํ•„์ˆ˜ ์š”์†Œ

  1. apiVersion

  2. kind

  3. metadata

  4. spec

    • kubernetes ์˜ ์ƒํƒœ๋ฅผ ์ง€์ •ํ•˜๋Š” state ๊ฐ’

3. labels

  • kubernetes ๋Š” label์„ ๊ธฐ์ค€์œผ๋กœ ํŠน์ • ์ž์›์„ ์„ ํƒํ•œ๋‹ค

  • pod์™€ ๊ฐ™์€ object์— ์ฒจ๋ถ€๋œ key value ๊ฐ’

Labels Use Cases

  • ์‹คํ–‰ ์ค‘์ธ ํŠน์ • pod๋ฅผ ๊ฐ€๋ฆฌํ‚ค๊ธฐ ์œ„ํ•ด ReplicaSet ์—์„œ ์‚ฌ์šฉํ•œ๋‹ค

4. Services: ClusterIP

  • Cluster-internal IP๋ฅผ ํ†ตํ•ด Service๋ฅผ ๋…ธ์ถœ

  • ์˜ค์ง cluster ๋‚ด๋ถ€์—์„œ๋งŒ ์ ‘๊ทผ ๊ฐ€๋Šฅ

  • kube-proxy๋ฅผ ํ†ตํ•ด ์ ‘๊ทผ ๊ฐ€๋Šฅ

  • Service๋ฅผ debugging ํ•˜๊ณ ๋‚˜, ๊ฐœ๋ฐœ์ž local์—์„œ ์ ‘๊ทผ ๋˜๋Š” ๋‚ด๋ถ€ dashboard๋ฅผ ๋ณด์—ฌ์ค„ ๋•Œ ์‚ฌ์šฉ

์„œ๋น„์Šค ์™ธ๋ถ€ ๋…ธ์ถœ

manifest ์—์„œ type์— ๊ธฐ์žฌํ•˜๋ฉด ๋œ๋‹ค

1. NodePort

  • NAT ๋ฅผ ์ด์šฉํ•˜์—ฌ cluster ๋‚ด Node์˜ ๊ณ ์ •๋œ port๋ฅผ ๊ฐ–๋Š” IP๋กœ service๋ฅผ ๋…ธ์ถœ

  • Cluster ์™ธ๋ถ€์—์„œ ์ ‘๊ทผ

    • <NodeIP> : <NodePort>

  • 1 service per port

  • Port ์‚ฌ์šฉ ๋ฒ”์œ„

    • 30000-32767

2. LoadBalancer

  • NodePort์—์„œ ๋ฐœ์ „๋œ type

  • Cloud provider์˜ Load Balancer๋ฅผ ์ด์šฉํ•ด service๋ฅผ ์™ธ๋ถ€๋กœ ๋…ธ์ถœ

  • NodePort and ClusterIP services (to which LB will route) automatically created

  • LB (ELB, NLB)๋กœ ๋…ธ์ถœ๋œ ๊ฐ service๋Š” ๊ณ ์œ ํ•œ IP ์ฃผ์†Œ๋ฅผ ๊ฐ–๋Š”๋‹ค

3. Ingress

  • Cluster ๋‚ด service ๋ฅผ HTTP(S) ๊ธฐ๋ฐ˜์œผ๋กœ ๋…ธ์ถœ

  • ๋‹ค์–‘ํ•œ ๊ตฌํ˜„์ฒด

    • ALB

    • Nginx

    • F5

    • HAProxy

  • Default Service Type

    • ClusterIP

  • Ingress๋Š” ์„œ๋น„์Šค ํƒ€์ž…์ด ์•„๋‹ˆ๋ผ service ์•ž์ชฝ์— ์œ„์น˜ํ•˜๋ฉฐ ์™ธ๋ถ€๋กœ๋ถ€ํ„ฐ ์„œ๋ฒ„ ๋‚ด๋ถ€๋กœ ์œ ์ž…๋˜๋Š” Network traffic์„ ์˜๋ฏธ

Nginx Ingress controller ์˜ˆ์‹œ

Volumes

  • Pod์— ์ข…์†๋˜๋Š” ๋””์Šคํฌ

  • Pod ๋‹จ์œ„์ด๊ธฐ ๋•Œ๋ฌธ์— ํ•ด๋‹น pod์— ์†ํ•ด ์žˆ๋Š” ์—ฌ๋Ÿฌ๊ฐœ์˜ container๊ฐ€ ๊ณต์œ ํ•ด์„œ ์‚ฌ์šฉ๋  ์ˆ˜ ์žˆ๋‹ค

Namespace

  • k8s ์ž์›์— ๋Œ€ํ•œ ์˜์—ญ์„ ์ œ๊ณตํ•˜๊ณ , ๊ถŒํ•œ๊ณผ ์ •์ฑ…์„ cluster์˜ ํ•˜์œ„ section์— ์ ์šฉํ•˜๋Š” ๋ฉ”์ปค๋‹ˆ์ฆ˜ ์ œ๊ณต

    • ์ฆ‰, ์ž์›์„ ๊ทธ๋ฃนํ™”ํ•ด ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ๋Š” ๊ธฐํšŒ ์ œ๊ณต

  • ์‚ฌ์šฉ ์˜ˆ

    • ๊ฐœ๋ฐœ ํ™˜๊ฒฝ, ํ…Œ์ŠคํŠธ ํ™˜๊ฒฝ, ์šด์˜ ํ™˜๊ฒฝ ๊ฐ™์€ ์†Œํ”„ํŠธ์›จ์–ด ํ™˜๊ฒฝ ๊ตฌ๋ถ„

    • ์ธํ”„๋ผํŒ€์ด ๋ณผ ์ˆ˜ ์žˆ๋Š” ๊ตฌ์—ญ๊ณผ ๊ฐœ๋ฐœํŒ€์ด ๋ณผ ์ˆ˜ ์žˆ๋Š” ๊ตฌ์—ญ ๊ตฌ๋ถ„

      • ๊ถŒํ•œ์˜ boundary

      • ์ž์›์˜ boundary

  • Cluster ์ƒ์„ฑ ์‹œ ๋‹ค์Œ์˜ ๊ธฐ๋ณธ์ ์ธ namespace ์‚ฌ์šฉ

    • default

      • ๋‹ค๋ฅธ namespace๊ฐ€ ์—†๋Š” object๋ฅผ ์œ„ํ•œ ๊ธฐ๋ณธ namespace

      • container, pod, service, replicaset ๋“ฑ์˜ ์ž์›์— ๋Œ€ํ•œ ์˜์—ญ์„ ์ œ๊ณต

    • kube-system

      • kubernetes system์—์„œ ์ƒ์„ฑํ•œ object๋ฅผ ์œ„ํ•œ namespace

    • kube-public

      • ์ž๋™์œผ๋กœ ์ƒ์„ฑ๋˜๋ฉฐ ๋ชจ๋“  ์‚ฌ์šฉ์ž (์ธ์ฆ๋˜์ง€ ์•Š์€ ์‚ฌ์šฉ์ž ํฌํ•จ)๊ฐ€ ์ฝ๊ธฐ ๊ถŒํ•œ์œผ๋กœ ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋‹ค

      • ์ฃผ๋กœ ์ „์ฒด cluster ์ค‘์— ๊ณต๊ฐœ์ ์œผ๋กœ ๋“œ๋Ÿฌ๋‚˜์„œ ์ฝ์„ ์ˆ˜ ์žˆ๋Š” resource๋ฅผ ์œ„ํ•ด ์˜ˆ์•ฝ๋˜์–ด ์žˆ๋‹ค

        • ๊ณต๊ฐœ์ ์ธ ์„ฑ๊ฒฉ์€ ๋‹จ์ง€ ๊ด€๋ก€์ด์ง€ ์š”๊ตฌ์‚ฌํ•ญ์€ ์•„๋‹ˆ๋‹ค!

Last updated