Vagrant는 HashiCorp사에서 개발한 IaC 도구 중 하나로 단일 워크를로우에서 가상머신 환경을 스크립트 형태로 빠르고 신속하게 만들 수 있는 도구이다.
Vagrant 설치
위 링크에 접속하여 자신에게 맞는 OS에 패키지를 설치하면 된다.
버추얼박스(영어: VirtualBox)는 리눅스, macOS, 솔라리스, 윈도우를 게스트 운영 체제로 가상화하는 x86 가상화 소프트웨어이다.
VirtualBox 설치
VirtualBox 설치는 공식 홈페이지를 통해서 할 수 있다.
kubernetes starter kit / 쉽게 시작하는 쿠버네티스
위 링크는 조훈님께서 올려주신 Github 링크이며, Vagrant를 통해 K8S 환경을 빠르게 구축할 수 있다.
또한, 작성자는 Windows 환경에서 사용중이기 때문에 PowerShell을 사용해보았다.
25년 1월 23일 기준 k8s 1.30 버전이며, 구성을 위한 깃허브 링크도 업로드하였다.
k8s v1.30 github 해당 링크는 작성자의 깃허브이다.
# 환경 구성
$ vagrant up
Bringing machine 'm-k8s-1.25.0' up with 'virtualbox' provider...
Bringing machine 'w1-k8s-1.25.0' up with 'virtualbox' provider...
Bringing machine 'w2-k8s-1.25.0' up with 'virtualbox' provider...
Bringing machine 'w3-k8s-1.25.0' up with 'virtualbox' provider...
==> m-k8s-1.25.0: Checking if box 'sysnet4admin/CentOS-k8s' version '0.8.0' is up to date...
==> m-k8s-1.25.0: Clearing any previously set forwarded ports...
==> m-k8s-1.25.0: Clearing any previously set network interfaces...
==> m-k8s-1.25.0: Preparing network interfaces based on configuration...
m-k8s-1.25.0: Adapter 1: nat
m-k8s-1.25.0: Adapter 2: hostonly
==> m-k8s-1.25.0: Forwarding ports...
m-k8s-1.25.0: 22 (guest) => 60010 (host) (adapter 1)
==> m-k8s-1.25.0: Running 'pre-boot' VM customizations...
==> m-k8s-1.25.0: Booting VM...
==> m-k8s-1.25.0: Waiting for machine to boot. This may take a few minutes...
m-k8s-1.25.0: SSH address: 127.0.0.1:60010
m-k8s-1.25.0: SSH username: vagrant
m-k8s-1.25.0: SSH auth method: private key
==> m-k8s-1.25.0: Machine booted and ready!
==> m-k8s-1.25.0: Checking for guest additions in VM...
m-k8s-1.25.0: The guest additions on this VM do not match the installed version of
m-k8s-1.25.0: VirtualBox! In most cases this is fine, but in rare cases it can
m-k8s-1.25.0: prevent things such as shared folders from working properly. If you see
m-k8s-1.25.0: shared folder errors, please make sure the guest additions within the
m-k8s-1.25.0: virtual machine match the version of VirtualBox you have installed on
m-k8s-1.25.0: your host and reload your VM.
m-k8s-1.25.0:
m-k8s-1.25.0: Guest Additions Version: 5.2.12
m-k8s-1.25.0: VirtualBox Version: 7.0
(중략)
==> w3-k8s-1.25.0: Machine booted and ready!
==> w3-k8s-1.25.0: Checking for guest additions in VM...
w3-k8s-1.25.0: The guest additions on this VM do not match the installed version of
w3-k8s-1.25.0: VirtualBox! In most cases this is fine, but in rare cases it can
w3-k8s-1.25.0: prevent things such as shared folders from working properly. If you see
w3-k8s-1.25.0: shared folder errors, please make sure the guest additions within the
w3-k8s-1.25.0: virtual machine match the version of VirtualBox you have installed on
w3-k8s-1.25.0: your host and reload your VM.
w3-k8s-1.25.0:
w3-k8s-1.25.0: Guest Additions Version: 5.2.12
w3-k8s-1.25.0: VirtualBox Version: 7.0
==> w3-k8s-1.25.0: Setting hostname...
==> w3-k8s-1.25.0: Configuring and enabling network interfaces...
==> w3-k8s-1.25.0: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> w3-k8s-1.25.0: flag to force provisioning. Provisioners marked to run always will still run.
호스트 이름 | IP | 역할 |
---|---|---|
m-k8s | 192.168.1.10 | Master Node |
w1-k8s | 192.168.1.101 | Worker Node |
w2-k8s | 192.168.1.102 | Worker Node |
w3-k8s | 192.168.1.103 | Worker Node |
결과로 위와 같은 정보로 Cluster 가 생성이 될 것이다.
구글에서 호스트하고 있던 저장소가 2024년 1월부로 중단되었고 이를 해결하기 위한 트러블 슈팅 시간이 늘어나 공유하고자 한다.
ℹ Update (January 12, 2024): the legacy Google-hosted repositories are going away in January 2024. Check out the deprecation announcement for more details about this change.
The existing packages in the legacy repositories will be available for the foreseeable future. However, the Kubernetes project can't provide any guarantees on how long is that going to be. The deprecated legacy repositories, and their contents, might be removed at any time in the future and without a further notice period. The legacy package repositories are going away in January 2024.
Link: https://kubernetes.io/blog/2023/08/15/pkgs-k8s-io-introduction/
영향은 모든 CentOs와 Ubuntu를 사용하는 경우이다. (사실 상 거의 모두...)
더 자세한 내용은 아래 링크에서 확인하면 될 것이다.
vagrant 실습 이슈 링크 : https://www.inflearn.com/news/1198141
# Cluster 확인
# kubectl get nodes -o wide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
m-k8s Ready control-plane 51m v1.25.0 192.168.1.10 <none> CentOS Linux 7 (Core) 3.10.0-1160.90.1.el7.x86_64 containerd://1.6.7
w1-k8s Ready <none> 49m v1.25.0 192.168.1.101 <none> CentOS Linux 7 (Core) 3.10.0-1160.90.1.el7.x86_64 containerd://1.6.7
w2-k8s Ready <none> 46m v1.25.0 192.168.1.102 <none> CentOS Linux 7 (Core) 3.10.0-1160.90.1.el7.x86_64 containerd://1.6.7
w3-k8s Ready <none> 44m v1.25.0 192.168.1.103 <none> CentOS Linux 7 (Core) 3.10.0-1160.90.1.el7.x86_64 containerd://1.6.7
VirtualBox 에는 위와 같이 확인이 될 것이고, kubectl 명령을 통한 클러스터 확인은 위의 예시와 같이 나올 것이다.
Vagrant 설치 및 명령어, 사용 예제
만약 Vagrant를 통해 구성 시 SSH 관련하여 Timeout 이 발생한다면 아래 링크도 참고하면 좋을 것같다.
Vagrant로 가상머신 부팅시 SSH auth method: private key 단계에서 멈출 때