네모네모새

Minikube 통한 Kubernetes 구축(1. Minikube 소개 및 아키텍쳐) 본문

Kubernetes

Minikube 통한 Kubernetes 구축(1. Minikube 소개 및 아키텍쳐)

네모새 2022. 3. 20. 16:59

Kubernetes 클러스터를 구축하는 방법은 여러가지가 있습니다.

EKS, ECS와 같이 특정 CSP(Cloud Service Provider)에 종속적인 구축 방법이 있고,

kOps와 같이 특정 CSP에 종속적이지 않지만 CSP의 자원을 활용해 클러스터를 구축하는 방법도 있습니다.

Minikube는 특정 환경에 구애받지 않고 로컬에 간편하게 쿠버네티스를 설치할 수 있는 도구입니다.

쿠버네티스를 처음 공부할 때 로컬 환경에 간단하게 쿠버네티스 클러스터를 구축하여 테스트나 실습을 진행할 때 유용합니다.

Minikube Architecture

Minikube의 아키텍쳐를 보면 하나의 VM에 Master와 Node가 구성되어 있고,

우측의 Docker 컨테이너 런타임이 동작하고 있습니다.

일반적인 쿠버네티스 환경에서는 Master Node와 Worker Node가 클러스터 단위로 묶여 동작합니다.

하지만, Minikube는 로컬 VM이 Master와 Worker Node의 역할을 모두 수행하기 때문에 저렴하고 간편하게 클러스터를 테스트 해볼 수 있습니다.

이번엔 Minikube를 통해 간단한 쿠버네티스 클러스터를 구축하고,

간단한 컨테이너 배포를 진행하겠습니다.

먼저 쿠버네티스를 설치하기 위한 로컬 환경을 구성하겠습니다.

minikube 공식 홈페이지 설치 가이드

설치에 대한 자세한 내용은 위의 공식 홈페이지에서 확인할 수 있습니다.

공식 홈페이지에서 권장하는 사양은 다음과 같습니다.

- 2vCore CPU

- 2GB Memory

- 20GB Free Disk

- 컨테이너를 실행하기 위한 런타임 환경(Docker 등)

저는 AWS에 ubuntu 20.04 EC2를 생성하여 설치를 진행하였습니다.

# 클러스터 구축을 위한 minikube 설치
$ curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
$ sudo install minikube-linux-amd64 /usr/local/bin/minikube

# 구축한 클러스터를 제어하기 위한 kubectl 설치
$ curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
$ sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl

이제 설치를 완료한 뒤 Minikube 클러스터를 실행하겠습니다.

# minikube 클러스터 시작
$ minikube start

* minikube v1.25.2 on Ubuntu 20.04
* Unable to pick a default driver. Here is what was considered, in preference order:
* Alternatively you could install one of these drivers:
  - docker: Not installed: exec: "docker": executable file not found in $PATH
  - kvm2: Not installed: exec: "virsh": executable file not found in $PATH
  - podman: Not installed: exec: "podman": executable file not found in $PATH
  - vmware: Not installed: exec: "docker-machine-driver-vmware": executable file not fou                      nd in $PATH
  - virtualbox: Not installed: unable to find VBoxManage in $PATH

X Exiting due to DRV_NOT_DETECTED: No possible driver was detected. Try specifying --dri                      ver, or see https://minikube.sigs.k8s.io/docs/start/

아무것도 설치하지 않고 minikube를 실행하면 위와 같은 메시지들이 나타납니다.
이는 Pod를 구동시키기 위한 컨테이너 런타임 환경이 구성되지 않았다는 의미입니다.
Docker를 설치하고 다시 minikube를 실행해보겠습니다.

# Docker 런타임 설치
$ apt-get update
$ apt-get install docker.io

# minikube 실행
$ minikube start

* minikube v1.25.2 on Ubuntu 20.04
* Automatically selected the docker driver. Other choices: none, ssh
* The "docker" driver should not be used with root privileges.
* If you are running minikube within a VM, consider using --driver=none:
*   https://minikube.sigs.k8s.io/docs/reference/drivers/none/

X Exiting due to DRV_AS_ROOT: The "docker" driver should not be used with root privileges.

이번에도 minikube 실행에 실패했습니다.
메시지를 자세히 살펴보면 root 권한에 대한 주의 메시지입니다.
docker를 root 권한으로 실행할 시 보안에 관한 문제가 발생할 수 있다는 메시지입니다.

이를 해결하기 위해서는 minikube실행시 뒤에 --driver=none 옵션을 추가하거나,
새로 계정을 생성하여 minikube를 실행하면 됩니다.

