인프라/쿠버네티스

kubernetes 테스트 환경 구축

G-egg 2025. 6. 3. 22:49
반응형

구성

마스터 노드와 워커 노드, 사설 DNS 노드로 구성한다.

 

IP 대역

192.168.0.0/24 bridge

 

사설 dns 노드

  • 스펙 (cpu 1코어 / ram 2GB(2048) / 25GB) 
  • apt update
  • apt install bind9 bindutils -y
  • vim /etc/bind/named.conf.options
options {
	directory "/var/cache/bind";
    
    listen-on { any; };
    allow-query { 192.168.0.0/24; };
    
    recursion yes;
    allow-recursion { 192.168.0.0/24; };
    
    forwarders {
    	8.8.8.8;
        8.8.4.4;
    }
    dnssec-validation no;
    listen-on-v6 { none; };
}

 

  • vim /etc/bind/named.conf.local
zone "demo.test" {
	type master;
    file "/etc/bind/zones/demo.test";
};
  • mkdir /etc/bind/zones
  • vim /etc/bind/zones/demo.test
$TTL	60
@	IN	SOA	ns.demo.test.	admin.demo.test.	(
                    3			; Serial
                    120			; Refresh
                    60			; Retry
                    2419200		; Expire
                    60 )		; Negative Cache TTL
;
@	IN	NS	ns
NS	IN	A	192.168.0.8
*	IN	A	192.168.0.3

 

마스터 노드

  • cpu 2코어 / ram 4GB(4096)

워커 노드

  • cpu 4코어 / ram 8GB(8192)
  • 마스터노드 clone 후 ip 변경
    • vim /etc/netplan/50-cloud-init.yaml 에서 ip 수정 && hostnamectl set-hostname worker --static

 

마스터 노드 && 워커노드 공통 구성

  • https://v1-32.docs.kubernetes.io/docs/setup/production-environment/container-runtimes/#prerequisite-ipv4-forwarding-optional
  • containerd 설치
    • wget https://github.com/containerd/containerd/releases/download/v버전/containerd-버전-linux-아키텍처.tar.gz
    • wget tar Cxzvf /usr/local containerd-버전-linux-아키텍처.tar.gz
    • wget https://raw.githubusercontent.com/containerd/containerd/main/containerd.service -P /usr/local/lib/systemd/system/
    • [ 참고 ] https://github.com/containerd/containerd/blob/main/docs/getting-started.md
  • runc 설치
    • wget https://github.com/opencontainers/runc/releases/download/v버전/runc.아키텍처 -O /usr/local/sbin/runc
      • https://github.com/opencontainers/runc/releases 에서 runc 버전 및 아키텍처 확인
    • chmod 755 /usr/local/sbin/runc
    • systemctl restart containerd

 

  • containerd 설정
    • mkdir -p /etc/containerd
    • containerd config default > /etc/containerd/config.toml
    • (선택) https://v1-32.docs.kubernetes.io/docs/setup/production-environment/container-runtimes/#containerd-systemd
    • 스왑 메모리 설정
      •  /etc/fstab swap 부분 주석 처리
      • 재부팅 이후 swapon --show 결과 없음 확인
      • [ 참고 ] https://v1-32.docs.kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/#swap-configuration
  • kubectl kubeadm kubelet 설치
    • [ 참고 ] https://v1-32.docs.kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/#swap-configuration

 

마스터 노드 구성

 

  • kubeadm init --apiserver-advertise-address 192.168.0.2 --service-cidr="10.254.0.0/16" --pod-network-cidr="10.100.0.0/16"
  • mkdir -p $HOME/.kube
  • cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  • chown $(id -u):$(id -g) $HOME/.kube/config

워커 노드 연결

  • kubeadm join 마스터노드:6443 --token 토큰값 \
            --discovery-token-ca-cert-hash sha256:해시값

편의성 제공

  • https://v1-32.docs.kubernetes.io/docs/reference/kubectl/quick-reference/#kubectl-autocomplete

 

CNI 설치

  • https://docs.tigera.io/calico/latest/getting-started/kubernetes/self-managed-onprem/onpremises#install-calico
반응형