๐[Sprint1] ์ฟ ๋ฒ๋คํฐ์ค ๋ฌด๊ฒ๊ฐ ์๊ฒ ์ค์นํ๊ธฐ
- -
*ํด๋น ๊ธ์ ์ธํ๋ฐ ใ์ฟ ๋ฒ๋คํฐ์ค ์ด๋๋ ํด๋์ค (์ง์ํธ) - Sprint1ใ ๊ฐ์๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ๋ณต์ต&์ ๋ฆฌ ์ฐจ ์์ฑ๋์์ต๋๋ค.
๐์ค์ต ํ๊ฒฝ ๊ตฌ์ฑ
์ด๋ฒ์๋ ์ฟ ๋ฒ๋คํฐ์ค ์ค์ตํ๊ฒฝ์ ๊ตฌ์ฑํด๋ณด๊ณ ์ ํฉ๋๋ค.
๊ฐ์ธ์ ์ผ๋ก ๊ณต๋ถํ ๋๋ VMware๊ด๋ จ ์ ํ์ ์ฌ์ฉํ๋ค๋ณด๋ VMware Workstation์ ํตํด์ ์งํํ๋ ค๊ณ ํ์ผ๋, ์ฒซ ์ค์ต์ด๊ธฐ ๋๋ฌธ์ ์ค์ต๋ด์ฉ์ ๋ ์ง์คํ๊ณ ์ VirtualBox๋ก ์งํํ์ต๋๋ค.
๐Vagrant๋ฅผ ํ์ฉํ์ฌ VM ์์ฑ
* OS: Rocky Linux
* ์ค์ต ์คํฌ๋ฆฝํธ๋ฅผ ํ์ฉํ์ฌ k8s ๋ง์คํฐ ๋
ธ๋ ์์ฑ
# Vagrant ํด๋ ์์ฑ
D:\> mkdir k8s
# Vagrant ์คํฌ๋ฆฝํธ ๋ค์ด๋ก๋
D:\k8s> curl -O https://raw.githubusercontent.com/k8s-1pro/install/main/ground/k8s-1.27/vagrant-2.3.4/Vagrantfile
# Rocky Linux Repo ์ธํ
D:\k8s> curl -O https://raw.githubusercontent.com/k8s-1pro/install/main/ground/k8s-1.27/vagrant-2.3.4/rockylinux-repo.json
D:\k8s> vagrant box add rockylinux-repo.json
# Vagrant Disk ์ค์ Plugin ์ค์น
D:\k8s> vagrant plugin install vagrant-vbguest vagrant-disksize
# Vagrant ์คํ (VM์์ฑ)
D:\k8s> vagrant up
์คํฌ๋ฆฝํธ๋ฅผ ์ด์ฉํ๋ฉด ๋จ ๋ช ๋ถ๋ง์ ๋ง์คํฐ ๋
ธ๋ ์์ฑ์ด ๊ฐ๋ฅํด์ง๋๋ค.. ์ฌ๊ธฐ์ ๊ทธ์น๋ฉด ์๋๊ฒ ์ฃ ..?
์ด๋ป๊ฒ ์คํฌ๋ฆฝํธ๊ฐ ๊ตฌ์ฑ๋์ด ๋ง์คํฐ ๋
ธ๋๊ฐ ์์ฑ๋์๋์ง ์๋์ ๊ฐ์ ์์์ ๋ฐ๋ผ ๊ทธ ๊ณผ์ ์ ์ฒ์ฒํ ์ดํด๋ณด๋ฉด ์ดํดํ๋ ๋ฐ ๋์์ด ๋ฉ๋๋ค.
๐์คํฌ๋ฆฝํธ ๋ง๋ณด๊ณ ๋ฏ์ด๋ณด๊ธฐ
๐OS ๊ตฌ์ฑ
Vagrant.configure("2") do |config|
config.vm.box = "rockylinux/8" → OS ์ข
๋ฅ ์ ํ
config.disksize.size = "50GB" → ๋์คํฌ ํฌ๊ธฐ ์ค์
config.vbguest.installer_options = { allow_kernel_upgrade: true }
config.vbguest.auto_update = false
config.vm.provision :shell, privileged: true, inline: $install_default
config.vm.define "master-node" do |master| → VM Name ์ค์
master.vm.hostname = "k8s-master" → hostname ์ค์
master.vm.network "private_network", ip: "192.168.56.30" → ip ์ค์ (private ๋์ญ)
master.vm.provider :virtualbox do |vb|
vb.memory = 6144 → ๋ฉ๋ชจ๋ฆฌ ์ค์
vb.cpus = 4 → CPU ์ค์
vb.customize ["modifyvm", :id, "--firmware", "efi"]
end
master.vm.provision :shell, privileged: true, inline: $install_master
end
end
$install_default = <<-SHELL → node๋ณ ๊ธฐ๋ณธ ์ค์น ์ธ์ด ์ค์
๋คํธ์ํฌ๋ Private-Network๋ก ๋ด๋ถ ํต์ ์ ํ๊ณ , NAT๋ฅผ ํตํด ์ธ๋ถ ์ธํฐ๋ท๋ง๊ณผ ํต์ ํ์ฌ Kubernetes์ค์น ์ ํ์ํ ํจํค์ง๋ค์ ๋ฐ์ ์ ์๋๋ก ํ์์ต๋๋ค.
๐ ์ปจํ ์ด๋ ๋ฐํ์ ๋ฐ ์ฟ ๋ฒ๋คํฐ์ค ์ค์น
๊ธฐ๋ณธ์ ์ธ ํ์์กด ์ค์ ๊ณผ ํจํค์ง ์ ๋ฐ์ดํธ๋ฅผ ์งํ ํ ํ ๋ณธ๊ฒฉ์ ์ผ๋ก ์ฟ ๋ฒ๋คํฐ์ค๋ฅผ ์ค์นํ๊ธฐ ์ํ ์์ ์ ์์ํฉ๋๋ค.
# ๋ฐฉํ๋ฒฝ off ๋ฐ ๋นํ์ฑํ
[root@k8s-master ~]# systemctl stop firewalld
[root@k8s-master ~]# systemctl disable firewalld
# swap ๋นํ์ฑํ
[root@k8s-master ~]# swapoff -a && sed -i '/ swap / s/^/#/' /etc/fstab
# swap ์ฌ์ฉ๋ฅ 0 ํ์ธ
[root@k8s-master ~]# free
total used free shared buff/cache available
Mem: 6063280 1599260 130720 19168 4333300 4161612
Swap: 0 0 0
# fstab์ swap ๋ถ๋ถ ์ฃผ์์ฒ๋ฆฌ ํ์ธ
[root@k8s-master ~]# cat /etc/fstab | grep swap
#/swapfile none swap defaults 0 0
IPv4๋ฅผ ํฌ์๋ฉํ์ฌ iptables๊ฐ ๋ธ๋ฆฌ์ง๋ ํธ๋ํฝ์ ๋ณด๊ฒ ํ๊ธฐ
(๋ฆฌ๋
์ค ๋
ธ๋์ iptables๊ฐ ๋ธ๋ฆฌ์ง๋ ํธ๋ํฝ์ ์ฌ๋ฐ๋ฅด๊ฒ ๋ณด๊ธฐ ์ํ ์๊ตฌ ์ฌํญ์ผ๋ก ํด๋น ์ธํ
๊ฐ์ ํ์ธ)
# ์ค์ ์ธํ
ํ์ธ
[root@k8s-master ~]# cat /etc/modules-load.d/k8s.conf
overlay
br_netfilter
[root@k8s-master ~]# cat /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.ipv4.ip_forward = 1
# ๋ชจ๋ ์ ์ฌ ํ์ธ
[root@k8s-master ~]# lsmod | grep overlay
overlay 139264 35
[root@k8s-master ~]# lsmod | grep br_netfilter
br_netfilter 24576 0
bridge 290816 1 br_netfilter
์ปจํ ์ด๋ ๋ฐํ์ ์ค์น
# docker repo ์ค์
[root@k8s-master ~]# yum install -y yum-utils
[root@k8s-master ~]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
# containerd ์ค์น
[root@k8s-master ~]# yum install -y containerd.io-1.6.21-3.1.el8
[root@k8s-master ~]# systemctl daemon-reload
[root@k8s-master ~]# systemctl enable --now containerd
# containerd CRI ํ์ฑํ
[root@k8s-master ~]# sed -i 's/^disabled_plugins/#disabled_plugins/' /etc/containerd/config.toml
# ["cri"] ์ฃผ์์ฒ๋ฆฌ ํ์ธ
[root@k8s-master ~]# cat /etc/containerd/config.toml
# Copyright 2018-2022 Docker Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#disabled_plugins = ["cri"]
...
[root@k8s-master ~]# systemctl restart containerd
kubeadm ์ค์น
# kubernetes.repo ์ค์
cat /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
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
# repo ํ์ธ
[root@k8s-master yum.repos.d]# yum repolist enabled
repo id repo name
appstream Rocky Linux 8 - AppStream
baseos Rocky Linux 8 - BaseOS
docker-ce-stable Docker CE Stable - x86_64
extras Rocky Linux 8 - Extras
kubernetes Kubernetes
# SELinux ์ค์ ํ์ธ
[root@k8s-master ~]# cat /etc/selinux/config
SELINUX=permissive → permissive ํ์ธ
[root@k8s-master ~]# sestatus
Current mode: permissive → permissive ํ์ธ
Mode from config file: permissive → permissive ํ์ธ
# kubelet, kubeadm, kubectl ํจํค์ง ์ค์น
[root@k8s-master ~]# yum install -y kubelet-1.27.1-0.x86_64 kubeadm-1.27.1-0.x86_64 kubectl-1.27.1-0.x86_64 --disableexcludes=kubernetes
systemctl enable --now kubelet
๐ ๋ง์คํฐ ๋ ธ๋ ์ธํ
kubeadm์ผ๋ก ํด๋ฌ์คํฐ ์์ฑ
# pod ๋คํธ์ํฌ ์ธํ
[root@k8s-master ~]# kubeadm init --pod-network-cidr=20.96.0.0/12 --apiserver-advertise-address 192.168.56.30
# master node ์ํํ์ธ
[root@k8s-master ~]# kubectl get node
NAME STATUS ROLES AGE VERSION
k8s-master Ready control-plane 85m v1.27.1
# pod network cidr ์ค์ ํ์ธ
[root@k8s-master ~]# kubectl cluster-info dump | grep -m 1 cluster-cidr
"--cluster-cidr=20.96.0.0/12",
# apiserver advertise address ์ ์ฉ ํ์ธ
[root@k8s-master ~]# kubectl cluster-info
Kubernetes control plane is running at https://192.168.56.30:6443
# kubernetes component pod ํ์ธ (Running ํ์ธ)
[root@k8s-master ~]# kubectl get pods -n kube-system
NAME READY STATUS RESTARTS AGE
coredns-5d78c9869d-l8kpn 1/1 Running 0 85m
coredns-5d78c9869d-qftxg 1/1 Running 0 85m
etcd-k8s-master 1/1 Running 0 86m
kube-apiserver-k8s-master 1/1 Running 0 86m
kube-controller-manager-k8s-master 1/1 Running 0 86m
kube-proxy-tht2n 1/1 Running 0 85m
kube-scheduler-k8s-master 1/1 Running 0 86m
metrics-server-7db4fb59f9-r8zwv 1/1 Running 0 85m
# kubectl ์ฌ์ฉ ์ค์
[root@k8s-master ~]# mkdir -p $HOME/.kube
[root@k8s-master ~]# cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
[root@k8s-master ~]# chown $(id -u):$(id -g) $HOME/.kube/config
# ์ธ์ฆ์ ์ค์ ํ์ธ
[root@k8s-master ~]# cat ~/.kube/config
...
server: https://192.168.56.30:6443 → IP ์ค์ ํ์ธ
...
# Pod Network ์ค์น (calico)
[root@k8s-master ~]# kubectl create -f https://raw.githubusercontent.com/k8s-1pro/install/main/ground/k8s-1.27/calico-3.25.1/calico.yaml
[root@k8s-master ~]# kubectl create -f https://raw.githubusercontent.com/k8s-1pro/install/main/ground/k8s-1.27/calico-3.25.1/calico-custom.yaml
# Calico Pod ์ํ ํ์ธ (Running ํ์ธ)
[root@k8s-master ~]# kubectl get -n calico-system pod
NAME READY STATUS RESTARTS AGE
calico-kube-controllers-789dc4c76b-ls888 1/1 Running 0 97m
calico-node-qck7p 1/1 Running 0 97m
calico-typha-86d895795d-wghjr 1/1 Running 0 97m
csi-node-driver-69qsk 2/2 Running 0 97m
[root@k8s-master ~]# kubectl get -n calico-apiserver pod
NAME READY STATUS RESTARTS AGE
calico-apiserver-5c57b4569f-dd6qk 1/1 Running 0 96m
calico-apiserver-5c57b4569f-s5h6p 1/1 Running 0 96m
# Calico์ pod network cidr ์ ์ฉ ํ์ธ
[root@k8s-master ~]# kubectl get installations.operator.tigera.io default -o yaml | grep cidr
cidr: 20.96.0.0/12
cidr: 20.96.0.0/12
# Master์ Pod๋ฅผ ์์ฑ ํ ์ ์๋๋ก ์ค์
[root@k8s-master ~]# kubectl taint nodes k8s-master node-role.kubernetes.io/control-plane-
# Taints ํด์ ํ์ธ
[root@k8s-master ~]# kubectl describe nodes | grep Taints
Taints: <none>
์ฟ ๋ฒ๋คํฐ์ค ํธ์ ๊ธฐ๋ฅ ์ค์น
# kubectl ์๋์์ฑ ๊ธฐ๋ฅ ์ค์
echo "source <(kubectl completion bash)" >> ~/.bashrc
echo 'alias k=kubectl' >>~/.bashrc
echo 'complete -o default -F __start_kubectl k' >>~/.bashrc
# kubectl ์๋์์ฑ ๊ธฐ๋ฅ ์ค์ ํ์ธ
[root@k8s-master ~]# cat ~/.bashrc
# .bashrc
# User specific aliases and functions
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
source <(kubectl completion bash)
alias k=kubectl
complete -o default -F __start_kubectl k
# Dashboard ์ค์น
kubectl create -f https://raw.githubusercontent.com/k8s-1pro/install/main/ground/k8s-1.27/dashboard-2.7.0/dashboard.yaml
# Dashboard Running ํ์ธ
[root@k8s-master ~]# kubectl get pod -n kubernetes-dashboard
NAME READY STATUS RESTARTS AGE
dashboard-metrics-scraper-5cb4f4bb9c-rpwk4 1/1 Running 0 111m
kubernetes-dashboard-6bc7c98694-5d9bz 1/1 Running 0 111m
# Metrics Server ์ค์น
kubectl create -f https://raw.githubusercontent.com/k8s-1pro/install/main/ground/k8s-1.27/metrics-server-0.6.3/metrics-server.yaml
# Metrics Server ์ค์น ํ์ธ
[root@k8s-master ~]# kubectl get pod -n kube-system | grep metrics
metrics-server-7db4fb59f9-r8zwv 1/1 Running 0 112m
๐pod ์ํ ํ์ธ
[root@k8s-master ~]# k get pods -A
NAMESPACE NAME READY STATUS RESTARTS AGE
calico-apiserver calico-apiserver-6d7f77dc86-24nkn 1/1 Running 0 19m
calico-apiserver calico-apiserver-6d7f77dc86-9mjt6 1/1 Running 0 19m
calico-system calico-kube-controllers-789dc4c76b-zf2z6 1/1 Running 0 21m
calico-system calico-node-bsgs5 1/1 Running 0 21m
calico-system calico-typha-956d8d9f5-kwjq5 1/1 Running 0 21m
calico-system csi-node-driver-rwf22 2/2 Running 0 21m
kube-system coredns-5d78c9869d-j4dk6 1/1 Running 0 21m
kube-system coredns-5d78c9869d-zwwhn 1/1 Running 0 21m
kube-system etcd-k8s-master 1/1 Running 0 21m
kube-system kube-apiserver-k8s-master 1/1 Running 0 21m
kube-system kube-controller-manager-k8s-master 1/1 Running 0 21m
kube-system kube-proxy-gx62q 1/1 Running 0 21m
kube-system kube-scheduler-k8s-master 1/1 Running 0 21m
kube-system metrics-server-7db4fb59f9-jl8mz 1/1 Running 0 21m
kubernetes-dashboard dashboard-metrics-scraper-5cb4f4bb9c-2cr78 1/1 Running 0 21m
kubernetes-dashboard kubernetes-dashboard-6bc7c98694-zd7xz 1/1 Running 0 21m
tigera-operator tigera-operator-549d4f9bdb-svv47 1/1 Running 0 21m
๐ Kubernetes Dashboard ์ ์ ๋ฐ ์ํ ํ์ธ
https://192.168.56.30:30000/#/login
'Containers > Kubernetes' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๐[Sprint1] ์ค๋ฌด์์ ๋๊ปด๋ณธ ์ฟ ๋ฒ๋คํฐ์ค๊ฐ ์ ๋ง ํธํ ์ด์ (0) | 2023.12.06 |
---|---|
๐[Sprint1] ์ปจํ ์ด๋ ํ๋ฐฉ ์ ๋ฆฌ (0) | 2023.09.16 |
๋น์ ์ด ์ข์ํ ๋งํ ์ฝํ ์ธ
์์คํ ๊ณต๊ฐ ๊ฐ์ฌํฉ๋๋ค