Container Orchestration
Container Orchestration ์ด๋ ๋ณต์กํ ์ปจํ ์ด๋ ํ๊ฒฝ์ ํจ๊ณผ์ ์ผ๋ก ๊ด๋ฆฌํ๊ธฐ ์ํ ๋๊ตฌ๋ก K8s ๊ฐ ์ฃผ๋ก ์ฐ์ธ๋ค.
- Cluster = Master Node ๊ฐ ์ค์์ ์ด, ๋ค์์ Worker Node ๊ฐ ํด๋ฌ์คํฐ๋ฅผ ์ด๋ฃจ์ด ์๋ก ํต์ ํ๋ฉฐ ์๋
- State = Desired State ์ ์ธ ์ ๊ด๋ฆฌ์์ ๊ฐ์ ์์ด ์๋์ผ๋ก ์ํ๋ฅผ ์ ์ง
- Scheduling = Container ๋ฅผ ๋ฐฐ์นํ ์ ํฉํ Worker Node ๋ฅผ ์ฐพ์ ๋ฐฐํฌ
- Rollout Rollback = ๋ฐฐํฌ ๋ฒ์ ๊ด๋ฆฌ
- Service Discovery = ์๋น์ค ๋ฑ๋ก ๋ฐ ์กฐํ
- Volume = NFS, EBS ๋ฑ ๋ค์ํ ์คํ ๋ฆฌ์ง ๋ง์ดํ
K8s Architecture
K8s ๋ Master Node ์ Worker Node ์ ์งํฉ์ผ๋ก ์ด๋ฃจ์ด์ง๋ค.
Master Node ๋ Worker Node ๋ค์ Manage, Plan, Schedule, Monitor ํ๋ ์ญํ ์ ์ํํ๊ธฐ ์ํด ์๋์ ๊ฐ์ Component ๋ค์ ๊ฐ์ง๋ค.
- kube-apiserver
- controller manager
- etcd cluster
- kube-scheduler
Worker Node ๋ Containerized Application ์ด ์คํ๋๋ Node ๋ก, ์ด๋ฅผ ์ํด ์๋์ ๊ฐ์ Component ๋ค์ ๊ฐ์ง๋ค.
- Container Runtime
- kubelet
- kube-proxy
Docker vs containerd
- Back in time, K8s only supported Docker as its container runtime
- CRI(Container Runtime Interface) was introduced as demand for various container runtime increases
- CRI allowed any vendor to work as a container runtime as long as they follow OCI(Open Container Initiative) standards
- OCI consists of
imagespec
andruntimespec
- OCI consists of
- Docker consists of
containerd
and many other components such as CLI, API, etc. containerd
is compatible with CRI however other components needdockershim
to be compatible with K8s- But now K8s no longer supports Docker engine through
dockershim
- But now K8s no longer supports Docker engine through
- We can use below 2 CLIs instead of docker to work with K8s
nerdctl
= for general purpose from ContainerD communitycrictl
= for debugging from K8s community (works with all CRI compatible container runtimes)
ETCD
- ETCD is a distributed reliable key-value store that is Simple, Secure & Fast
- K8s ์ ๋ชจ๋ ์ํ์ ๋ฐ์ดํฐ๋ฅผ ์ ์ฅ
- Key-Value ํํ๋ก ๋ฐ์ดํฐ๋ฅผ ์ ์ฅ
- ๋ถ์ฐ ์์คํ ์ผ๋ก ๊ตฌ์ฑํ์ฌ ๊ณ ๊ฐ์ฉ์ฑ ํ๋ณด
- TTL, watch ๋ฑ ๋ถ๊ฐ ๊ธฐ๋ฅ ์ ๊ณต
Kube-API Server
- ์ํ๋ฅผ ๋ฐ๊พธ๊ฑฐ๋ ์กฐํ
- etcd ์ ์ ์ผํ๊ฒ ํต์ ํ๋ ๋ชจ๋
- REST API ํํ๋ก ์ ๊ณต
- ์์ฒญ์ ๋ํ ๊ถํ ์ฒดํฌ
- ์ํ์ ํ์ฅ ๊ฐ๋ฅ
- kubeadm ์ผ๋ก ์ค์นํ ๊ฒฝ์ฐ Pod ์ ํํ๋ก ์คํ๋๋ค.
- Authenticate User
- Validate Request
- Retrieve data
- Update ETCD
- Scheduler
- Kubelet
Kube Controller Manager
- ๋ค์ํ Controller ๊ฐ ์กด์ฌ
- A
controller
is aprocess
that continuously monitors the state of the components within the system and works towards bringing the whole system to the desired functioning state - Replication Controller, Node Controller, Endpoint Controller, โฆ
- ๋์ ์์ด ์ํ๋ฅผ ์ฒดํฌํ๊ณ ์ํ๋ ์ํ๋ฅผ ์ ์ง
- ๋ณต์ก์ฑ์ ๋ฎ์ถ๊ธฐ ์ํด ํ๋์ ํ๋ก์ธ์ค๋ก ์คํ
- A
Installing Kube Controller Manager
wget https://storage.googleapis.com/kubernetes-release/release/v1.13.0/bin/linux/amd64/kube-controller-manager
- kubeadm ์ผ๋ก ์ค์นํ ๊ฒฝ์ฐ Pod ์ ํํ๋ก ์คํ๋๋ค.
Kube Scheduler
- kube-scheduler ๋ ์์ฑ ์์ฒญ๋ Pod ๊ฐ ์ด๋ Node ์ ๋ฐฐํฌ๋์ด์ผ ํ๋์ง ํ์ธํ๋ ์ญํ ์ ์ํํ๋ค. Node ์ ํ์ฌ ์ํ์ Pod ์ ์๊ตฌ์ฌํญ์ ์ฒดํฌํ์ฌ ์ ์ ํ Node ๋ฅผ ์ฐพ๋ ์์ ๋ง ์ํํ ๋ฟ Pod ๋ฅผ ์์ฑํ๋ ์ญํ ์ kubelet ์ด ์ํํ๋ค.
How does it work?
- Pod ์ ํ์ํ ๋ฆฌ์์ค๋ฅผ ์ฌ๋ถ์ผ๋ก ๊ฐ์ง๊ณ ์๋ Node ๋ฅผ ํ์ธํ๊ณ Pod ๊ฐ ๋ฐฐ์น๋ ํ ๋จ์ ๋ฆฌ์์ค๋์ ๊ธฐ์ค์ผ๋ก ์์๋ฅผ ๋งค๊ฒจ ์ค์ผ์ฅด๋ง์ ์ํํ๋ค.
Installing Kube Scheduler
wget https://storage.googleapis.com/kubernetes-release/release/v1.13.0/bin/linux/amd64/kube-scheduler
- kubeadm ์ผ๋ก ์ค์นํ ๊ฒฝ์ฐ Pod ์ ํํ๋ก ์คํ๋๋ค.
Kubelet
kubelet ์ Master Node ์ kube-apiserver ๋ก ๋ถํฐ Container ์์ฑ ์์ฒญ์ ๋ฐ์ Worker Node ์ ์ค์น๋ Container Runtime ์ ์ด์ฉํด Container ๋ฅผ ์์ฑํ๋ ์ญํ ์ ํ๋ค. kubelet ์ ์์ ์ด ์์นํ Node ์ ์์ฑํ Pod ๋ค์ ๋ชจ๋ํฐ๋งํ์ฌ ์ฃผ๊ธฐ์ ์ผ๋ก kube-apiserver ์ ์ํตํ๋ค.
Installing Kubelet
wget https://storage.googleapis.com/kubernetes-release/release/v1.13.0/bin/linux/amd64/kubelet
kubeadm ์ผ๋ก K8s Cluster ๋ฅผ ๊ตฌ์ถํ ๋ kubelet ์ ์ค์น๋์ง ์์ผ๋ ์๋์ผ๋ก Worker Node ์ kubelet ์ ์ค์นํด์ฃผ์ด์ผ ํ๋ค. ๋๋ฌธ์ kubelet ์ ๋ค๋ฅธ Component ๋ค๊ณผ ๋ค๋ฅด๊ฒ Pod ์ด ์๋ Node ์ ํ๋ก์ธ์ค๋ก์ ์คํ๋๋ค.
Kube Proxy
- ๋คํธ์ํฌ ํ๋ก์์ ๋ถํ ๋ถ์ฐ ์ญํ ์ ํ๋ฉฐ K8s Cluster ์ ๋ฐฐํฌ๋ ๋ชจ๋ Pod ๊ฐ์ ํต์ ์ ๋ด๋นํ๋ค.
- Pod ํํ๋ก ์คํ๋๊ธฐ ๋๋ฌธ์ kubectl get pods ๋ก ์กฐํ ๊ฐ๋ฅํ๋ค.
- ์ฑ๋ฅ์์ ์ด์ ๋ก ๋ณ๋์ ํ๋ก์ ํ๋ก๊ทธ๋จ ๋์ iptables ๋๋ IPVS ๋ฅผ ์ฌ์ฉํ์ฌ ์ค์ ๋ง ๊ด๋ฆฌํ๋ค.