
K3d 란?
k3d는 도커에서 k3s (Rancher Lab의 최소 Kubernetes 배포) 를 실행하는 경량 래퍼 이다.
k3d를 사용하면 예를 들어 Kubernetes의 로컬 개발을 위해 Docker에서 단일 및 다중 노드 k3s 클러스터 를 매우 쉽게 생성할 수 있다.
k3d 설치후 docker ps 명령어로 확인해보면 k3d 가 설치된것을 확인할 수 있다.
특이점
- k3d 는 default ingress-controller 가 traefik 으로 install 되는 것을 확인할 수 있다.
- K3d는 다음과 같은 호스트 이름을 제공합니다 >> host.k3d.internal
- 호스트에서 실행 중인 서비스에 액세스 K3d에서 실행하는 일부 워크로드는 Docker 호스트에서 이미 실행 중인 서비스에 액세스해야한다.
- kind , Local , vm 에서 띄운 k3s에서 실행했을 때는 database url 을 host.docker.internal 으로 했었는데 k3d 로 실행하니 database url 을 host.k3d.internal 으로 해야 docker-compose 로 띄운 mysql 과 k3d 에 띄운 demo-api app 이 연결이 됐다.
실행 환경
- Window 10
- WSL2
PS C:\Users> wsl -l -v
NAME STATE VERSION
* Ubuntu Running 2
docker-desktop-data Running 2
docker-desktop Running 2
따로 VM 을 생성하지 않고 , WSL (OS) 환경에서 k3d 를 설치함.
1. k3d install
wget -q -O - https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | bash
2. k3d Config
k3d 는 default ingress controller 가 traefik 으로 설치된다.
Nginx Ingress Controller 를 사용하기 위해 traefik 을 diable 해준다.
만약 traefik Ingress Controller 를 사용하고 싶다면 위 config.yml 에서 disable=traefik argument 를 지워주면된다.
3.k3d cluster 생성
k3d cluster create --config ./k3d-config.yml
4. Nginx Ingress Controller
4.1. Nginx Ingress Controller 설치
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/cloud/deploy.yaml
https://github.com/scaamanho/k3d-cluster/blob/master/Ingress-Controller.md
GitHub - scaamanho/k3d-cluster: Kubernetes Cluster with K3D with dockers
Kubernetes Cluster with K3D with dockers. Contribute to scaamanho/k3d-cluster development by creating an account on GitHub.
github.com
4.2. 설치 터미널
11:19:55 ubuntu@DESKTOP k3d → kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/cloud/deploy.yaml
namespace/ingress-nginx created
serviceaccount/ingress-nginx created
serviceaccount/ingress-nginx-admission created
role.rbac.authorization.k8s.io/ingress-nginx created
role.rbac.authorization.k8s.io/ingress-nginx-admission created
clusterrole.rbac.authorization.k8s.io/ingress-nginx created
clusterrole.rbac.authorization.k8s.io/ingress-nginx-admission created
rolebinding.rbac.authorization.k8s.io/ingress-nginx created
rolebinding.rbac.authorization.k8s.io/ingress-nginx-admission created
clusterrolebinding.rbac.authorization.k8s.io/ingress-nginx created
clusterrolebinding.rbac.authorization.k8s.io/ingress-nginx-admission created
configmap/ingress-nginx-controller created
service/ingress-nginx-controller created
service/ingress-nginx-controller-admission created
deployment.apps/ingress-nginx-controller created
job.batch/ingress-nginx-admission-create created
job.batch/ingress-nginx-admission-patch created
ingressclass.networking.k8s.io/nginx created
validatingwebhookconfiguration.admissionregistration.k8s.io/ingress-nginx-admission created
4.3. Ingress Controller 설치 확인
10:34:45 ubuntu@DESKTOP demo-api ±|main ✗|→ k get all -n ingress-nginx
NAME READY STATUS RESTARTS AGE
pod/ingress-nginx-admission-create-tllqg 0/1 Completed 0 14m
pod/ingress-nginx-admission-patch-j4skj 0/1 Completed 1 14m
pod/ingress-nginx-controller-6f7bd4bcfb-4bftt 1/1 Running 0 14m
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/ingress-nginx-controller-admission ClusterIP 10.43.169.171 <none> 443/TCP 14m
service/ingress-nginx-controller LoadBalancer 10.43.169.254 172.18.0.3,172.18.0.4,172.18.0.5 80:32425/TCP,443:30763/TCP 14m
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/ingress-nginx-controller 1/1 1 1 14m
NAME DESIRED CURRENT READY AGE
replicaset.apps/ingress-nginx-controller-6f7bd4bcfb 1 1 1 14m
NAME COMPLETIONS DURATION AGE
job.batch/ingress-nginx-admission-create 1/1 12s 14m
job.batch/ingress-nginx-admission-patch 1/1 13s 14m
4.4. Ingress 확인
10:23:29 ubuntu@DESKTOP demo-fe ±|main ✗|→ k get ingress -A
NAMESPACE NAME CLASS HOSTS ADDRESS PORTS AGE
fe demo-fe-ingress <none> demo.com 172.18.0.3,172.18.0.4,172.18.0.5 80 2m28s
4.5. hosts 설정
- C:\Windows\System32\drivers\etc\hosts 파일에 추가
# C:\Windows\System32\drivers\etc\hosts
127.0.0.1 demo.com
5. k3d cluster 삭제
# k3d cluster delete <cluster-name>
k3d cluster delete my-cluster
참고
https://k3d.io/v5.4.6/#install-current-latest-release
k3d
Overview What is k3d? k3d is a lightweight wrapper to run k3s (Rancher Lab’s minimal Kubernetes distribution) in docker. k3d makes it very easy to create single- and multi-node k3s clusters in docker, e.g. for local development on Kubernetes. Note: k3d i
k3d.io
https://k3d.io/v5.4.6/usage/exposing_services/
Exposing Services - k3d
Exposing Services 1. via Ingress (recommended) In this example, we will deploy a simple nginx webserver deployment and make it accessible via ingress. Therefore, we have to create the cluster in a way, that the internal port 80 (where the traefik ingress c
k3d.io
'Kubernetes' 카테고리의 다른 글
[kubectl] krew - Kubernetes Plugin Manager (0) | 2023.07.10 |
---|---|
vCluster (Multi-Tenancy in Kubernetes) (0) | 2023.07.10 |
[kubectl] kubectx + kubens 설정 및 자동 완성 (0) | 2023.07.09 |
nginx ingress controller tcp 설정 (0) | 2022.12.26 |
kind & nginx ingress - 로컬 PC 에 쿠버네티스 설치 (0) | 2022.12.26 |