๐Ÿ˜ก VM [๋…ธ๋“œ, ํด๋Ÿฌ์Šคํ„ฐ ๊ตฌ์„ฑํ•˜๊ธฐ, Cillium]

๊น€์„ฑ์ธยท2023๋…„ 10์›” 10์ผ
0

[DevOps] ๐ŸณDocker & Kubernetes

๋ชฉ๋ก ๋ณด๊ธฐ
14/62

๋…ธ๋“œ ์ค€๋น„

https://kubernetes.io/ko/docs/setup/production-environment/tools/kubeadm/install-kubeadm/


์Šค์™‘ ๋น„ํ™œ์„ฑํ™”

# ํ˜„์žฌ ์‹œ์Šคํ…œ์— ์ ์šฉ(๋ฆฌ๋ถ€ํŒ…ํ•˜๋ฉด ์žฌ ์„ค์ • ํ•„์š”)
sudo swapoff -a
# ๋ฆฌ๋ถ€ํŒ… ํ•„์ˆ˜
sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab

์ปจํ…Œ์ด๋„ˆ ๋Ÿฐํƒ€์ž„ ๊ตฌ์„ฑ

https://www.itzgeek.com/how-tos/linux/ubuntu-how-tos/install-containerd-on-ubuntu-22-04.html#Using_Docker_Repository

# using Docker Repository
sudo apt update
sudo apt install -y ca-certificates curl gnupg lsb-release
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) 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

# install contaierd
sudo apt update
sudo apt install -y containerd.io
sudo systemctl status containerd

# Containerd configuration for Kubernetes
# ์ปจํ…Œ์ด๋„ˆd ๋Ÿฐํƒ€์ž„ ๋“ฑ๋ก
# SystemdCgroup: ๋„์ปค๋„ค์ž„์ŠคํŽ˜์ด์Šค๋ฅผ ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค์™€ ๊ณต์œ ํ•˜๊ธฐ ์œ„ํ•œ ์„ค์ •
cat <<EOF | sudo tee -a /etc/containerd/config.toml
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc]
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options]
SystemdCgroup = true
EOF

sudo sed -i 's/^disabled_plugins \=/\#disabled_plugins \=/g' /etc/containerd/config.toml

sudo systemctl restart containerd

# ์†Œ์ผ“์ด ์žˆ๋Š”์ง€ ํ™•์ธ
ls /var/run/containerd/containerd.sock

kubeadm ์„ค์น˜ํ•˜๊ธฐ

https://kubernetes.io/ko/docs/setup/production-environment/tools/kubeadm/install-kubeadm/#kubeadm-kubelet-%EB%B0%8F-kubectl-%EC%84%A4%EC%B9%98

  1. apt ํŒจํ‚ค์ง€ ์ƒ‰์ธ์„ ์—…๋ฐ์ดํŠธํ•˜๊ณ , ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค apt ๋ฆฌํฌ์ง€ํ„ฐ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐ ํ•„์š”ํ•œ ํŒจํ‚ค์ง€๋ฅผ ์„ค์น˜ํ•œ๋‹ค.
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl
  1. ๊ตฌ๊ธ€ ํด๋ผ์šฐ๋“œ์˜ ๊ณต๊ฐœ ์‚ฌ์ด๋‹ ํ‚ค๋ฅผ ๋‹ค์šด๋กœ๋“œ ํ•œ๋‹ค.
sudo curl -fsSLo /etc/apt/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg
  1. ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค apt ๋ฆฌํฌ์ง€ํ„ฐ๋ฆฌ๋ฅผ ์ถ”๊ฐ€ํ•œ๋‹ค.
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
  1. apt ํŒจํ‚ค์ง€ ์ƒ‰์ธ์„ ์—…๋ฐ์ดํŠธํ•˜๊ณ , kubelet, kubeadm, kubectl์„ ์„ค์น˜ํ•˜๊ณ  ํ•ด๋‹น ๋ฒ„์ „์„ ๊ณ ์ •ํ•œ๋‹ค.
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl

๊ณ : Debian 12 ๋ฐ Ubuntu 22.04 ์ด์ „ ๋ฆด๋ฆฌ์Šค์—์„œ๋Š” /etc/apt/keyrings์ด ๊ธฐ๋ณธ์ ์œผ๋กœ ์กด์žฌํ•˜์ง€ ์•Š๋Š”๋‹ค. ํ•„์š”ํ•œ ๊ฒฝ์šฐ ์ด ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ์ƒ์„ฑํ•˜์—ฌ, ๋ˆ„๊ตฌ๋‚˜ ์ฝ์„ ์ˆ˜ ์žˆ์ง€๋งŒ ๊ด€๋ฆฌ์ž๋งŒ ์“ธ ์ˆ˜ ์žˆ๋„๋ก ๋งŒ๋“ค ์ˆ˜ ์žˆ๋‹ค.

cat <<EOF > kube_install.sh
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl

sudo curl -fsSLo /etc/apt/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg

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

sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl
EOF

sudo bash kube_install.sh

kubeadm version