하지만 계정을 추가할 경우 docker 및 minikube에 대한 권한 설정이 필요하기 때문에
이번에는 그냥 --driver=none 옵션을 추가하겠습니다.

# root 권한 경고 메시지 무시 옵션 부여
$ minikube start --driver=none

* minikube v1.25.2 on Ubuntu 20.04
* Using the none driver based on user configuration

X Exiting due to GUEST_MISSING_CONNTRACK: Sorry, Kubernetes 1.23.3 requires conntrack to be installed in root's path

이번에도 실행에 실패했습니다.
이번에는 conntrack이 설치되지 않았다는 메시지가 발생합니다.
conntrack을 설치해주겠습니다.

# conntrack 설치
$ apt-get install conntrack

# minikube 실행
$ minikube start --driver=none

* minikube v1.25.2 on Ubuntu 20.04
* Using the none driver based on user configuration

X The requested memory allocation of 1940MiB does not leave room for system overhead (total system memory: 1940MiB). You may face stability issues.
* Suggestion: Start minikube with less memory allocated: 'minikube start --memory=1940mb'

* Starting control plane node minikube in cluster minikube
* Running on localhost (CPUs=2, Memory=1940MB, Disk=19788MB) ...
* OS release is Ubuntu 20.04.3 LTS
* Preparing Kubernetes v1.23.3 on Docker 20.10.7 ...
  - kubelet.resolv-conf=/run/systemd/resolve/resolv.conf
  - kubelet.housekeeping-interval=5m
    > kubectl.sha256: 64 B / 64 B [--------------------------] 100.00% ? p/s 0s
    > kubelet.sha256: 64 B / 64 B [--------------------------] 100.00% ? p/s 0s
    > kubeadm.sha256: 64 B / 64 B [--------------------------] 100.00% ? p/s 0s
    > kubectl: 44.43 MiB / 44.43 MiB [-------------] 100.00% 41.37 MiB p/s 1.3s
    > kubeadm: 43.12 MiB / 43.12 MiB [-------------] 100.00% 42.72 MiB p/s 1.2s
    > kubelet: 118.75 MiB / 118.75 MiB [-----------] 100.00% 45.38 MiB p/s 2.8s
  - Generating certificates and keys ...
  - Booting up control plane ...
  - Configuring RBAC rules ...
* Configuring local host environment ...
*
! The 'none' driver is designed for experts who need to integrate with an existing VM
* Most users should use the newer 'docker' driver instead, which does not require root!
* For more information, see: https://minikube.sigs.k8s.io/docs/reference/drivers/none/
*
! kubectl and minikube configuration will be stored in /root
! To use kubectl or minikube commands as your own user, you may need to relocate them. For example, to overwrite your own settings, run:
*
  - sudo mv /root/.kube /root/.minikube $HOME
  - sudo chown -R $USER $HOME/.kube $HOME/.minikube
*
* This can also be done automatically by setting the env var CHANGE_MINIKUBE_NONE_USER=true
* Verifying Kubernetes components...
  - Using image gcr.io/k8s-minikube/storage-provisioner:v5
* Enabled addons: default-storageclass, storage-provisioner
* Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default

이제 minikube 클러스터가 구성되었습니다.
이제 kubectl을 이용해 minikube가 정상적으로 구성되었는지 확인해보겠습니다.

$ kubectl get pod --all-namespaces

NAMESPACE     NAME                                    READY   STATUS    RESTARTS   AGE
kube-system   coredns-64897985d-748ll                 1/1     Running   0          81s
kube-system   etcd-ip-10-0-2-146                      1/1     Running   0          96s
kube-system   kube-apiserver-ip-10-0-2-146            1/1     Running   0          92s
kube-system   kube-controller-manager-ip-10-0-2-146   1/1     Running   0          92s
kube-system   kube-proxy-m7rjw                        1/1     Running   0          81s
kube-system   kube-scheduler-ip-10-0-2-146            1/1     Running   0          95s
kube-system   storage-provisioner                     1/1     Running   0          91s

kubectl get 명령어를 통해 클러스터에서 동작중인 pod를 확인했습니다.
etcd, api-server, controller-manager, scheduler와 같은 컴포넌트들이 정상적으로 올라와있는것을 확인 할 수 있습니다.

참고

쿠버네티스 Github - https://github.com/kubernetes/minikube

공식 홈페이지 - https://minikube.sigs.k8s.io/docs/start/

'Kubernetes' 카테고리의 다른 글

Replica Set과 Deployment  (0) 2022.03.29
Kubernetes 기본 오브젝트  (0) 2022.03.29
Kubernetes 구조  (0) 2022.03.29
Kubernetes와 가상화 기술  (0) 2022.03.29
Comments