๐Ÿ™ ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ๊ฐœ๋… ์ •๋ฆฌ # ํ•ต์‹ฌ ๊ฐœ๋… ๐Ÿš

bo-yoonยท2021๋…„ 7์›” 11์ผ
2

kubernetes

๋ชฉ๋ก ๋ณด๊ธฐ
3/10

udemy Certified Kubernetes Administrator (CKA) with Practice Tests
์ฐธ๊ณ 



# โš“๏ธ ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค๋ž€? โš“๏ธ : https://kubernetes.io/ko/
  • ์ปจํ…Œ์ด๋„ˆํ™” ๋œ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์ž๋™์œผ๋กœ ๋ฐฐํฌ, ์Šค์ผ€์ผ๋ง ๋ฐ ๊ด€๋ฆฌํ•ด์ฃผ๋Š” ์˜คํ”ˆ์†Œ์Šค ์‹œ์Šคํ…œ



์ฃผ์š” ์—ญํ• 

1) ์Šค์ผ€์ค„๋ง : ์ปจํ…Œ์ด๋„ˆ ๋ณ„ ์ž์›์„ ๊ด€๋ฆฌํ•˜์—ฌ ์ตœ์ ํ™” ํ•˜๊ณ , ์ ์ ˆํ•œ ๋…ธ๋“œ์— ๋ฐฐํฌ ํ•œ๋‹ค.
2) ์ •์ƒ, ๋น„์ •์ƒ ์ƒํƒœ๋ฅผ ์ฒดํฌํ•˜๊ณ  ์žฌ๊ธฐ๋™ํ•œ๋‹ค.
3) ์ปจํ…Œ์ด๋„ˆ ๋ฆฌ์†Œ์Šค ๋ชจ๋‹ˆํ„ฐ๋ง
4) ๋™์ ์œผ๋กœ ์‚ญ์ œ, ํ™•์žฅ ๊ด€๋ฆฌ




๐Ÿฆญ ๊ตฌ์„ฑ ์š”์†Œ

: https://kubernetes.io/ko/docs/concepts/architecture/

โ›ด ๋งˆ์Šคํ„ฐ ๋…ธ๋“œ

  • ๋งˆ์Šคํ„ฐ ๋…ธ๋“œ๋ž€ ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ํด๋Ÿฌ์Šคํ„ฐ๋ฅผ ์ปจํŠธ๋กคํ•˜๋Š” ์‹œ์Šคํ…œ์ด๋‹ค.

๐Ÿช ๊ตฌ์„ฑ ์š”์†Œ ๐Ÿช

  1. kube-apiserver : ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค์˜ ์ค‘์‹ฌ์ด ๋˜๋Š” ์š”์†Œ, ๋ชจ๋“  ๋ช…๋ น๊ณผ ํ†ต์‹ ์„ REST API ๋ฅผ ์ œ๊ณต, kubectl ์€ kube-apiserver์™€ ํ†ต์‹ ์„ ์ฃผ๊ณ  ๋ฐ›๋Š”๋‹ค.

  2. kube-scheduler : ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค์˜ Pod๋‚˜ Service ๋“ฑ ๋ฆฌ์†Œ์Šค๋ฅผ ์ ์ ˆํ•œ ๋…ธ๋“œ์— ํ• ๋‹นํ•œ๋‹ค.

  3. kube-controller : ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค์—๋Š” ์—ฌ๋Ÿฌ ์ข…๋ฅ˜์˜ ์ปจํŠธ๋กค๋Ÿฌ๊ฐ€ ์žˆ๋Š”๋ฐ ์ด ์ปจํŠธ๋กค๋Ÿฌ๋ฅผ ์ƒ์‚ฐํ•˜๊ณ  ๋ฐฐํฌํ•˜๋Š” ๋“ฑ ๊ด€๋ฆฌํ•œ๋‹ค.

    • controller๋ž€?
      - ์ปจํŠธ๋กค๋Ÿฌ๋ž€ ์ ์–ด๋„ ํ•˜๋‚˜์ด์ƒ์˜ ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ๋ฆฌ์†Œ์Šค๋ฅผ ์ถ”์ ํ•œ๋‹ค. ํด๋Ÿฌ์Šคํ„ฐ์˜ ์ƒํƒœ๋ฅผ ๊ด€์ฐฐํ•œ๋‹ค์Œ ํ•„์š”ํ•œ ๊ฒฝ์šฐ์— ์ƒ์„ฑ ๋˜๋Š” ๋ณ€๊ฒฝ์„ ์š”์ฒญํ•˜๋Š” ์ปจํŠธ๋กค ๋ฃจํ”„์ด๋‹ค.
  1. Etcd : ๋…ธ๋“œ,ํŒŒ๋“œ, config, secret, account, role ๊ฐ™์€ ํด๋Ÿฌ์Šคํ„ฐ์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ์ €์žฅํ•˜๋Š” ๋ฐ์ดํ„ฐ ๋ฒ ์ด์Šค. ํ‚ค ๋ฒจ๋ฅ˜ ๊ฐ’์ด๋‹ค.



