사이드 프로젝트 백엔드 쪽을 맡으면서 단순히 API만 개발할게 아니라 Cloud Native 앱으로 개발하고 싶은 욕심이 생겼다.
그 시작으로 현재 사용하고 있는 local 서버를 클라우드 환경과 유사하게 구축하고자 kubernetes에 서버를 올리고자 한다.
(아직 사이드 프로젝트에서 수익이 나오는 상황이 아니라, 클라우드 사용에 비용에 부담이 있다 ㅎㅎ..)
local 환경에서 kubernetes를 운영하는 방법에는 여러가지가 있는데,
가장 유명한 minikube와 microk8s, k3s가 있다.
모두 단일 클러스터로 활용 방법은 유사하지만, minikube는 일단 microk8s보다 내장되어있는 기능이 많아서 헤비하다고 느껴졌다.
이후에 필요하다면 설치하면 될 것같고, k3s는 중국산이라 아직은 믿고 싶지 않아서 microk8s로 선택했다.
공통적인 내용이지만 명령어는 클라우드에서 사용하는 kubernetes와 동일하여 혼란은 없다.
microk8s은 ubuntu에서 snap으로 간단히 설치가 가능하다.
OS : ubuntu 18.04 LTS
1. Installation
92phnatom:~$ sudo snap install microk8s --classic
* 정상 설치 여부 확인
92phnatom:~$ sudo microk8s.kubectl get nodes
92phnatom:~$ sudo microk8s.kubectl get services
2. Dashboard
92phnatom:~$ sudo microk8s.enable dns dashboard
92phnatom:~$ sudo microk8s.kubectl get all --all-namespaces
* Dashboard에 접속하기 위한 Token 발급
92phnatom:~$ token=$(microk8s kubectl -n kube-system get secret | grep default-token | cut -d " " -f1)
92phnatom:~$ sudo microk8s kubectl -n kube-system describe secret $token
발급받은 토큰 정보를 입력하면 아래와 같이 dashboard에 접속할 수 있다.
이후에는 대시보드를 통해서만 모니터링할 것이기 때문에,,
(이상하게도 Chrome에서는 dashboard에 접속이 안된다. 그래서 firefox로 접속했다)
https://10.152.183.111
3. Sample nginx deployment
# nginx ingress controller가 작동중인지 확인
92phantom:~$ sudo microk8s.kubectl get pods -n kube-system
# Create a deployment
92phantom:~$ sudo microk8s.kubectl create deployment web --image=gcr.io/google-samples/hello-app:1.0
# Expose the deployment name = web
92phantom:~$ sudo microk8s.kubectl expose deployment web --type=NodePort --port=8080
# web이라는 서비스가 expose 되어 잘 작동하는 지 확인
92phantom:~$ sudo microk8s.kubectl get services
local ip 10.152.183.137의 8080포트에서 작동하고 있고,
그 상위 ubuntu 18.04 내부 ip에서는 32760포트에서 작동하고 있다.
이대로 라우터에서 포트포워딩하면 external-ip는 생성되지 않지만, 외부에서도 접근될 꺼 같다.
# local ip 10.152.183.137의 8080포트에서 작동하고 있고,
92phantom:~$ curl 10.152.183.137:8080
# 그 상위 ubuntu 18.04 내부 ip에서는 32760포트에서 작동하고 있다.
92phantom:~$ curl 192.168.x.x:32760
'Side Project' 카테고리의 다른 글
[Elasticsearch] 2-1. 검색과 쿼리 - Query DSL (Full text query) (0) | 2020.11.24 |
---|---|
[Elasticsearch] 1. Build Environment(Elasticsearch, Kibana) (0) | 2020.11.24 |
[GCP] MySQL 환경 구축 (1) | 2020.02.13 |
[GCP] 서버 환경 구축 (0) | 2020.02.13 |