๐ŸŒฑ Infra/Container_ Kubernetes

k8s ๋น ๋ฅด๊ฒŒ ์„ค์น˜ํ•˜๊ธฐ

mini_world 2022. 2. 22. 23:41
๋ชฉ์ฐจ ์ ‘๊ธฐ

์ด๋ฒˆ ํฌ์ŠคํŒ…์€ ๋‹จ์ผ๋…ธ๋“œ์— ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค๋ฅผ ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค. ์ฐธ๊ณ 

* ์„ค์น˜ OS: centos-release-7-9.2009.1.el7.centos.x86_64

 

1.  kube ์„ค์น˜

์•„๋ž˜์˜ ์ˆœ์„œ์— ๋”ฐ๋ผ ๋ช…๋ น์–ด๋ฅผ ์ญ‰ ์ž…๋ ฅํ•ด์ค๋‹ˆ๋‹ค. ํ•˜๋‚˜๋ผ๋„ ๋น ํŠธ๋ฆฌ๋ฉด kubeadm init์— ์˜ค๋ฅ˜๊ฐ€ ๋‚˜์˜ค๊ธฐ ๋•Œ๋ฌธ์— ๋น ํŠธ๋ฆฌ๋Š” ๊ฒƒ ์—†์ด ์ž˜ ๋”ฐ๋ผ์˜ค์„ธ์š”!๐Ÿฅฒ

# ๋Ÿฐํƒ€์ž„ docker ์„ค์น˜
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
sudo yum-config-manager --add-repo   https://download.docker.com/linux/centos/docker-ce.repo
sudo yum update -y && sudo yum install -y containerd.io docker-ce docker-ce-cli

# ๋„์ปค ์„ค์ •ํŒŒ์ผ ์ƒ์„ฑ
sudo mkdir /etc/docker
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

# ๋„์ปค ์„œ๋น„์Šค ์žฌ์‹œ์ž‘ ๋ฐ enable
 sudo systemctl restart docker
 sudo systemctl enable docker
 
# iptables ์„ค์ •
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sudo sysctl --system

# selinux ์„ค์ •
sudo setenforce 0
sudo sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config


# kube ๋ ˆํฌ ์„ค์น˜
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

# kube ํŒจํ‚ค์ง€ ์„ค์น˜
sudo yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
sudo systemctl enable --now kubelet

 

์ด์ œ kubectl ๋ช…๋ น์–ด ์‚ฌ์šฉ์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.
์ด์ œ namespace, service, nodes, pods ๋“ฑ ์‚ฌ์šฉํ•˜๊ธฐ ์ด์ „์—! kubeadm init์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.
๐Ÿ‘‰ kubeadm init ์‹คํ–‰ํ•˜๋Š” ์ด์œ ?
kubectl ๋ช…๋ น์–ด๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ master๋…ธ๋“œ์—์„œ๋งŒ ์‹คํ–‰ ๊ฐ€๋Šฅํ•˜๋ฉฐ, kubeadm init์€ ๋งˆ์Šคํ„ฐ๋…ธ๋“œ๋กœ ์‹คํ–‰ํ•˜๊ฒ ๋‹ค๋Š” ์ดˆ๊ธฐ ์„ค์ •์ž…๋‹ˆ๋‹ค.

# ๋งˆ์Šคํ„ฐ ๋…ธ๋“œ๋กœ ์„ค์ •
kubeadm init --apiserver-advertise-address=<ํ˜„์žฌ ํ˜ธ์ŠคํŠธIP> --pod-network-cidr= <ํŒŒ๋“œ๊ฐ€ ์‚ฌ์šฉํ•  IP๋Œ€์—ญ>
kubeadm init --apiserver-advertise-address=10.77.110.102 --pod-network-cidr=192.168.0.0/16

 

์—ฌ๊ธฐ๊นŒ์ง€ ์ง„ํ–‰ ๋˜์—ˆ๋‹ค๋ฉด, ์ง„์งœ๋กœ kubectl ๋ช…๋ น์–ด ์‚ฌ์šฉ์ด ๊ฐ€๋Šฅํ•ด์•ผํ•˜๋Š”๋ฐ, ๋ญ๊ฐ€ ์ž˜ ์•ˆ๋˜์ฃ ...?
์•„๋งˆ coredns ํŒŒ๋“œ๊ฐ€ ์ •์ƒ์ ์œผ๋กœ ์˜ฌ๋ผ์˜ค์ง€ ์•Š์•˜์„๊ฒ๋‹ˆ๋‹ค.

# kube-system ํŒŒ๋“œ ํ™•์ธํ•˜๊ธฐ
kubectl get pods -n kube-system -o wide

 

coredns ๋Š” ๋„คํŠธ์›Œํฌ๊ฐ€ ์„ค์น˜๋˜๊ธฐ ์ด์ „์—๋Š” ์‹œ์ž‘๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ์ œ๋Œ€๋กœ ์„ค์น˜ํ•ด์ค์‹œ๋‹ค. ์ฐธ๊ณ ๋งํฌ

# flannel yaml ๋‹ค์šด๋กœ๋“œ
wget https://raw.githubusercontent.com/flannel-io/flannel/master/Documentation/kube-flannel.yml

# network ๋ถ€๋ถ„ ์ˆ˜์ •
sed -i "s|10.244.0.0|192.168.0.0|" kube-flannel.yml
sed -i "s|v1beta1|v1|" kube-flannel.yml

# ์„ค์ • ์ ์šฉ
kubectl create -f kube-flannel.yml

 

 

์˜ค~๐Ÿ™Œ ์ด์ œ ์ •์ƒ์ ์œผ๋กœ ์˜ฌ๋ผ์™”๋„ค์š”!!!

 

 

 

์ฐธ๊ณ ์ž๋ฃŒ - [๋งํฌ]

728x90