์ด ๊ธ์ JB Ground ๋ธ๋ก๊ทธ์ ๊ฐ์ด๋๋ฅผ ๊ธฐ๋ฐ์ผ๋ก,
VirtualBox + Ubuntu 22.04 ํ๊ฒฝ์์ ์ง์ ํ ์คํธํ ๊ฒฐ๊ณผ๋ฅผ ์ ๋ฆฌํ ๋ด์ฉ์ ๋๋ค.
๋ณธ ๊ตฌ์ฑ์ 3๋์ ์๋ฒ ๋ชจ๋๊ฐ Control Plane(๋ง์คํฐ) ๊ณผ Worker ๋ ธ๋ ์ญํ ์ ๋์์ ์ํํฉ๋๋ค.
| ๋ ธ๋ | ์ญํ | IP ์ฃผ์ | OS |
|---|---|---|---|
| node1 | Master + Worker | 10.0.2.4 | Ubuntu 22.04 |
| node2 | Master + Worker | 10.0.2.5 | Ubuntu 22.04 |
| node3 | Master + Worker | 10.0.2.6 | Ubuntu 22.04 |
๐ก ๋ชจ๋ ๋ ธ๋๋ VirtualBox์์ NAT Network ๋ชจ๋๋ก ์ฐ๊ฒฐ๋์ด ์์ต๋๋ค.
โป ๋ชจ๋ ์ค์น ๊ณผ์ ์ root ๊ณ์ ์ผ๋ก ์งํํ ๊ฒ์ ๊ถ์ฅ
#root ๊ณ์ ์ ์ ๋ฐฉ๋ฒ
sudo su
ํด๋ผ์คํฐ๋ฅผ ๊ตฌ์ถํ๊ธฐ ์ํด ํ์ํ ์ฌ์ ์์ ์ ๋ค์๊ณผ ๊ฐ๋ค.
swap ๋ฉ๋ชจ๋ฆฌ ๋นํ์ฑํ
ํด๋ฌ์คํฐ์ ๋ชจ๋ ์์คํ
๊ฐ์ ๋คํธ์ํฌ ์ฐ๊ฒฐ
์ปจํ
์ด๋ ๋ฐํ์ ์ค์น
Master Node ์ต์ ์ฌ์ Worker Node ์ต์ ์ฌ์
CPU: 2 Core, RAM: 2GB CPU: 1 Core, RAM: 1GB
#์ฝ์ด ํ์ธ
nproc
#๋ฉ๋ชจ๋ฆฌ ํ์ธ
free -h
#MAC ํ์ธ
ifconfig -a
#product uuid ํ์ธ
sudo cat /sys/class/dmi/product_uuid
#๋๋
sudo cat /sys/class/dmi/id/product_uuid
#swap ์์ ๋นํ์ฑํ
sudo swapoff -a
#swap ์๊ตฌ ๋นํ์ฑํ
sudo sed -i '/swap/s/^/#/' /etc/fstab
#๋ฉ๋ชจ๋ฆฌ ์ํ ํ์ธ
sudo free -m
#swap ๋ฉ๋ชจ๋ฆฌ ์ํ ํ์ธ, ์ถ๋ ฅ๊ฐ์ด ์์ผ๋ฉด swap ๋ฉ๋ชจ๋ฆฌ ๋นํ์ฑํ ์ํ
sudo swapon -s
swap ๋นํ์ฑํ ๊ฒฐ๊ณผ
โป์ ๋ฐฉ๋ฒ์ผ๋ก ๋นํ์ฑํ ๋์ง ์๋ ๊ฒฝ์ฐ
#swap unit ์กฐํ
systemctl list-unit-files --type swap
#swap unit(dev-ํํฐ์
์ด๋ฆ.swap)์ maskํด์ ๋นํ์ฑํ
systemctl mask [swap unit๋ช
]
ex) systemctl mask dev-sda3.swap
#๋นํ์ฑํ ์ ์ฉ ํ์ธ
sudo systemctl list-unit-files --type swap
#๋ฐฉํ๋ฒฝ ์์ธ ์ค์ (๋ง์คํฐ, ์์ปค)
sudo apt-get install -y firewalld
sudo systemctl start firewalld
sudo systemctl enable firewalld
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
#๋ง์คํฐ ๋
ธ๋์ผ ๊ฒฝ์ฐ
sudo firewall-cmd --permanent --add-port=6443/tcp
sudo firewall-cmd --permanent --add-port=2379-2380/tcp
sudo firewall-cmd --permanent --add-port=10250-10252/tcp
sudo firewall-cmd --permanent --add-port=8285/udp
sudo firewall-cmd --permanent --add-port=8472/udp
sudo firewall-cmd --reload
#์์ปค ๋
ธ๋์ผ ๊ฒฝ์ฐ
sudo firewall-cmd --permanent --add-port=10250/tcp
sudo firewall-cmd --permanent --add-port=30000-32767/tcp
sudo firewall-cmd --permanent --add-port=8285/udp
sudo firewall-cmd --permanent --add-port=8472/udp
sudo firewall-cmd --permanent --add-port=26443/tcp
sudo firewall-cmd --reload
#๋ฐฉํ๋ฒฝ ๋นํ์ฑํ(๋ง์คํฐ, ์์ปค)
sudo apt-get install -y firewalld
sudo systemctl stop firewalld
sudo systemctl disable firewalld
๋ฐฉํ๋ฒฝ ์คํ ์ํ ํ์ธ
#์ด๋ฆฐ ํฌํธ ํ์ธ
sudo firewall-cmd --list-all
#์ด๋ฆฐ ํฌํธ ํ์ธ
sudo netstat -tlnp
#๋ค๋ฅธ ๋
ธ๋์ ํฌํธ ์ ๊ฒ
telnet [ip] [port]
ex) telnet 192.168.100.128 6443
Trying 192.168.111.128...
telnet: Unable to connect to remote host: Connection refused
#Trying 192.168.111.128... ๋ง ๊ณ์ ๋์ค๋ฉด ๋ฐฉํ๋ฒฝ ์คํ๋์ด ์์ง ์์
#Connection refuesed๊ฐ ๋์ค๋ฉด ๋ฐฉํ๋ฒฝ ์คํ์ ๋์ด ์์ผ๋ ํ๋ก์ธ์ค๊ฐ ์ฌ๋ผ๊ฐ ์์ง ์์ ์ํ
#๋ฐฉ๋ฒ2
curl -v telnet://[ip]:[port]
#/etc/modules-load.d/k8s.conf ํ์ผ ์์ฑ
sudo cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
br_netfilter
EOF
#/etc/sysctl.d/k8s.conf ํ์ผ ์์ฑ
sudo cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
#์์คํ
์ฌ์์ ์์ด stysctl ํ๋ผ๋ฏธํฐ ๋ฐ์
sudo sysctl --system
๊ธ์ด์ด๋ ๋์ปค๋ฅผ ๊ธฐ๋ณธ์ ์ผ๋ก ์ค์นํํ ๋ธ๋ก๊ทธ์ ์๋ ๋์ปค์ชฝ ๋ด์ฉ์ ํ ๋๋ก ์งํํ์์.
์ฟ ๋ฒ๋คํฐ์ค๋ ์ปจํ ์ด๋๋ค์ ํตํฉ ๊ด๋ฆฌํ๋ ์ค์ผ์คํธ๋ ์ด์ ํ๋ซํผ์ด๊ธฐ ๋๋ฌธ์ ์ปจํ ์ด๋์ ์คํ, ๊ด๋ฆฌ ๋ฑ์ ์ญํ ์ ์ํํ๋ ์ปจํ ์ด๋ ๋ฐํ์์ ๋ณ๋ ์ค์นํด์ผ ํ๋ค.
์ฟ ๋ฒ๋คํฐ์ค ์ค์น์ ์์ ๋์ปค๋ฅผ ์ ํ ์ค์นํ๋ ๊ฒฝ์ฐ๊ฐ ์๋๋ฐ ์ด๋ Docker์ ํต์ฌ ์ปจํ ์ด๋ ๋ฐํ์ ๊ธฐ๋ฅ์ ๋ ๋ฆฝ ์คํํ ๊ตฌ์ฑ ์์๋ก ํ์ฅํ ๊ฒ์ด Containerd์ด๊ธฐ ๋๋ฌธ์ Docker์ ์ปจํ ์ด๋ ๋ฐํ์์ธ Containerd๋ฅผ ์ฟ ๋ฒ๋คํฐ์ค์ ์ปจํ ์ด๋ ๋ฐํ์์ผ๋ก ์ฌ์ฉ ๊ฐ๋ฅํ๊ธฐ ๋๋ฌธ์ด๋ค.
์ฟ ๋ฒ๋คํฐ์ค์ ์ปจํ ์ด๋ ๋ฐํ์์ผ๋ก ๋์ปค๋ฅผ ์ฌ์ฉ ๊ฐ๋ฅํ ์ด์
๋์ปค ๋ฟ๋ง์ด ์๋ CRI ํ์ค์ ๋ง์กฑํ๋ ์ปจํ ์ด๋ ๋ฐํ์์ ๋ชจ๋ ์ฟ ๋ฒ๋คํฐ์ค ํด๋ฌ์คํฐ์ ์ปจํ ์ด๋ ๋ฐํ์์ผ๋ก ์ฌ์ฉ์ด ๊ฐ๋ฅํ๋ค. ๋ํ์ ์ผ๋ก Containerd์ CRI-O๊ฐ ์๋ค.
CRI(Container Runtime Interface)
Containerd: ๋์ปค์ ํต์ฌ ์ปจํ ์ด๋ ๋ฐํ์ ๊ธฐ๋ฅ์ ๋ ๋ฆฝ ์คํํ ๊ตฌ์ฑ ์์๋ก ํ์ฅํ ์ปจํ ์ด๋ ๋ฐํ์์ผ๋ก ๋์ปค ์์ง์ ๊ธฐ๋ณธ์ผ๋ก ํ์ฌ๋์ด ์์ด ์ง๊ธ๋ ๋์ปค๋ฅผ ์ฌ์ฉํ๋ค๋ฉด ๋ด๋ถ์ ์ผ๋ก ์ฌ์ฉ๋๋ ์ปจํ ์ด๋ ๋ฐํ์
CRI-O: ๋ ๋ํ์ด ๊ฐ๋ฐํ ์ฟ ๋ฒ๋คํฐ์ค์ฉ OCI(Open Container initiative) ์ปจํ ์ด๋ ๋ฐํ์์ผ๋ก ๋์ปค๋ฅผ ๋์ฒดํ๊ธฐ ์ํด ์ฟ ๋ฒ๋คํฐ์ค์์ CRI ๊ตฌํ ๋ชฉ์ ์ผ๋ก ๋ง๋ ์ฟ ๋ฒ๋คํฐ์ค ์ ์ฉ ๋ฐํ์
์ฟ ๋ฒ๋คํฐ์ค์ ์ปจํ ์ด๋ ๋ฐํ์์ ์ค์นํ๋ ๋ฐฉ๋ฒ์ ๋ช ๊ฐ์ง ์๊ฐํ๋๋ก ํ๊ฒ ๋ค.
- docker ์ค์น ์ Depends๋ก ํจ๊ป ์ค์น๋๋ containerd ํจํค์ง ์ฌ์ฉ
- containerd๋ง ์ค์น ์ฌ์ฉ
- docker engine + cri-dockerd
โป ์ธ๊ฐ์ง ๋ฐฉ๋ฒ ์ค ํ๊ฐ์ง๋ง ์ ์ฉํ๋ฉด ๋๋ค.
#apt ์
๋ฐ์ดํธ
sudo apt-get update
#ํ์ ํจํค์ง ์ค์น
sudo apt-get install -y apt-transport-https ca-certificates curl gnupg
2.1.2. ๊ณต๊ฐํค ๋ค์ด๋ก๋ ๋ฐ ์ ์ฅ์ ๋ฑ๋ก
#๊ณต๊ฐํค ๋ค์ด๋ก๋
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
# ์ ์ฅ์ ๋ฑ๋ก
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
#์ ์ฅ์ ์ถ๊ฐ๋ก apt ์
๋ฐ์ดํธ
sudo apt update
#๋์ปค ์ค์น
sudo apt install -y docker.io ๋๋ sudo apt install -y docker-ce
#๋์ปค ๋ฒ์ ์กฐํ
docker --version
โป docker.io ๋ฐ๋น์(์ฐ๋ถํฌ)์์ ์ ๊ณตํ๋ ๋์ปค ํจํค์ง๋ก ๋ฐ๋น์ ์ ์ฅ์์์ ๋์ปค ํจํค์ง๋ฅผ ๊ฐ์ ธ์ค๊ฒ ๋๋ค.
docker.io ๋ docker์ ์ธ๋ถ ์ข
์์ฑ ํจํค์ง๋ ๋ง์ดํฌ๋ก ํจํค์ง์ผ๋ก ๋
๋ฆฝ์ ์ผ๋ก ํจํค์ง๋์ด ์๋ค.
docker-ce ์ค์น ์ โ ์ธ๋ถ ์ข
์์ฑ ํจํค์ง๋ก containerd.io ์ค์น๋จ.
docker.io ์ค์น ์ โ ์ธ๋ถ ์ข
์์ฑ ํจํค์ง๋ก containerd ์ค์น๋จ.
#/etc/docker ๋๋ ํ ๋ฆฌ ์์ ๊ฒฝ์ฐ ์์ฑ
sudo mkdir /etc/docker
#daemon.json ํ์ผ ์ถ๊ฐ
sudo cat <<EOF | sudo tee /etc/docker/daemon.json
{
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2"
}
EOF
Kubernetes 1.22๋ฒ์ ๋ถํฐ๋ systemd์ cgroup ๋ง์ถฐ์ผํจ.
#containerd ๊ตฌ์ฑ ํ์ผ ์์ฑ
sudo mkdir -p /etc/containerd
#containerd ๊ธฐ๋ณธ ์ค์ ๊ฐ์ผ๋ก config.toml ์์ฑ
sudo containerd config default | sudo tee /etc/containerd/config.toml
#config.toml ํ์ผ ์์
vi /etc/containerd/config.toml
# cgroup driver(runc) ์ฌ์ฉํ๊ธฐ ์ค์
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options]
SystemdCgroup = true
#์์ ์ฌํญ ์ ์ฉ ๋ฐ ์ฌ์คํ
sudo systemctl restart containerd
#๋์ปค ์ฌ์์
sudo service docker restart
#๋์ปค ์ํ ์กฐํ
sudo service docker status
docker.io ์ค์น ๊ฒฐ๊ณผ
#apt ์
๋ฐ์ดํธ
sudo apt-get update
#ํ์ ํจํค์ง ์ค์น
sudo apt-get install -y apt-transport-https ca-certificates curl gnupg
#๊ณต๊ฐํค ๋ค์ด๋ก๋
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
# ์ ์ฅ์ ๋ฑ๋ก
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
#์ ์ฅ์ ์ ์ฉ์ ์ํ apt ์
๋ฐ์ดํธ
sudo apt-get update
#containerd ํจํค์ง ์ค์น
sudo apt-get install containerd
#์ค์น ํ์ธ
sudo systemctl status containerd
#containerd ๊ตฌ์ฑ ํ์ผ ์์ฑ
sudo mkdir -p /etc/containerd
#containerd ๊ธฐ๋ณธ ์ค์ ๊ฐ์ผ๋ก config.toml ์์ฑ
sudo containerd config default | sudo tee /etc/containerd/config.toml
#config.toml ํ์ผ ์์
vi /etc/containerd/config.toml
# cgroup driver(runc) ์ฌ์ฉํ๊ธฐ ์ค์
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options]
SystemdCgroup = true
#์์ ์ฌํญ ์ ์ฉ ๋ฐ ์ฌ์คํ
sudo systemctl restart containerd
Docker ์์ง ๊ด๋ จ ๋ช
๋ น์ ๊ธฐ๋ฐ์ผ๋ก ์คํฌ๋ฆฝํธ๋ฅผ ์คํ
๊ถํ์ด ์๋ Pod์์ Docker ๋ช
๋ น ์คํ
Docker ํน์ ๋ก๊น
๋ฐ ๋ชจ๋ํฐ๋ง ํ์ฉ
๋ฑ์ ์ด์ ๋ก ๋์ปค ์์ง์ ์ปจํ
์ด๋ ๋ฐํ์์ผ๋ก ์ฌ์ฉํ๋ ๊ฒฝ์ฐ๊ฐ ์๋ค.
๋๋ dockershim์ ๋์ฒดํ๊ธฐ ์ํด ํฌ๋ฆฌ๋์ปค๋(cri-dockerd)๋ก ๋ง์ด๊ทธ๋ ์ด์
ํ๋ ๊ฒฝ์ฐ๊ฐ ์๋ค.
#apt ์
๋ฐ์ดํธ
sudo apt update
#ํ์ ํจํค์ง ์ค์น
sudo apt install -y apt-transport-https ca-certificates curl gnupg
#์ค์น ํจํค์ง ์กฐํ
dpkg -l | grep [ํจํค์ง๋ช
]
#๊ณต๊ฐํค ๋ค์ด๋ก๋
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
# ์ ์ฅ์ ๋ฑ๋ก
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
#๋ฑ๋กํ ๋ ํฌ์งํ ๋ฆฌ๋ฅผ ๋ฐ์ํ๊ธฐ ์ํด apt update
sudo apt update
#docker ํจํค์ง ์ค์น
sudo apt install -y docker-ce
#๋ฒ์ ํ์ธ
docker --version
#hello-world container ์์ฑ
docker run -it --name [์ปจํ
์ด๋๋ช
] hello-world
#๋์ปค ์ปจํ
์ด๋ ์กฐํ
docker ps -a
#๋์ปค ์ปจํ
์ด๋ ์ญ์
docker rm [์ปจํ
์ด๋ID ๋๋ ์ปจํ
์ด๋๋ช
]
#๋์ปค ์ด๋ฏธ์ง ์กฐํ
docker images
#๋์ปค ์ด๋ฏธ์ง ์ญ์
docker rmi [์ด๋ฏธ์ง๋ช
]
#cri-dockerd ์์ค์ฝ๋ ๋ณต์ฌ
git clone https://github.com/Mirantis/cri-dockerd.git
#Go์ธ์ด ์ค์น
wget https://storage.googleapis.com/golang/getgo/installer_linux
chmod +x ./installer_linux
./installer_linux
source ~/.bash_profile
#cri-dockerd ๋น๋
cd cri-dockerd
mkdir bin
go build -o bin/cri-dockerd
#/usr/local/bin ์ผ๋ก ๋น๋ํ์ผ ๋ณต์ฌ
mkdir -p /usr/local/bin
install -o root -g root -m 0755 bin/cri-dockerd /usr/local/bin/cri-dockerd
#systemd์ ์๋น์ค ๋ฑ๋ก
cp -a packaging/systemd/* /etc/systemd/system
sed -i -e 's,/usr/bin/cri-dockerd,/usr/local/bin/cri-dockerd,' /etc/systemd/system/cri-docker.service
#์ฌ๊ธฐ๋
systemctl daemon-reload
systemctl enable cri-docker.service
systemctl enable --now cri-docker.socket
sudo systemctl restart docker && sudo systemctl restart cri-docker
#์ํ ํ์ธ
sudo systemctl status cri-docker.socket --no-pager
# Docker daemon Cgroup ๋ณ๊ฒฝ
cat <<EOF | sudo tee /etc/docker/daemon.json
{
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2"
}
EOF
ํ์ ํจํค์ง ๋ชฉ๋ก
apt-transport-https
ca-certificates
curl
gnupg
#apt ์
๋ฐ์ดํธ
sudo apt-get update
#ํ์ ํจํค์ง ์ค์น
sudo apt-get install -y apt-transport-https ca-certificates curl gnupg
#๊ณต๊ฐ ํค ๋ค์ด๋ก๋
curl -fsSLo /etc/apt/keyrings/kubernetes-archive-keyring.gpg https://dl.k8s.io/apt/doc/apt-key.gpg
#apt ์ ์ฅ์์ ์ฟ ๋ฒ๋คํฐ์ค ์ ์ฅ์ ์ถ๊ฐ
sudo echo "deb [signed-by=/etc/apt/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
#โป 23.01์ฏค ๋ถํฐ ์ฟ ๋ฒ๋คํฐ์ค ์ ์ฅ์ url์ด ๋ณ๊ฒฝ๋จ.
#https://packages.cloud.google.com/apt/doc/apt-key.gpg -> https://dl.k8s.io/apt/doc/apt-key.gpg
โปUbuntu 20.04์๋ /etc/apt/keyrings ๋๋ ํ ๋ฆฌ๊ฐ ์์ผ๋ฏ๋ก ๋๋ ํ ๋ฆฌ ์์ฑ ํ์. 22.04 ์ดํ์๋ ๋๋ ํ ๋ฆฌ ์กด์ฌํจ
#keyrings ๋๋ ํ ๋ฆฌ ์์ฑ
sudo mkdir -p /etc/apt/keyrings
#๊ฐ์ธํค ๋ค์ด๋ก๋
curl -fsSLo /etc/apt/keyrings/kubernetes-archive-keyring.gpg https://dl.k8s.io/apt/doc/apt-key.gpg
#์ฟ ๋ฒ๋คํฐ์ค ๋ ํฌ์งํ ๋ฆฌ ์ถ๊ฐ
sudo apt-add-repository "deb [signed-by=/etc/apt/keyrings/kubernetes-archive-keyring.gpg] http://apt.kubernetes.io/ kubernetes-xenial main"
โป๊ทธ๋๋ ๋ฌธ์ ๊ฐ ๋ฐ์ํ ๊ฒฝ์ฐ vi ํธ์ง๊ธฐ๋ก kubenetes.list ํ์ผ์ ํด๋น ๋ฌธ์์ด ์ถ๊ฐ
sudo vi /etc/apt/sources.list.d/kubernetes.list
#๋ค์ ๋ฌธ์์ด ์ถ๊ฐ
deb [signed-by=/etc/apt/keyrings/kubernetes-archive-keyring.gpg] http://apt.kubernetes.io/ kubernetes-xenial main
#์ ์ฅ์ ์ถ๊ฐ๋์๊ธฐ ๋๋ฌธ์ apt ์
๋ฐ์ดํธ
sudo apt-get update
#์ฟ ๋ฒ๋คํฐ์ค ํจํค์ง ์ค์น
sudo apt-get install -y kubelet kubeadm kubectl
#์ฟ ๋ฒ๋คํฐ์ค ํจํค์ง ๋ฒ์ ๊ณ ์
sudo apt-mark hold kubelet kubeadm kubectl
#์ฟ ๋ฒ๋คํฐ์ค ์ค์น ๋ฒ์ ์กฐํ
kubelet --version
kubeadm version
kubectl version
#kubelet service ํ์ธ
sudo systemctl status kubelet.service
์ฟ ๋ฒ๋คํฐ์ค ์ค์น ๊ฒฐ๊ณผ
๋ง์ฝ haproxy๋ฅผ ์ฌ์ฉํ๊ณ VIP๋ฅผ ์ฌ์ฉํ๊ณ ์๋ค๋ฉด VIP๊ฐ ํ ๋น์ค์ธ
kubeadm์ ํตํด Control-Plane ์ค์ ์ ์๋ฃํ๋ฉด Worker Node์ joinํค๊ฐ ๋ฐ๊ธ๋๊ณ ํด๋น ํค๋ก Worker Node๋ฅผ ๋ฑ๋ก ์ ์ฌ์ฉํ๋ ๊ผญ ๊ธฐ์ตํด๋์
#์ฟ ๋ฒ๋คํฐ์ค ํด๋ฌ์คํฐ๋ฅผ ์ด๊ธฐํํ์ฌ ์๋ก์ด ๋ง์คํฐ ๋
ธ๋๋ฅผ ์์ฑํ๋ ๋ช
๋ น์ด
#๋ณ๋์ ์ต์
์ ์ค์ ํ์ง ์์ผ๋ฉด ๊ธฐ๋ณธ ๋ํดํธ ๊ฐ์ผ๋ก ์ ์ฉ
kubeadm init [์ต์
]
ํ๋จ์ ์ด๊ธฐํ ์ค์ ๋ช ๋ น์ ๋ง์คํฐ ๋ ธ๋๊ฐ ์ฌ๋ฌ๊ฐ๋ผ๋ ํ๋์ ๋ง์คํฐ ๋ ธ๋์ ํ ๋ฒ๋ง ์คํํ๋ฉด ๋๋ค.(๋ง์ฝ ํ์ง ์์ผ๋ฉด ๋ง์ง๋ง ํ์ธ ์์ ''kubectl get nodes -o wide'' ์์ ๋ค๋ฅธ ๋ ธ๋๋ค์ STATUS๊ฐ NotReady๋ก ํ์๋ ๊บผ๋ค.)
#Flannel(๋ํดํธ ์ค์ ๊ฐ)
sudo kubeadm init
#๋๋
sudo kubeadm init \
--control-plane-endpoint "10.0.2.10:6443" \ # vip์ฌ์ฉ ๋๋ ๋์ค ํ์ฅ์.
--upload-certs \
--pod-network-cidr=192.168.0.0/16
#Calico
sudo kubeadm init \
--control-plane-endpoint "10.0.2.10:6443" \ # vip์ฌ์ฉ ๋๋ ๋์ค ํ์ฅ์.
--upload-certs \
--pod-network-cidr=192.168.0.0/16
๋ง์ฝ VIP(๊ฐ์ IP)๋ฅผ ์ฐ๊ณ ์ถ๋ค.
- ์ฌ๋ฌ ๋ง์คํฐ๋ฅผ HA๋ก ๊ตฌ์ฑํ๋ ค๋ฉด ๋ณดํต Keepalived๋ HAProxy๋ก control-plane-endpoint ๋ฅผ ๊ณ ์ .
์๋ฅผ ๋ค์ด,
--control-plane-endpoint "k8s-cluster.example.local:6443"
์ผ๋ก ์ค์ ํ๊ณ
์ด ์ด๋ฆ์ /etc/hosts์ VIP๋ก ๋งคํํด๋๋ฉด
์ด๋ ๋ง์คํฐ๊ฐ active๋ ์ง ์ ์์ด ๊ฐ๋ฅํฉ๋๋ค.
์ต์ ๋ชฉ๋ก
--config : ์ด๊ธฐํ์ ์ฌ์ฉํ ๊ตฌ์ฑ ํ์ผ์ ์ง์
--token : ํด๋ฌ์คํฐ์ ๋ํ ์ก์ธ์ค๋ฅผ ํ์ฉํ๋ ํ ํฐ์ ์ด๊ธฐํ
--pod-network-cidr : ํด๋ฌ์คํฐ์ ๋ํ Pod ๋คํธ์ํฌ CIDR ๋ฒ์๋ฅผ ์ง์
--apiserver-advertise-address : API ์๋ฒ๊ฐ ํผ๋ธ๋ฆญ ์๋ํฌ์ธํธ์ ๋ํด ์๋ฆด IP ์ฃผ์๋ฅผ ์ง์
--apiserver-cert-extra-sans : ๋ง์คํฐ ๋ ธ๋ ์ธ์ ์ค์ ์ถ๊ฐํ DNS ์ด๋ฆ์ ์ง์
--control-plane-endpoint : ์ปจํธ๋กค ํ๋ ์ธ ๊ตฌ์ฑ์์๊ฐ ์๋ก ํต์ ํ๋๋ฐ ์ฌ์ฉํ ์๋ํฌ์ธํธ๋ฅผ ์ง์
--cri-socket : ์ฌ์ฉํ CRI์ ์์ผ์ ์ง์
๊ธ์ด์ด๋ ๋ชจ๋ ๋ ธ๋๊ฐ ๋ง์คํฐ ๋ ธ๋์ด๋ฏ๋ก ๋ชจ๋ ๋ค ์ ์ฉ ํด์คฌ๋ค.
root ๊ณ์ ์ด ์๋ ๋ค๋ฅธ ๊ณ์ ์์๋ kubectl ๋ช
๋ น์ด๋ฅผ ์ฌ์ฉํ๊ธฐ ์ํด config ์ค์
โปconfig ์ค์ ์ ์งํํ์ง ์์ ๊ฒฝ์ฐ kubectl ๋ช
๋ น์ด๋ฅผ ์ฌ์ฉ ์
The connection to the server localhost:8080 was refused - did you specify the right host or port?
๋ฌธ๊ตฌ๋ฅผ ๋์ฐ๋ฉด์ ๋คํธ์ํฌ ์ฐ๊ฒฐ์ด ๊ฑฐ์ ๋ ์ ์๋ค.
sudo mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
์ปจํ ์ด๋ ๊ฐ์ ๋คํธ์ํฌ๋ฅผ ์ ์ดํ ์ ์๋ ํ๋ฌ๊ทธ์ธ์ผ๋ก ์ปจํ ์ด๋ ๋ฐํ์์์ ์ปจํ ์ด๋์ ๋คํธ์ํฌ๋ฅผ ์ฌ์ฉํ๊ฒ ํด์ฃผ๋ ์ธํฐํ์ด์ค์ด๋ค.
์ฟ ๋ฒ๋คํฐ์ค์์ ์ฌ์ฉ๋๋ Pod๋ค์ ๊ธฐ๋ณธ์ ์ผ๋ก ์ค๋ฒ๋ ์ด ๋คํธ์ํฌ ๋ฐฉ์์ ์ ์ฉํ์ฌ ์๋ํฌ์ธํธ ๊ฐ์ ๋คํธ์ํฌ ๊ตฌ์กฐ๋ฅผ ์ถ์ํํ์ฌ ๋คํธ์ํฌ ํต์ ๊ฒฝ๋ก๋ฅผ ๋จ์ํํ๋ค. ์ด๋ ์ฌ์ฉ๋๋ ํ๋ฌ๊ทธ์ธ ๋ง๋ค ์ค์ ๋ฐฉ๋ฒ์ด ๋ค๋ฅด๋ค.
Flannel
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
Calico
curl https://docs.projectcalico.org/manifests/calico.yaml -O --insecure
kubectl apply -f calico.yaml
cni ์ค์น ๊ฒฐ๊ณผ
#CNI ์ ์ฉ ํ์ธ
kubectl get pods -A -o wide
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-flannel kube-flannel-ds-g8j8h 1/1 Running 0 87s
๋ง์คํฐ ๋
ธ๋์์ kubeadm init ์ ํตํด ์์ฑํ join ๋ช
๋ น์ด๋ฅผ ์ด์ฉํ์ฌ ์์ปค ๋
ธ๋ ๋ฑ๋ก
sudo kubeadm join [ip]:6443 --token [ํ ํฐ๋ช
] --discovery-token-ca-cert-hash [hashkey]
๋ง์คํฐ ๋ ธ๋๊ฐ ์์ปค๋ ธ๋์ ์ญํ ๋ ํ ์ ์๋๋ก...
kubectl taint nodes <๋ง์คํฐ๋ ธ๋์ด๋ฆ> node-role.kubernetes.io/control-plane-
sudo kubectl get node
๋๋
sudo kubectl get nodes -o wide
๋ง์ฝ 8080 connect:connection refused ์ค๋ฅ๊ฐ ๋ฐ์ํ๋ค๋ฉด
๋จ์ํ sudo๋ฅผ ์ ์ธํ๊ณ ์คํ.. kubectl์์ฒด๋ root๊ถํ์ด ํ์์๊ณ ํด๋ฌ์คํฐ ๊ถํ์ kubeconfig๊ฐ ์ฒ๋ฆฌ.
sudo kubeadm join 10.0.2.9:6443 \ --token [ํ ํฐ๊ฐ] \ --discovery-token-ca-cert-hash sha256:[ํด์๊ฐ] \ --control-plane \ ๋ฅผ ํตํด ์๋ํ์ง๋ง#!/bin/bash
# Kubernetes Complete Reset Script for Masters & Workers
echo "------------------------------------------------"
echo "Kubernetes ํด๋ฌ์คํฐ ์์ ์ด๊ธฐํ๋ฅผ ์์ํฉ๋๋ค..."
echo "------------------------------------------------"
# 1. ๊ธฐ๋ณธ ๋ฆฌ์
๋ฐ ์๋น์ค ์ค๋จ
echo "[1/4] ์๋น์ค ์ค๋จ ๋ฐ kubeadm reset ์คํ ์ค..."
sudo kubeadm reset -f
sudo systemctl stop kubelet
sudo systemctl stop haproxy || true
sudo systemctl stop keepalived || true
# 2. ์ค์ ๋ฐ ๋ฐ์ดํฐ ๋๋ ํ ๋ฆฌ ์๊ตฌ ์ญ์
echo "[2/4] ์ค์ ํ์ผ ๋ฐ etcd ๋ฐ์ดํฐ ์ญ์ ์ค..."
sudo rm -rf /etc/kubernetes/
sudo rm -rf ~/.kube/
sudo rm -rf /var/lib/etcd
sudo rm -rf /etc/cni/net.d
sudo rm -rf /var/lib/kubelet/*
sudo rm -rf /var/log/pods/*
sudo rm -rf /var/log/containers/*
# 3. ๋คํธ์ํฌ ์ธํฐํ์ด์ค ๋ฐ iptables ์ด๊ธฐํ
echo "[3/4] ๋คํธ์ํฌ ์ธํฐํ์ด์ค ๋ฐ iptables ๊ท์น ์ด๊ธฐํ ์ค..."
sudo ip link delete cni0 2>/dev/null || true
sudo ip link delete flannel.1 2>/dev/null || true
sudo ip link delete calico-vpp-0 2>/dev/null || true
sudo ip link set tunl0 down 2>/dev/null || true
sudo ip link delete tunl0 2>/dev/null || true
sudo iptables -F && sudo iptables -t nat -F && sudo iptables -t mangle -F && sudo iptables -X
sudo ipvsadm --clear 2>/dev/null || true
# 4. ์๋ฅ ์ปจํ
์ด๋ ๋ฐ ์์ผ ์ ๋ฆฌ
echo "[4/4] ์ฐ๊บผ๊ธฐ ์ปจํ
์ด๋ ๋ฐ ์ ์ ํฌํธ ๊ฐ์ ์ ๋ฆฌ ์ค..."
if command -v crictl &> /dev/null; then
sudo crictl ps -aq | xargs -r sudo crictl stop
sudo crictl ps -aq | xargs -r sudo crictl rm
fi
# ํฌํธ ์ ์ ํ๋ก์ธ์ค ๊ฐ์ ์ข
๋ฃ (6443, 2379, 2380 ๋ฑ)
sudo fuser -k 6443/tcp 2379/tcp 2380/tcp 10250/tcp 2>/dev/null || true
# ์ปจํ
์ด๋ ๋ฐํ์ ์ฌ์์
sudo systemctl restart containerd
echo "------------------------------------------------"
echo "์ด๊ธฐํ ์๋ฃ! ์ด์ ํด๋ฌ์คํฐ๋ฅผ ์๋ก ๊ตฌ์ฑํ ์ ์์ต๋๋ค."
echo "------------------------------------------------"