티스토리 뷰
지금 난 Backend 개발 리드 겸 AWS 인프라 관리 겸 DevOps 관리를 하고 있다.
DevOps+AWS를 전담해주던 팀장이 그만두면서 그 업무가 고스란히 나한테 넘어왔기 때문이다..
우리 서버는 EKS를 사용 중인데 인수인계 받은 그대로 운영은 할 수 있지만, 정확히 알고 사용한다고 하긴 어렵다.
그래도 담당자인데 제대로 알아야하지 싶어서 쿠버네티스를 로컬에서부터 차근차근 공부해보기 위해보려한다.
(AWS 인프라는 그래도 어느정도 알게된 이유도 있다)
그래서 추천 받은게 KIND, Minikube 였는데 조금 더 가벼워보이고 접근성이 좋아보이는 KIND를 선택했다.
KIND란?
KIND는 Docker 컨테이너 "노드"를 사용하여 로컬 Kubernetes 클러스터를 실행하기 위한 도구입니다.
KIND는 주로 Kubernetes 자체를 테스트하기 위해 설계되었지만 로컬 개발이나 CI에 사용될 수도 있습니다.
도커를 사용해서 경량화된 쿠버네티스 클러스터를 구축할 수 있고 kubectl 명령어도 지원하기 때문에
공부하면서 테스트하기엔 딱이라 생각했다.
일단 들어가기전에 쿠버네티스의 용어들은 기본적으로 알고 있다 가정한다.
생소한 용어들이라 조금 피곤하지만 필수적으로 알아야한다.
클러스터, 네임스페이스, 서비스, 노드, 파드, 디플로이먼트 등등 서로간의 상관관계부터 스케일링까지 엮여 있어 피곤하지만 반드시 알아야 다음 이야기들이 진행된다.
시작하기에 앞서, 이 영상을 보고 가는걸 추천한다.
WSL2에 KIND 설치하기
일단 내 환경은 Windows다 Docker를 사용하기 위해서 WSL2가 필요하다.
WSL에 접속하고 아래와 같이 실행한다.
$ [ $(uname -m) = x86_64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.21.0/kind-linux-amd64
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 97 100 97 0 0 185 0 --:--:-- --:--:-- --:--:-- 186
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 6245k 100 6245k 0 0 3695k 0 0:00:01 0:00:01 --:--:-- 3695k
$ chmod +x ./kind
$ sudo mv ./kind /usr/local/bin/kind
이러면 설치 끝이다.
간단한 설치가 일단 접근성을 낮춰줬다.
Cluster 생성 예제
kind 명령어를 통해 클러스터를 간단하게 생성할 수 있다.
$ kind create cluster
Creating cluster "kind" ...
✓ Ensuring node image (kindest/node:v1.29.1) 🖼
✓ Preparing nodes 📦
✓ Writing configuration 📜
✓ Starting control-plane 🕹️
✓ Installing CNI 🔌
✓ Installing StorageClass 💾
Set kubectl context to "kind-kind"
You can now use your cluster with:
kubectl cluster-info --context kind-kind
Thanks for using kind! 😊
$ kind create cluster --name kind-2
...
$ kubectl cluster-info --context kind-kind
Kubernetes control plane is running at https://127.0.0.1:42759
CoreDNS is running at https://127.0.0.1:42759/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
$ kind get clusters
kind
kind-2
2개의 클러스터를 생성했다.
이름을 별도로 지정하지 않으면 kind라는 이름으로 생성된다.
docker ps 명령어를 찍어보면, 도커 컨테이너가 2개 생성된 것을 볼 수 있다.
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
kindest/node <none> 464874016844 9 days ago 956MB
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
NAMES
f5698ca2e0a2 kindest/node:v1.29.1 "/usr/local/bin/entr…" About a minute ago Up About a minute 127.0.0.1:44115->6443/tcp kind-2-control-plane
e5a903f97253 kindest/node:v1.29.1 "/usr/local/bin/entr…" 12 minutes ago Up 12 minutes 127.0.0.1:42759->6443/tcp kind-control-plane
kind delete 명령어로 클러스터들을 손쉽게 지울 수 있다.
$ kind delete cluster
Deleting cluster "kind" ...
Deleted nodes: ["kind-control-plane"]
$ kind delete cluster --name kind-2
Deleting cluster "kind-2" ...
Deleted nodes: ["kind-2-control-plane"]
여기까지는 installation 페이지에서 소개한 튜토리얼이다.
그 다음은 nginx 서버를 띄워보는 작업을 해본다.
KIND로 nginx 서버 띄우기
https://kind.sigs.k8s.io/docs/user/using-wsl2/#accessing-a-kubernetes-service-running-in-wsl2
kind 클러스터와 30000 포트와 매핑되는 노드를 만드는 configuration 파일을 만든다.
# cluster-config.yml
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
extraPortMappings:
- containerPort: 30000
hostPort: 30000
protocol: TCP
이 config 파일로 클러스터와 노드를 생성한다.
$ kind create cluster --config=cluster-config.yml
Creating cluster "kind" ...
✓ Ensuring node image (kindest/node:v1.29.1) 🖼
✓ Preparing nodes 📦
✓ Writing configuration 📜
✓ Starting control-plane 🕹️
✓ Installing CNI 🔌
✓ Installing StorageClass 💾
Set kubectl context to "kind-kind"
You can now use your cluster with:
kubectl cluster-info --context kind-kind
Not sure what to do next? 😅 Check out https://kind.sigs.k8s.io/docs/user/quick-start/
그리고 80포트와 연결된 deployment를 만든다.
파드를 조회해보면 nginx 파드가 생성된 것을 확인할 수 있음
$ kubectl create deployment nginx --image=nginx --port=80
deployment.apps/nginx created
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-7c5ddbdf54-z8mdw 1/1 Running 0 150m
이렇게 생성된 파드는 클러스터 내의 다른 컴포넌트와 통신할 수 있지만, 외부에서 접근할 수 없다.
외부에서 접근하려면 서비스(Service)를 추가로 생성해야한다.
$ kubectl create service nodeport nginx --tcp=80:80 --node-port=30000
service/nginx created
$ kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 158m
nginx NodePort 10.96.167.79 <none> 80:30000/TCP 157m
서비스를 생성하고 처음에 열어둔 노드의 30000 포트와 nginx pod의 80번 포트를 매핑한다.
$ curl localhost:30000
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
curl 조회하면 잘 나온다.
브라우저에서 localhost로 30000번 포트로 접근해보면 pod가 잘 연결된걸 확인할 수 있다.
마치며
일단은 KIND 페이지에서 제공하는 가장 기본적인건 핥아본 것 같다.
중간 중간 모르는 개념들은 찾아가면서 했는데, 이 포스팅에선 별도로 정리하진 않았다.
다음은 스프링부트 프로젝트로 컨테이너를 생성하고, pod를 띄워볼 것이다.
- Total
- Today
- Yesterday
- serverless
- AOP
- 후쿠오카
- S3
- docker
- GIT
- Elastic cloud
- OpenAI
- 스프링부트
- MySQL
- ChatGPT
- 오블완
- object
- 티스토리챌린지
- terraform
- EKS
- springboot
- Log
- cache
- AWS EC2
- AWS
- JWT
- Spring
- 후기
- 람다
- lambda
- CloudFront
- java
- Kotlin
- elasticsearch
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |