본문 바로가기
개발 이야기/Kubernetes

Minikube 설치해보기

by 농개 2024. 3. 2.

Minikube는 로컬 컴퓨터에서 Kubernetes 클러스터를 실행하는 도구로, 개발 및 테스트 목적에 유용합니다.

컴퓨터 내 가상 머신 안에 단일 노드 Kubernetes 클러스터를 설정하여

전체 규모의 클러스터나 클라우드 인프라 없이도 Kubernetes를 실험할 수 있게 해줍니다.

 

해당 포스팅에서는 Minikube를 로컬 PC에 설치하는 방법을 정리합니다.

먼저 저의 로컬 PC 환경은 아래와 같습니다.

사전에 도커가 받드시 설치되어 있어야합니다.

  • MacOS Sonoma (칩: M2)
  • Docker version 25.0.3 (Docker Desktop on Mac 사용 중)

 

1. 설치

MacOS에서는 Homebrew가 설치되어 있다면, 아래 명령어로 간단히 설치 가능합니다.

터미널을 열러 brew install minikube를 실행 시켜 줍니다.

 ~  brew install minikube
Running `brew update --auto-update`...
==> Auto-updated Homebrew!
Updated 2 taps (homebrew/core and homebrew/cask).
==> New Formulae
actions-batch                 gptscript                     liborigin                     mmdbinspect                   npm-check-updates             taskopen
bpftop                        kubeshark                     mdsh                          nmail                         pkl
==> New Casks
stashpad

Warning: Cask minikube was renamed to homebrew/core/minikube.
==> Downloading https://ghcr.io/v2/homebrew/core/minikube/manifests/1.32.0
############################################################################################################################################################################# 100.0%
==> Fetching dependencies for minikube: kubernetes-cli
==> Downloading https://ghcr.io/v2/homebrew/core/kubernetes-cli/manifests/1.29.2
...(생략)

 

만약 OS가 다르다면

공식 문서에서 가이드 참고하시면 될 것 같네요.

공식문서: https://minikube.sigs.k8s.io/docs/start/

공식홈페이지 가이드 캡쳐

 

설치가 끝났으면 실행 시켜 봅시다.

minikube start 실행!

 ~ minikube start
😄  Darwin 14.3.1 (arm64) 의 minikube v1.32.0
✨  자동적으로 docker 드라이버가 선택되었습니다
📌  Using Docker Desktop driver with root privileges
👍  minikube 클러스터의 minikube 컨트롤 플레인 노드를 시작하는 중
🚜  베이스 이미지를 다운받는 중 ...
💾  쿠버네티스 v1.28.3 을 다운로드 중 ...
...(생략)

 

 

2. 노드 및 파드 확인

설치가 끝났다면 아래 명령어로 노드 정보를 확인해 볼 수 있습니다.

kubectl get nodes

 ~ kubectl get nodes
NAME       STATUS   ROLES           AGE     VERSION
minikube   Ready    control-plane   4m27s   v1.28.3

단일 노드로 구성되어 있어서 하나만 뜨네요.

 

그리고 아래 커맨드를 통해 모든 POD를 확인 할 수 있습니다.

kubectl get po -A

 ~ kubectl get po -A
NAMESPACE     NAME                               READY   STATUS    RESTARTS       AGE
kube-system   coredns-bjekblejeklrfjlq           1/1     Running   0              5m3s
kube-system   etcd-minikube                      1/1     Running   0              5m17s
kube-system   kube-apiserver-minikube            1/1     Running   0              5m17s
kube-system   kube-controller-manager-minikube   1/1     Running   0              5m17s
kube-system   kube-proxy-vj1j2                   1/1     Running   0              5m4s
kube-system   kube-scheduler-minikube            1/1     Running   0              5m17s
kube-system   storage-provisioner                1/1     Running   1 (5m3s ago)   5m16s

쿠버네티스 시스템에 필요한 요소들이 기본 POD 형태로 실행이 되는 것 같네요.

 

 

3. 서비스 배포

서버 애플리케이션을 배포해봅시다.

여기서는 Springboot Docker image 를 사용합니다.

# Dockerfile
FROM amazoncorretto:17