์ฐธ๊ณ  : https://www.inflearn.com/questions/888659/%EC%BF%A0%EB%B2%84%EB%84%A4%ED%8B%B0%EC%8A%A4-%EC%84%A4%EC%B9%98%ED%95%A0-%EB%95%8C-%EC%97%90%EB%9F%AC%EB%82%A9%EB%8B%88%EB%8B%A4-%ED%95%B4%EA%B2%B0-%EB%B0%A9%EB%B2%95-%EA%B3%B5%EC%9C%A0%ED%95%A9%EB%8B%88%EB%8B%A4-23-05-30-%EA%B8%B0%EC%A4%80

kubeadm ์„ค์น˜ ์˜ค๋ฅ˜

Hit:1 https://download.docker.com/linux/ubuntu focal InRelease
Hit:2 http://asia-northeast3.gce.archive.ubuntu.com/ubuntu focal InRelease 
Hit:3 http://asia-northeast3.gce.archive.ubuntu.com/ubuntu focal-updates InRelease
Hit:4 http://asia-northeast3.gce.archive.ubuntu.com/ubuntu focal-backports InRelease
Hit:5 http://security.ubuntu.com/ubuntu focal-security InRelease           
Reading package lists... Done
Reading package lists... Done
Building dependency tree       
Reading state information... Done
ca-certificates is already the newest version (20230311ubuntu0.20.04.1).
curl is already the newest version (7.68.0-1ubuntu2.19).
The following packages were automatically installed and are no longer required:
  libatasmart4 libblockdev-fs2 libblockdev-loop2 libblockdev-part-err2 libblockdev-part2 libblockdev-swap2
  libblockdev-utils2 libblockdev2 libmbim-glib4 libmbim-proxy libmm-glib0 libnspr4 libnss3 libnuma1
  libparted-fs-resize0 libqmi-glib5 libqmi-proxy libudisks2-0 libxmlb2 usb-modeswitch usb-modeswitch-data
Use 'sudo apt autoremove' to remove them.
The following NEW packages will be installed:
  apt-transport-https
0 upgraded, 1 newly installed, 0 to remove and 21 not upgraded.
Need to get 1704 B of archives.
After this operation, 162 kB of additional disk space will be used.
Get:1 http://asia-northeast3.gce.archive.ubuntu.com/ubuntu focal-updates/universe amd64 apt-transport-https all 2.0.9 [1704 B]
Fetched 1704 B in 0s (21.0 kB/s)
Selecting previously unselected package apt-transport-https.
(Reading database ... 62245 files and directories currently installed.)
Preparing to unpack .../apt-transport-https_2.0.9_all.deb ...
Unpacking apt-transport-https (2.0.9) ...
Setting up apt-transport-https (2.0.9) ...
deb [signed-by=/etc/apt/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main
Hit:1 https://download.docker.com/linux/ubuntu focal InRelease
Hit:2 http://asia-northeast3.gce.archive.ubuntu.com/ubuntu focal InRelease                                    
Hit:3 http://asia-northeast3.gce.archive.ubuntu.com/ubuntu focal-updates InRelease                            
Hit:4 http://asia-northeast3.gce.archive.ubuntu.com/ubuntu focal-backports InRelease                          
Hit:6 http://security.ubuntu.com/ubuntu focal-security InRelease                                   
Get:5 https://packages.cloud.google.com/apt kubernetes-xenial InRelease [8993 B]  
Ign:7 https://packages.cloud.google.com/apt kubernetes-xenial/main amd64 Packages
Ign:7 https://packages.cloud.google.com/apt kubernetes-xenial/main amd64 Packages
Ign:7 https://packages.cloud.google.com/apt kubernetes-xenial/main amd64 Packages
Err:7 https://packages.cloud.google.com/apt kubernetes-xenial/main amd64 Packages
  404  Not Found [IP: 142.250.76.142 443]
Fetched 8993 B in 1s (6544 B/s)
Reading package lists... Done
E: Failed to fetch https://packages.cloud.google.com/apt/dists/kubernetes-xenial/main/binary-amd64/by-hash/SHA256/0d7ba2a5a480b51e90c78214afbd41cb4211c23cc52c2497ebcfc3f1bb8e7e31  404  Not Found [IP: 142.250.76.142 443]
E: Some index files failed to download. They have been ignored, or old ones used instead.
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package kubelet
E: Unable to locate package kubeadm
E: Unable to locate package kubectl
E: Unable to locate package kubelet
E: Unable to locate package kubeadm
E: Unable to locate package kubectl
E: No packages found

๐Ÿค—ํ•ด๊ฒฐ

echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -

sudo apt-get update
sudo apt-get install kubelet kubeadm kubectl

sudo apt-get update

์˜ค๋ฅ˜ ํ•œ๋ฒˆ ๋” ๋‚จ

sudo apt-get update
Hit:1 https://download.docker.com/linux/ubuntu focal InRelease
Hit:2 http://asia-northeast3.gce.archive.ubuntu.com/ubuntu focal InRelease
Hit:3 http://asia-northeast3.gce.archive.ubuntu.com/ubuntu focal-updates InRelease
Hit:4 http://asia-northeast3.gce.archive.ubuntu.com/ubuntu focal-backports InRelease
Hit:6 http://security.ubuntu.com/ubuntu focal-security InRelease
Get:5 https://packages.cloud.google.com/apt kubernetes-xenial InRelease [8993 B]
Ign:7 https://packages.cloud.google.com/apt kubernetes-xenial/main amd64 Packages
Ign:7 https://packages.cloud.google.com/apt kubernetes-xenial/main amd64 Packages
Ign:7 https://packages.cloud.google.com/apt kubernetes-xenial/main amd64 Packages
Err:7 https://packages.cloud.google.com/apt kubernetes-xenial/main amd64 Packages
  404  Not Found [IP: 142.250.76.142 443]
Fetched 8993 B in 2s (5979 B/s)
Reading package lists... Done
E: Failed to fetch https://packages.cloud.google.com/apt/dists/kubernetes-xenial/main/binary-amd64/by-hash/SHA256/0d7ba2a5a480b51e90c78214afbd41cb4211c23cc52c2497ebcfc3f1bb8e7e31  404  Not Found [IP: 142.250.76.142 443]
E: Some index files failed to download. They have been ignored, or old ones used instead.

kubernets.list ํŒŒ์ผ ํ™•์ธํ•ด๋ณด๋‹ˆ URL์€ ์ •์ƒ์ ์œผ๋กœ ์ž‘์„ฑ๋˜์–ด์žˆ๋‹ค.. ๊ทธ๋ž˜์„œ ๋‹ค์‹œ update๋ฅผ ํ•˜๋‹ˆ๊นŒ ์ด๋ฒˆ์—” ์„ฑ๊ณตํ•จ..
๊ทธํ›„ sudo apt-get install kubelet kubeadm kubectl ํ•˜๋‹ˆ ์„ฑ๊ณต


๋„ทํ•„ํ„ฐ ๋ธŒ๋ฆฟ์ง€ ์„ค์ •

๋„คํŠธ์›Œํฌ ํ†ต์‹ ์„ ์œ„ํ•œ ์„ค์ •

sudo -i

sudo modprobe br_netfilter
echo 1 > /proc/sys/net/ipv4/ip_forward
echo 1 > /proc/sys/net/bridge/bridge-nf-call-iptables

exit


ํด๋Ÿฌ์Šคํ„ฐ ๊ตฌ์„ฑํ•˜๊ธฐ

๋งˆ์Šคํ„ฐ ๋…ธ๋“œ ์ดˆ๊ธฐํ™”

sudo kubeadm init: ์˜ต์…˜์„ ์ค˜์„œ ์ปจํŠธ๋กค ํ”Œ๋ ˆ์ธ์„ ์—ฌ๋Ÿฌ๊ฐœ ๋งŒ๋“ค์ˆ˜ ์žˆ์Œ. (๋งˆ์Šคํ„ฐ๋ฅผ ๋‘๋Œ€ ์ด์ƒ)

์œ ์ € ์„ค์ •

To start using your cluster, you need to run the following as a regular user:

  mkdir -p $HOME/.kube
  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  sudo chown $(id -u):$(id -g) $HOME/.kube/config

Alternatively, if you are the root user, you can run:

  export KUBECONFIG=/etc/kubernetes/admin.conf

ํŒŒ๋“œ ๋„คํŠธ์›Œํฌ ์„ค์ •

https://kubernetes.io/docs/concepts/cluster-administration/addons/

You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
  https://kubernetes.io/docs/concepts/cluster-administration/addons/

Then you can join any number of worker nodes by running the following on each as root:

์›Œ์ปค ๋…ธ๋“œ ์กฐ์ธ

์›Œ์ปค ๋…ธ๋“œ ์กฐ์ธ๋ฐฉ๋ฒ•

sudo kubeadm join 10.178.0.2:6443 --token 5mjpzx.trk8jvqeuyecyt0g \
        --discovery-token-ca-cert-hash sha256:efa7e790d83179e19dbc5635dc21573d2095c5e1fe61080b0cd32f67d86ded5d

Cilium ์„ค์น˜

https://kubernetes.io/docs/tasks/administer-cluster/network-policy-provider/cilium-network-policy/
์ปจํ…Œ์ด๋„ˆ์— ํŒŒ๋“œ๊ฐ„ ํ†ต์‹ ์„ ํ• ๋•Œ ์“ฐ๋Š” ๋„๊ตฌ ์„ธํŒ…

curl -LO https://github.com/cilium/cilium-cli/releases/latest/download/cilium-linux-amd64.tar.gz
sudo tar xzvfC cilium-linux-amd64.tar.gz /usr/local/bin
rm cilium-linux-amd64.tar.gz
cilium install

ํŒŒ๋“œ๊ฐ€ ์„ค์น˜๋˜์–ด์„œ ready ์ƒํƒœ๋กœ ๋ณ€๊ฒฝ๋จ

profile
๊ฐœ๋ฐœ์ž๊ฐ€ ๊ฟˆ์ธ 25์‚ด ๋Œ€ํ•™์ƒ์ž…๋‹ˆ๋‹ค.

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