๐ŸŒฑ Infra/Container_ Kubernetes

[์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ๋ฌด์ž‘์ • ๋”ฐ๋ผํ•˜๊ธฐ] Step 1 . ํŒจํ‚ค์ง€ ์„ค์น˜ํ•˜๊ธฐ

mini_world 2020. 11. 30. 18:02
๋ชฉ์ฐจ ์ ‘๊ธฐ

 

์ฟ ๋ฒ„๋„คํ‹ฐ์Šค๋ž€ ๋ฌด์—‡์ผ๊นŒ์š”?๐Ÿคจ
ํ•œ๋งˆ๋””๋กœ ๋งํ•ด์„œ "์ปจํ…Œ์ด๋„ˆ๋ฅผ ์—ฌ๋Ÿฌ ๋…ธ๋“œ์—์„œ ์šด์˜ํ•  ์ˆ˜ ์žˆ๋„๋ก ์ปจํŠธ๋กค ํ•ด์ฃผ๋Š” ์˜ค์ผ€์ŠคํŠธ๋ ˆ์ด์…˜ ํˆด" ์ž…๋‹ˆ๋‹ค.

์—ฌ๊ธฐ์„œ ๋งํ•˜๋Š” "๋…ธ๋“œ"๋ž€, ํ•˜๋‚˜์˜ ์ปดํ“จํ„ฐ/์„œ๋ฒ„๋ฅผ ์ง€์นญํ•ฉ๋‹ˆ๋‹ค.

Docker๋‚˜ Docker Composer๋Š” ํ•˜๋‚˜์˜ ๋…ธ๋“œ์—์„œ๋งŒ ์‚ฌ์šฉํ–ˆ์—ˆ์ฃ , 
์ง€๊ธˆ๋ถ€ํ„ฐ๋Š” ์—ฌ๋Ÿฌ๋Œ€์˜ ๋…ธ๋“œ๋ฅผ ์‚ฌ์šฉํ•  ์˜ˆ์ •์ž…๋‹ˆ๋‹ค. :)

์—ฌ๋Ÿฌ๊ฐ€์ง€ ๊ฐœ๋…์ด ๋ง‰ ๋‚˜์˜ค๊ฒ ์ง€๋งŒ, ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ ์ปจํ…Œ์ด๋„ˆ ๋Ÿฐํƒ€์ž„์ด ์„ค์น˜ ๋˜์–ด์žˆ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
๋ฆฌ๋ˆ…์Šค ํ™˜๊ฒฝ์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค์˜ ์ปจํ…Œ์ด๋„ˆ ๋Ÿฐ ํƒ€์ž„์€ containerd, CRI-O, Docker ์ž…๋‹ˆ๋‹ค.
์ €๋Š” Docker ๋Ÿฐํƒ€์ž„์„ ์„ค์น˜ํ•˜๋„๋ก ํ•ฉ๋‹ˆ๋‹ค.

์—ฌ๊ธฐ ๋ฅผ ํด๋ฆญํ•˜์—ฌ ๋„์ปค ์„ค์น˜๋ถ€ํ„ฐ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
์ €๋Š” ๊ณต์‹๋ฌธ์„œ๋ฅผ ์ฐธ๊ณ ํ•˜์—ฌ Step by Step์œผ๋กœ ์„ค์น˜๋ฅผ ๋ณด์—ฌ๋“œ๋ฆฌ๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.!

์ œ๊ฐ€ ๊ตฌ์„ฑํ•  ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ํด๋Ÿฌ์Šคํ„ฐ ๊ตฌ์„ฑ๋„์ž…๋‹ˆ๋‹ค. :)


 

1. ์ปจํ…Œ์ด๋„ˆ ๋Ÿฐํƒ€์ž„(docker-ce) ์„ค์น˜ 

์ด์ œ ์ปจํ…Œ์ด๋„ˆ ๋Ÿฐํƒ€์ž„์œผ๋กœ Docker-ce๋ฅผ ๋”์ด์ƒ ์‚ฌ์šฉํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
Containerd๋ฅผ ์‚ฌ์šฉํ•˜๋ฉฐ, https://github.com/containerd/containerd/blob/main/docs/getting-started.md ์—ฌ๊ธฐ๋ฅผ ์‚ฌ์šฉํ•ด์„œ Containerd ๋ฅผ ์„ค์น˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค :) 

๊ฐ ๋…ธ๋“œ์— Docker-ce๋ฅผ ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค.
๋ชจ๋“  ๋…ธ๋“œ์— ๋™์ผํ•˜๊ฒŒ ์ž‘์—… ํ•ด์ฃผ์„ธ์š” :) 

์•„๋ž˜ ๋”๋ณด๊ธฐ๋ฅผ ํด๋ฆญํ•˜์—ฌ ํ™•์ธํ•˜์„ธ์š”๐Ÿฅณ

๋”๋ณด๊ธฐ

Docker-ce ์„ค์น˜์— ํ•„์š”ํ•œ ํŒจํ‚ค์ง€๋ฅผ ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค.

[root@kube-manager /]# sudo yum install -y yum-utils device-mapper-persistent-data lvm2

๋„์ปค ๋ฆฌํฌ์ง€ํ† ๋ฆฌ๋ฅผ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

[root@kube-manager /]# sudo yum-config-manager --add-repo   https://download.docker.com/linux/centos/docker-ce.repo

์ด์ œ OS๋ฅผ ์—…๋ฐ์ดํŠธ ํ•˜๊ณ  ํ•„์š”ํ•œ Docker-ce ํŒจํ‚ค์ง€๋ฅผ ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค.

[root@kube-manager /]# sudo yum update -y && sudo yum install -y containerd.io docker-ce docker-ce-cli

๋„์ปค ์„ค์ •ํŒŒ์ผ์ด ๋‹ด๊ธธ ๋””๋ ‰ํ„ฐ๋ฆฌ๋ฅผ ๋งŒ๋“ค์–ด์ค๋‹ˆ๋‹ค. 

[root@kube-manager /]# sudo mkdir /etc/docker

๊ทธ๋ฆฌ๊ณ  ์•„๋ž˜ ๋„์ปค ๋ฐ๋ชฌ ์„ค์ •ํŒŒ์ผ์„ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค.

[root@kube-manager /]# 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",
  "storage-opts": [
    "overlay2.override_kernel_check=true"
  ]
}
EOF

/etc/docker/daemon.json ํŒŒ์ผ์ด ์ž˜ ์ž‘์„ฑ๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.

[root@kube-manager /]# cat /etc/docker/daemon.json

{
  "exec-opts": ["native.cgroupdriver=systemd"],
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "100m"
  },
  "storage-driver": "overlay2",
  "storage-opts": [
    "overlay2.override_kernel_check=true"
  ]
}

์ž, ์ด์ œ ๋ชจ๋“  ์ค€๋น„๊ฐ€ ์™„๋ฃŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.
๋„์ปค๋ฅผ ์žฌ์‹œ์ž‘ํ•˜๊ณ  ๋ถ€ํŒ…์‹œ docker ์„œ๋น„์Šค๊ฐ€ ์‹œ์ž‘ ๋˜๋„๋ก ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค!

[root@kube-manager /]# sudo systemctl daemon-reload
[root@kube-manager /]# sudo systemctl restart docker
[root@kube-manager /]# sudo systemctl enable docker

์—ฌ๊ธฐ๊นŒ์ง€ ์™„๋ฃŒ ๋˜์—ˆ์œผ๋ฉด ๋‹ค์Œ ๋‹จ๊ณ„๋กœ ๋„˜์–ด๊ฐ‘๋‹ˆ๋‹ค :) 

 

2. Kubeadm ์„ค์น˜ ์ „ ํ™•์ธ

์„ค์น˜ํ•˜๊ธฐ ์ „, OS๊ฐ€ Centos 7 ๋ฒ„์ „ ์ด์ƒ, RAM 2GB ์ด์ƒ, ์Šค์™‘ ๋น„ ํ™œ์„ฑํ™”๋ฅผ ํ™•์ธ ํ•ฉ๋‹ˆ๋‹ค.
์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ์„ค์น˜ ์กฐ๊ฑด์€ ์—ฌ๊ธฐ์— ์ž์„ธํžˆ ๋‚˜์™€์žˆ์œผ๋‹ˆ, ๋‹ค์‹œํ•œ๋ฒˆ ์ ๊ฒ€ํ•ด๋ณด์‹œ๊ธฐ๋ฅผ ๋ฐ”๋ž๋‹ˆ๋‹ค. :)
๋ชจ๋“  ๋…ธ๋“œ์— ๋™์ผํ•˜๊ฒŒ ์ž‘์—… ํ•ด์ฃผ์„ธ์š” :) 

์•„๋ž˜ ๋”๋ณด๊ธฐ๋ฅผ ํด๋ฆญํ•˜์—ฌ ํ™•์ธํ•˜์„ธ์š”๐Ÿฅณ

๋”๋ณด๊ธฐ

2-1) OS ํ™•์ธ

๋จผ์ €, OS์˜ ๋ฒ„์ „์„ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.

  • Ubuntu 16.04 ์ด์ƒ
  • Debian 9 ์ด์ƒ
  • CentOS 7
  • RHEL (Red Hat Enterprise Linux) 7
  • Fedora 25 ์ด์ƒ
  • HypriotOS v1.0.1 ์ด์ƒ
  • Flatcar Container Linux (2512.3.0์œผ๋กœ ํ…Œ์ŠคํŠธ ๋จ)

์ €๋Š” Centos 7 ๋กœ ์กฐ๊ฑด์— ๋งŒ์กฑ ํ•ฉ๋‹ˆ๋‹ค.

[root@kube-manager /]# rpm -qa | grep release
centos-release-7-7.1908.0.el7.centos.x86_64
centos-release-7-9.2009.0.el7.centos.x86_64

 

2-2) ๋ฉ”๋ชจ๋ฆฌ ํ™•์ธ

์ด์ œ RAM์„ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.  

[root@kube-manager /]# free -h
              total        used        free      shared  buff/cache   available
Mem:           3.6G        232M        1.5G         16M        1.9G        3.1G
Swap:            0B          0B          0B

๊ทธ๋ฆฌ๊ณ  ์—ฌ๊ธฐ์—์„œ ํ•œ๊ฐ€์ง€ ๋” ์ฃผ์˜๊นŠ๊ฒŒ ๋ด์•ผํ•  ๋ถ€๋ถ„์€ swap ๋ถ€๋ถ„์ž…๋‹ˆ๋‹ค.
Kubelet์€ ์Šค์™‘์„ ์‚ฌ์šฉํ•˜์ง€ ์•Š์œผ๋ฉฐ, ๋น„ํ™œ์„ฑํ™” ๋˜์–ด์žˆ์–ด์•ผ ์ •์ƒ์ ์œผ๋กœ ๋™์ž‘ํ•ฉ๋‹ˆ๋‹ค.
๋งŒ์•ฝ free ๋ช…๋ น์–ด ๊ฒฐ๊ณผ์— Swap ๊ฐ’์ด ๋‚˜์™”๋‹ค๋ฉด ์•„๋ž˜ ๋ช…๋ น์–ด๋กœ ์Šค์™‘์„ ๋„๊ณ , fstab์— ์Šค์™‘ ๋ถ€๋ถ„์„ ์ฃผ์„ ์ฒ˜๋ฆฌ ํ•ฉ๋‹ˆ๋‹ค.

[root@kube-manager /]# swapoff -a
[root@kube-manager /]# cat /etc/fstab | grep swap
#/dev/mapper/cl-swap swap swap defaults 0 0 

 

2-3) iptables ์„ค์ •

iptables ๋ฅผ ์„ค์ •ํ•˜๊ธฐ ์ „์— br_netfilter ๋ชจ๋“ˆ์ด ๋กœ๋“œ ๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.
๋งŒ์•ฝ ์•„๋ž˜์ฒ˜๋Ÿผ ์•ˆ๋˜์–ด์žˆ๋‹ค๋ฉด #
sudo modprobe br_netfilter ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

[root@kube-manager /]# lsmod | grep br_netfilter
br_netfilter           22256  0
bridge                151336  1 br_netfilter

์ด์ œ iptables ์„ค์ •์„ ๋„ฃ์–ด์ค๋‹ˆ๋‹ค.

[root@kube-manager /]# cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF

์„ค์ •์ด ์ž˜ ๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.

[root@kube-manager /]# cat /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1

์ด์ œ, sysctl ๋ช…๋ น์–ด๋กœ ์„ค์ •์„ ๋กœ๋“œ ํ•ฉ๋‹ˆ๋‹ค.

[root@kube-manager /]# sudo sysctl --system

 

2-4) SELinux ์„ค์ •

SELinux๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. 
์•„๋ž˜ ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•˜์—ฌ SELinux๋ฅผ ๋„๊ณ , ์žฌ๋ถ€ํŒ… ๋˜๋”๋ผ๋„ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋„๋ก ์„ค์ •์„ ๋ณ€๊ฒฝํ•ฉ๋‹ˆ๋‹ค.

[root@kube-manager /]# sudo setenforce 0

[root@kube-manager /]# sudo sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config

์„ค์ •ํŒŒ์ผ ํ™•์ธ ์‹œ ์•„๋ž˜ ์ฒ˜๋Ÿผ "SELINUX=permissive"๋กœ ๋‚˜์˜ค๋ฉด ๋ฉ๋‹ˆ๋‹ค. :)

[root@kube-manager /]# cat /etc/selinux/config

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=permissive
# SELINUXTYPE= can take one of three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

 

์ด์ œ ์ด๋ฒˆ ๋‹จ๊ณ„๋Š” ์™„๋ฃŒ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.
๋‹ค์Œ ๋‹จ๊ณ„๋กœ ๋„˜์–ด๊ฐ‘๋‹ˆ๋‹ค! 

 

3. Kubeadm ์„ค์น˜

๊ฐ ๋…ธ๋“œ์— dockeradm๋ฅผ ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค. 
์œ„์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ๋ชจ๋“  ๋…ธ๋“œ์— ๋™์ผํ•˜๊ฒŒ ์ž‘์—… ํ•ด์ฃผ์„ธ์š” :) 

์•„๋ž˜ ๋”๋ณด๊ธฐ๋ฅผ ํด๋ฆญํ•˜์—ฌ ํ™•์ธํ•˜์„ธ์š”๐Ÿฅณ

๋”๋ณด๊ธฐ

๋จผ์ €, ๋ ˆํฌ์ง€ํ† ๋ฆฌ๋ฅผ ๋“ฑ๋กํ•ฉ๋‹ˆ๋‹ค. 

[root@kube-manager /]# cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-\$basearch
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
exclude=kubelet kubeadm kubectl
EOF

 ์ž˜ ๋“ฑ๋ก๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•ด๋ด…๋‹ˆ๋‹ค. 

[root@kube-manager /]# cat /etc/yum.repos.d/kubernetes.repo

[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-$basearch
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
exclude=kubelet kubeadm kubectl

์ด์ œ ์ง„์งœ ์„ค์น˜ํ•ด๋ด…์‹œ๋‹ค! 

[root@kube-manager /]# sudo yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes

์„ค์น˜๊ฐ€ ์ž˜ ๋˜์—ˆ๋Š”์ง€ rpm๋ช…๋ น์–ด๋กœ ํ™•์ธํ•ด๋ด…์‹œ๋‹ค. :) ์„ค์น˜๊ฐ€ ์ž˜ ๋˜์—ˆ๋„ค์š”!

[root@kube-manager /]# rpm -qa | grep kube

kubeadm-1.19.4-0.x86_64
kubernetes-cni-0.8.7-0.x86_64
kubectl-1.19.4-0.x86_64
kubelet-1.19.4-0.x86_64

์ž, ์ด์ œ kubelet ๋ฐ๋ชฌ์„ ์žฌ์‹œ์ž‘ ๋˜๋”๋ผ๋„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก enable ํ•ฉ๋‹ˆ๋‹ค.

[root@kube-manager /]# sudo systemctl enable --now kubelet

Created symlink from /etc/systemd/system/multi-user.target.wants/kubelet.service to /usr/lib/systemd/system/kubelet.service.

 

์—ฌ๊ธฐ๊นŒ์ง€๊ฐ€ Kubenetes ์„ค์น˜ ๊ณผ์ •์ด์—ˆ์Šต๋‹ˆ๋‹ค. 

๋‹ค์Œ ๊ณผ์ •์—์„œ ์ปจํŠธ๋กคํ”Œ๋ ˆ์ธ ๊ตฌ์„ฑ์„ ํ•ด๋ด…์‹œ๋‹ค!!

 

 

728x90