โ›ต๏ธ ์›Œ์ปค ๋…ธ๋“œ

  • ์‹ค์ œ๋กœ ์ผํ•˜๋Š” ์ปดํฌ๋„ŒํŠธ

๐Ÿช ๊ตฌ์„ฑ ์š”์†Œ ๐Ÿช

  1. kubelet : ์„ ์žฅ, ์›Œ์ปค ๋…ธ๋“œ์— ํŒŒ๋“œ๋ฅผ ์ƒ์„ฑํ•˜๊ธฐ ์œ„ํ•ด ์ปจํ…Œ์ด๋„ˆ ๋Ÿฐํƒ€์ž„์— ์š”์ฒญ์„ ํ•˜๊ณ , ์˜ค๋ธŒ์ ํŠธ์˜ ์ƒํƒœ๋ฅผ ๋ชจ๋‹ˆํ„ฐ๋ง ํ•˜๋ฉฐ ์ฒดํฌํ•˜์—ฌ ๊ทธ ๊ฒฐ๊ณผ๋ฅผ kube-apiserver์— ์ „๋‹ฌํ•œ๋‹ค.

  2. kube-proxy : ๊ฐ ๋…ธ๋“œ์—์„œ ์‹คํ–‰๋˜๋ฉฐ, ๋กœ๋“œ ๋ฐธ๋Ÿฐ์‹ฑ์„ ์ œ๊ณตํ•œ๋‹ค. ๊ฐ ์„œ๋น„์Šค์—๊ฒŒ ๋„๋‹ฌํ•˜๋Š” ๋ฐ๋งŒ ์‚ฌ์šฉํ•˜๋ฉฐ, ๋…ธ๋“œ์— ์˜ค๋Š” ํŠธ๋ž˜ํ”ฝ์„ ์ ์ ˆํ•˜๊ฒŒ ๋ผ์šฐํŒ…ํ•ด์ค€๋‹ค.

  3. Container runtime : ๋„์ปค ๊ฐ™์€ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์‹คํ–‰ํ•˜๋Š” ๊ตฌ์„ฑ์š”์†Œ์ด๋‹ค.




๐Ÿšค ์˜ค๋ธŒ์ ํŠธ

๐Ÿช ๊ตฌ์„ฑ ์š”์†Œ ๐Ÿช

1) Pod

