Minikube와 같은 단일 노드 환경은 쿠버네티스를 쉽고 빠르게 체험할 수 있는 좋은 도구지만 컨트롤 플레인과 워커 노드가 어떻게 상호작용하며 클러스터를 이루는지 그 기본 구조를 이해하기 위해, 가상머신(VM) 3대를 이용하여 쿠버네티스 환경을 구축해본다.
| 항목 | 버전 |
|---|---|
| OS | Rocky Linux 8.10 |
| Kubernetes | v1.32.3 |
| Containerd | 1.6.32 |
| Ansible | 2.16.3 |
진행 과정에서 ansible을 사용했다. ansible의 간단한 설정 방법은 https://hd-engineering.tistory.com/13
Ansible 간단 설정
1. SSH 키 배포 (초기 설정)SSH 키 생성 (제어 노드에서)ssh-keygen# → 엔터 3번 (기본 경로 및 패스프레이즈 없이 생성)대상 노드에 공개 키 배포for i in {1..5}; do ssh-copy-id -i ~/.ssh/id_rsa.pub root@ygbaek0${i}.git
hd-engineering.tistory.com
1. /etc/hosts 파일 배포
Ansible을 실행하는 컨트롤 노드에 /etc/hosts 파일을 미리 작성해두고, 모든 k8s 노드에 일괄적으로 배포합니다.
ansible k8s -m copy --args "src=/etc/hosts dest=/etc/hosts"
2. Firewalld 비활성화
쿠버네티스는 자체적인 네트워크 규칙(iptables 등)을 통해 통신을 제어한다. 학습 환경에서는 복잡한 방화벽 포트 설정을 피하기 위해 firewalld를 비활성화함
ansible k8s -m shell -a "systemctl stop firewalld && systemctl disable firewalld" -b
3. swapoff
---
- name: Disable swap permanently
hosts: k8s
become: true
tasks:
- name: Turn off swap immediately
command: swapoff -a
- name: Remove swap entry from /etc/fstab
lineinfile:
path: /etc/fstab
regexp: '^.*swap.*'
state: absent
- name: Ensure swap is not enabled after reboot
command: sysctl vm.swappiness=0
ansible-playbook disable_swap.yml
4. Containerd 설치 및 설정
ontainerd는 쿠버네티스가 컨테이너를 실행하고 관리하기 위해 사용하는 컨테이너 런타임이다. kubelet과 Containerd가 시스템 리소스를 관리하는 방식(cgroup driver)을 통일시켜주어야 안정적으로 동작하므로 Containerd 설정 파일에서 SystemdCgroup = true 로 변경
dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
dnf install containerd -y
systemctl enable --now containerd
containerd config default | sudo tee /etc/containerd/config.toml
# config.toml 수정 (SystemdCgroup = true)
vi /etc/containerd/config.toml
ansible k8s -m copy --args "src=/etc/containerd/config.toml dest=/etc/containerd/config.toml"
ansible k8s -m ansible.builtin.systemd -a "name=containerd state=restarted enabled=true" -b
5. Kubernetes 사전 네트워크 설정
# k8s_sysctl_setup.yml
---
- name: Configure sysctl and modules for Kubernetes
hosts: k8s
become: true
tasks:
- name: Ensure br_netfilter module is loaded at boot
copy:
dest: /etc/modules-load.d/k8s.conf
content: |
br_netfilter
- name: Load br_netfilter module now
modprobe:
name: br_netfilter
state: present
- name: Set sysctl params for Kubernetes networking
copy:
dest: /etc/sysctl.d/k8s.conf
content: |
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
- name: Apply sysctl params without reboot
command: sysctl --system
ansible-playbook k8s_sysctl_setup.yml
6. Kubernetes 패키지 설치
# install_k8s_packages.yml
---
- name: Install Kubernetes components on all nodes (v1.32)
hosts: all
become: true
tasks:
- name: Add Kubernetes repo (v1.32)
copy:
dest: /etc/yum.repos.d/kubernetes.repo
content: |
[kubernetes]
name=Kubernetes
baseurl=https://pkgs.k8s.io/core:/stable:/v1.32/rpm/
enabled=1
gpgcheck=1
gpgkey=https://pkgs.k8s.io/core:/stable:/v1.32/rpm/repodata/repomd.xml.key
exclude=kubelet kubeadm kubectl cri-tools kubernetes-cni
mode: 0644
- name: Set SELinux to permissive mode immediately
command: setenforce 0
when: ansible_selinux.status == "enabled"
- name: Set SELinux to permissive on boot
replace:
path: /etc/selinux/config
regexp: '^SELINUX=enforcing'
replace: 'SELINUX=permissive'
- name: Install Kubernetes packages (v1.32)
yum:
name:
- kubelet
- kubeadm
- kubectl
state: present
disable_excludes: kubernetes
- name: Enable and start kubelet
systemd:
name: kubelet
enabled: true
state: started
ansible-playbook install_k8s_packages.yml
7. Control Plane 초기화
# 커널 버전 에러 무시 --ignore-preflight-errors=SystemVerification
# flannel 사용하기 위해 --pod-network-cidr=10.244.0.0/16
sudo kubeadm init --pod-network-cidr=10.244.0.0/16 --ignore-preflight-errors=SystemVerification
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
출력되는 내용 확인 후 9. 워커 노드 join 단계에서 사용한다
8. cni 설치
kubectl apply -f https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml
9. 워커 노드 Join
워커 노드에서 실행
kubeadm join 192.168.80.241:6443 --token <TOKEN> \
--discovery-token-ca-cert-hash sha256:<HASH> \
--ignore-preflight-errors=SystemVerification
10. 클러스터 확인
kubectl get pods -n kube-system
kubectl get nodes
11. kubectl 자동완성 설정
sudo dnf install -y bash-completion
source <(kubectl completion bash)
echo 'source <(kubectl completion bash)' >> ~/.bashrc'Linux > K8s' 카테고리의 다른 글
| ArgoCD API를 활용한 Application 파라미터 업데이트 (0) | 2026.01.05 |
|---|---|
| Custom metric 기반 HPA 구성하기(httpd) (0) | 2025.11.16 |
| Spring Boot 애플리케이션을 Docker와 Kubernetes로 배포하기 (1) | 2025.07.07 |
| ArgoCD 설치(minikube) (0) | 2025.04.28 |
| k8s host volume mount test (0) | 2024.04.18 |