# argument jar path
ARG JAR_FILE=build/libs/*.jar

# copy jar path
COPY ${JAR_FILE} app.jar

# execute
ENTRYPOINT ["java", "-jar", "app.jar"]

 

이 후, docker build로 도커 이미지를 빌드합니다.

docker build -t springboot-exam:0.0.1 .

 

이미지가 만들어 졌다면

아래 명령어로 배포(Deployment) 해봅시다.

~ kubectl create deployment springboot-exam --image=springboot-exam:0.0.1
deployment.apps/springboot-exam created
  • kubectl create deployment {서비스명} --image={도커이미지 및 태그}

그리고 테스트 접근을 위해 포트를 노출(Expose) 시켜줍니다.

 ~ kubectl expose deployment springboot-exam --type=NodePort --port=8080
service/springboot-exam exposed
  • kubectl expose deployment {서비스명}--type=NodePort --port={포트번호}

 

🙁 서비스가 Running 상태가 아니라면

 ~ kubectl get po -A
NAMESPACE     NAME                               READY   STATUS             RESTARTS      AGE
default       springboot-exam-c6d65585c-s4hg9    0/1     ImagePullBackOff   0             4m31s
kube-system   coredns-dwwwwwwwwwwwwwww           1/1     Running            0             35m
kube-system   etcd-minikube                      1/1     Running            0             36m

springboot-exam 파드의 상태가 이상합니다.

ImagePullBackOff

아마도 도커이미지를 Pull 하는 과정에서 문제가 있었나 봅니다.

 

이벤트 로그를 확인해봅시다.

 ~ kubectl get events
LAST SEEN   TYPE      REASON                    OBJECT                                 MESSAGE
43m         Normal    Starting                  node/minikube                          Starting kubelet.
43m         Normal    NodeAllocatableEnforced   node/minikube                          Updated Node Allocatable limit across pods
43m         Normal    NodeHasSufficientMemory   node/minikube                          Node minikube status is now: NodeHasSufficientMemory
43m         Normal    NodeHasNoDiskPressure     node/minikube                          Node minikube status is now: NodeHasNoDiskPressure
43m         Normal    NodeHasSufficientPID      node/minikube                          Node minikube status is now: NodeHasSufficientPID
42m         Normal    RegisteredNode            node/minikube                          Node minikube event: Registered Node minikube in Controller
42m         Normal    Starting                  node/minikube
11m         Normal    Scheduled                 pod/springboot-exam-c6d65585c-s4hg9    Successfully assigned default/springboot-exam-c6d65585c-s4hg9 to minikube
9m52s       Normal    Pulling                   pod/springboot-exam-c6d65585c-s4hg9    Pulling image "springboot-exam:0.0.1"
9m48s       Warning   Failed                    pod/springboot-exam-c6d65585c-s4hg9    Failed to pull image "springboot-exam:0.0.1": Error response from daemon: 
pull access denied for springboot-exam, repository does not exist or may require 'docker login': denied: requested access to the resource is denied

repository does not exist or may require docker login: denied 가 보이네요.

이는 Minikube 노드에서 이미지 레포지토리를 못찾아서 생긴 문제입니다.

아래처럼 docker 환경 변수를 Minikube에 추가하여 해결 가능합니다.

단, 아래 명령어는 일회성이라 터미널 실행 마다 해줘야 합니다.

그리고 명령어 실행 후, 도커 이미지를 다시 빌드해줘야합니다.

~ eval $(minikube docker-env)

 

다른 방법으로는

아래 명령어로 도커이미지를 직업 Minikube 레포지토리로 옮기는 방법이 있습니다.

minikube image load springboot-exam:0.0.1

 

다시 이벤트 로그를 확인해보니

14m         Normal    SuccessfulCreate          replicaset/springboot-exam-c6d65585c   Created pod: springboot-exam-c6d65585c-s4hg9
14m         Normal    ScalingReplicaSet         deployment/springboot-exam             Scaled up replica set springboot-exam-c6d65585c to 1

정상적으로 파드가 생성되었네요.

 

 

4. 서비스 접속 확인

아래 명령어로 서비스 접근 테스트 가능합니다.

~  minikube service springboot-exam
|-----------|-----------------|-------------|---------------------------|
| NAMESPACE |      NAME       | TARGET PORT |            URL            |
|-----------|-----------------|-------------|---------------------------|
| default   | springboot-exam |        8080 | http://xxx.xxx.xx.xx:12314 |
|-----------|-----------------|-------------|---------------------------|
🏃  springboot-exam 서비스의 터널을 시작하는 중
|-----------|-----------------|-------------|------------------------|
| NAMESPACE |      NAME       | TARGET PORT |          URL           |
|-----------|-----------------|-------------|------------------------|
| default   | springboot-exam |             | http://127.0.0.1:63137 |
|-----------|-----------------|-------------|------------------------|
🎉  Opening service default/springboot-exam in default browser...
❗  Because you are using a Docker driver on darwin, the terminal needs to be open to run it.

 

위와같이 minikube service springboot-exam 명령어를 통해 서비스 접근 확인이 가능합니다.

 

다른 방법으로는 포트포워딩을 통해 로컬 포트와 맵핑 하여 테스트 해볼 수 있습니다.

kubectl port-forward service/springboot-exam 8080:8080

 

위처럼 127.0.0.1:8080 로 접근이 되는 것을 확인 할 수 있습니다.

 

 

5. Minikube 종료

minikube stop 			# 정지
minikube delete 		# 로컬 클러스터 삭제
minikube delete --all 	# 로컬 클러스터 삭제 및 프로필 삭제