: https://kubernetes.io/ko/docs/concepts/workloads/pods/

  • ํŒŒ๋“œ๋Š” ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค์—์„œ ์ƒ์„ฑํ•˜๊ณ  ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐฐํฌ ๊ฐ€๋Šฅํ•œ ๊ฐ€์žฅ ์ž‘์€ ๋‹จ์œ„์ด๋‹ค.
  • ๋˜ํ•œ ํ•˜๋‚˜ ์ด์ƒ์˜ ์ปจํ…Œ์ด๋„ˆ๋กœ ๊ตฌ์„ฑ๋œ ๊ทธ๋ฃน์ด๋‹ค. ๊ฐ™์€ ํŒŒ๋“œ ๋‚ด ์ปจํ…Œ์ด๋„ˆ๋Š” ๊ฐ™์€ ์•„์ดํ”ผ๋ฅผ ๊ฐ€์ง€๊ณ  ํฌํŠธ๋ฅผ ๊ณต์œ ํ•˜๊ณ  ๋˜ํ•œ ๋ณผ๋ฅจ๋„ ๊ณต์œ ํ•  ์ˆ˜ ์žˆ๋‹ค. ๋„์ปค ๋„คํŠธ์›Œํฌ ๊ตฌ์กฐ๋ฅผ ์ƒ๊ฐํ•˜๋ฉด ์ดํ•ดํ•˜๊ธฐ ์‰ฝ๋‹ค.

์˜ˆ์‹œ)


apiVersion: v1
kind: Pod
metadata:
  name: nginx
spec:
  containers:
  - name: nginx
    image: nginx:1.7.9
    ports:
    - containerPort: 8080

2) Service

: https://kubernetes.io/ko/docs/concepts/services-networking/service/

  • ํŒŒ๋“œ ์ง‘ํ•ฉ์—์„œ ์‹คํ–‰์ค‘์ธ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๋„คํŠธ์›Œํฌ ์˜ค๋ธŒ์ ํŠธ๋กœ ๋…ธ์ถœํ•˜๋Š” ๋ฐฉ๋ฒ•
  • ํŒŒ๋“œ ๊ฐ™์€ ๊ฒฝ์šฐ ๋งค๋ฒˆ ์‚ญ์ œ๋˜๊ณ  ์ƒ์„ฑ๋˜๊ณ  ๊ฐ€๋” ๊ณ ์žฅ๋„ ๋‚˜๊ณ ๋ฅผ ๋ฐ˜๋ณตํ•˜๋ฉฐ ์•„์ดํ”ผ๊ฐ€ ๋ณ€๊ฒฝ๋œ๋‹ค. ๋งค๋ฒˆ ์ด์‚ฌ๊ฐ€๋Š” ํŒŒ๋“œ์—๊ฒŒ ๊ณ ์ •๋œ ์ฃผ์†Œ๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ์ „์†กํ•˜๊ธด ์–ด๋ ต๋‹ค. ๊ทธ๋ž˜์„œ ์„œ๋น„์Šค๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์„œ๋น„์Šค๊ฐ€ ํŒŒ๋“œ๋ฅผ ์ฐพ์•„๊ฐ€๊ฒŒ ๋งŒ๋“ ๋‹ค. ์ฆ‰, ์‚ฌ์šฉ์ž๋Š” ๊ณ ์ •๋˜์–ด ์žˆ๋Š” ์„œ๋น„์Šค๋ฅผ ์ฐพ์•„ ๊ฐ€๋ฉด ๋˜๊ธฐ ๋•Œ๋ฌธ์— ํŒŒ๋“œ์— ์ ‘๊ทผ์ด ์‰ฌ์›Œ์ง„๋‹ค.
  • ์„œ๋น„์Šค๋Š” ์…€๋ ‰ํ„ฐ์™€ ํฌํŠธ๋ฅผ ํ†ตํ•ด ํŒŒ๋“œ๋ฅผ ์ถ”์ ํ•œ๋‹ค.

์˜ˆ์‹œ)


apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  selector:
    app: MyApp
  ports:
    - protocol: TCP
      port: 80
      targetPort: 9376

3) Volume

https://kubernetes.io/ko/docs/concepts/storage/volumes/

  • Pod ์— ์ข…์†๋˜์–ด ์žˆ๋Š” ๋””์Šคํฌ๋กœ Pods ์•ˆ์˜ ๊ฐ™์€ ๋„คํŠธ์›Œํฌ ์Šคํƒ๋ฅผ ๊ณต์œ ํ•˜๋Š” ์ปจํ…Œ์ด๋„ˆ๋“ค์ด ๊ฐ™์ด ์‚ฌ์šฉํ•œ๋‹ค. ํŒŒ๋“œ ๋‚ด์— ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์žฌ ์‹œ์ž‘ํ•ด๋„ ๋ฐ์ดํ„ฐ๋Š” ๋ณด์กด๋œ๋‹ค.

  • ๋ณผ๋ฅจ์€ ๋””๋ ‰ํ„ฐ๋ฆฌ๋ฉฐ ์ผ๋ถ€ ๋ฐ์ดํ„ฐ๊ฐ€ ์žˆ์„ ์ˆ˜ ์žˆ์œผ๋ฉฐ, ํŒŒ๋“œ ๋‚ด์— ์ปจํ…Œ์ด๋„ˆ์— ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๊ณ , ๋””๋ ‰ํ„ฐ๋ฆฌ์˜ ์ƒ์„ฑ ๋ฐฉ์‹, ์ด๋ฅผ ์ง€์›ํ•˜๋Š” ๋งค์ฒด์™€ ์‚ฌ์šฉ์€ ์‚ฌ์šฉ๋œ ํŠน์ • ๋ณผ๋ฅจ์˜ ์œ ํ˜•์— ๋”ฐ๋ผ ๊ฒฐ์ •๋จ

  • ๋ณผ๋ฅจ์€ Pod์˜ ์ปดํฌ๋„ŒํŠธ์ด๋ฉฐ pods์˜ ์ŠคํŒฉ์— ์˜ํ•ด์„œ ์ •์˜ ๋œ๋‹ค . spec.volumes , .spec.containers[*].volumeMounts


emptyDir
: ํŒŒ๋“œ๊ฐ€ ๋…ธ๋“œ์— ํ• ๋‹น ๋ ๋•Œ ์ƒ์„ฑ ๋˜๋ฉฐ, ์ผ์‹œ์ ์œผ๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅํ•˜์˜€๋‹ค ๋…ธ๋“œ์—์„œ ํŒŒ๋“œ๊ฐ€ ์‹คํ–‰ ์ค‘์ง€ ๋˜๋ฉด ์‚ญ์ œ๋˜๋Š” ๋””๋ ‰ํ„ฐ๋ฆฌ. ์ฒ˜์Œ์—๋Š” ๋น„์–ด์žˆ๋‹ค.

apiVersion: v1
kind: Pod
metadata:
  name: test-pd
spec:
  containers:
  - image: k8s.gcr.io/test-webserver
    name: test-container
    volumeMounts:
    - mountPath: /cache
      name: cache-volume
  volumes:
  - name: cache-volume
    emptyDir: {}

hostPath
: hostPath ๋ณผ๋ฅจ์€ ํ˜ธ์ŠคํŠธ ๋…ธ๋“œ์˜ ํŒŒ์ผ ์‹œ์Šคํ…œ์— ์žˆ๋Š” ํŒŒ์ผ์ด๋‚˜ ๋””๋ ‰ํ„ฐ๋ฆฌ๋ฅผ ํŒŒ๋“œ ๋‚ด๋ถ€์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋งˆ์šดํŠธ ํ•˜๋Š” ๊ฒƒ์œผ๋กœ ๊ณต์œ  ํด๋”๋ผ๊ณ  ์ƒ๊ฐํ•˜๋ฉด ์‰ฝ๋‹ค.

apiVersion: v1
kind: Pod
metadata:
  name: test-pd
spec:
  containers:
  - image: k8s.gcr.io/test-webserver
    name: test-container
    volumeMounts:
    - mountPath: /test-pd
      name: test-volume
  volumes:
  - name: test-volume
    hostPath:
      # ํ˜ธ์ŠคํŠธ์˜ ๋””๋ ‰ํ„ฐ๋ฆฌ ์œ„์น˜
      path: /data
      # ์ด ํ•„๋“œ๋Š” ์„ ํƒ ์‚ฌํ•ญ์ด๋‹ค
      type: Directory

  • ์ด ๋ฐ–์—๋„ ํŠน์ • ํด๋ผ์šฐ๋“œ์™€ ์—ฐ๊ด€ํ•ด์„œ ์“ฐ๋Š” awsElasticBlockStore, gcePersistentDisk, ๋„คํŠธ์›Œํฌ ํŒŒ์ผ ์‹œ์Šคํ…œ์„ ํŒŒ๋“œ์— ๋งˆ์šดํŠธ ํ•ด์„œ ์‚ฌ์šฉํ•˜๋Š” nfs, ํŠน์ • ํด๋ผ์šฐ๋“œ์˜ ์ƒˆ๋ถ€ ๋‚ด์šฉ์„ ๋ชฐ๋ผ๋„ ๋‚ด๊ตฌ์„ฑ ์žˆ๋Š” ์Šคํ† ๋ฆฌ์ง€๋ฅผ ํ•  ์ˆ˜ ์žˆ๋Š” persistentVolumeclaim ์ด ์žˆ๋‹ค.


4) Controller

https://kubernetes.io/docs/concepts/workloads/controllers/replicaset/

  • ์•ž์„œ ์–ธ๊ธ‰ํ–ˆ๋“ฏ์ด ์ปจํŠธ๋กค๋Ÿฌ๋ž€ ์ ์–ด๋„ ํ•˜๋‚˜ ์ด์ƒ์˜ ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ๋ฆฌ์†Œ์Šค๋ฅผ ์ถ”์ ํ•˜๋Š” ๊ฐ์ฒด์ธ๋ฐ, ์ด ๊ฐ์ฒด๋Š” Pod๊ฐ€ ํ•ญ์ƒ ์‹คํ–‰๋˜๋„๋ก ํ•˜๋Š” ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ์˜ค๋ธŒ์ ํŠธ์ด๋‹ค. Pod์˜ ์ƒํƒœ๋ฅผ ํ•ญ์ƒ ์ถ”์ ํ•˜์—ฌ ์ง€์ •ํ•œ ์ˆซ์ž๋ณด๋‹ค ์‚ฌ๋ผ์ง€๋Š” ๊ฒฝ์šฐ์—๋Š” ๋‹ค์‹œ ์ƒ์„ฑํ•œ๋‹ค.

replicaController
: ๋ ˆ์ด๋ธ” ์…€๋ ‰ํ„ฐ๋กœ ํŒŒ๋“œ๋ฅผ ์ถ”์ 

replicaSet
: ๋ ˆํ”Œ๋ฆฌ์นด ์ปจํŠธ๋กค ๋ณด๋‹ค ํŠน์ • ๋ ˆ์ดํ”Œ ํ‚ค๋ฅผ ํฌํ•จํ•˜๋Š” ํŒŒ๋“œ๊ฐ€ ์žˆ๋Š”์ง€ ์ฒดํฌ, replicacontroller๋ณด๋‹ค ๋” ์ •ํ™•ํ•˜๊ฒŒ Pod ๋ฅผ ์ถ”์ ํ•œ๋‹ค. ํ˜„์žฌ์—๋Š” ๋Œ€๋ถ€๋ถ„ ์ด๊ฒƒ์„ ์‚ฌ์šฉํ•œ๋‹ค.

apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: frontend
  labels:
    app: guestbook
    tier: frontend
spec:
  # modify replicas according to your case
  replicas: 3
  selector:
    matchLabels:
      tier: frontend
  template:
    metadata:
      labels:
        tier: frontend
    spec:
      containers:
      - name: php-redis
        image: gcr.io/google_samples/gb-frontend:v3
profile
๊ฐœ๋ฐœ ๋กœ๊ทธ ๐ŸŽ ๐ŸŽ ๐ŸŽ

0๊ฐœ์˜ ๋Œ“๊ธ€