Local 환경에서 K8s를 사용하기 위해서 다양한 방법을 사용 할 수 있다.
그중 본문에서는 Kind 설치에 대해 설명한다.
Kind 란?
Kind (Kubernetes in Docker)는 가용성이 높은 Kubernetes 클러스터를 설치하는 CNCF 인증 프로젝트이다.
이름에서 알 수 있듯이 kind는 노드라는 Docker 컨테이너에서 k8s 클러스터를 가동한다.
따라서 minikube 및 microk8s와 같은 VM 기반 Kubernetes에 비해 Kubernetes 설정이 더 빠르다고한다.
실행 환경
본문은 Local 환경에서 별도 VM 생성 없이 WSL 환경에서 테스트했습니다. (Window 10)
PS C:\Users > wsl -l -v
NAME STATE VERSION
Ubuntu Running 2
docker-desktop-data Running 2
docker-desktop Running 2
Ubuntu 버전 확인
Ubuntu 20.04.4 LTS
ubuntu@DESKTOP-BHD5HLL ~ → lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.4 LTS
Release: 20.04
Codename: focal
목차
1. Kind Install
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.16.0/kind-linux-amd64
chmod +x ./kind
sudo mv ./kind /usr/local/bin/kind
2. Kind Config
2.1. ingress 를 사용할 경우 config
# ingress-cluster-config.yml
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
kubeadmConfigPatches:
- |
kind: InitConfiguration
nodeRegistration:
kubeletExtraArgs:
node-labels: "ingress-ready=true"
extraPortMappings:
- containerPort: 80
hostPort: 80
protocol: TCP
- containerPort: 443
hostPort: 443
protocol: TCP
2.2. NodePort 를 사용할 경우 config
# cluster-config.yml
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
extraPortMappings:
- containerPort: 30000
hostPort: 30000
protocol: TCP
- role: worker
3. Kind Cluster Create
kind create cluster --config ./ingress-cluster-config.yml
4. Ingress
4.1. Nginx Ingress Controller 설치
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/deploy.yaml
4.2. 설치 터미널
11:14:18 ubuntu@DESKTOP kind → kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/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. Nginx Ingress Controller 설치 확인
11:15:43 ubuntu@DESKTOP kind → k get all -n ingress-nginx
NAME READY STATUS RESTARTS AGE
pod/ingress-nginx-admission-create-rvq9q 0/1 Completed 0 72s
pod/ingress-nginx-admission-patch-pbx8d 0/1 Completed 1 72s
pod/ingress-nginx-controller-6bccc5966-w4l29 1/1 Running 0 72s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/ingress-nginx-controller NodePort 10.96.77.135 <none> 80:32233/TCP,443:31633/TCP 72s
service/ingress-nginx-controller-admission ClusterIP 10.96.129.136 <none> 443/TCP 72s
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/ingress-nginx-controller 1/1 1 1 72s
NAME DESIRED CURRENT READY AGE
replicaset.apps/ingress-nginx-controller-6bccc5966 1 1 1 72s
NAME COMPLETIONS DURATION AGE
job.batch/ingress-nginx-admission-create 1/1 14s 72s
job.batch/ingress-nginx-admission-patch 1/1 15s 72s
4.4. Nginx Ingress Example
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: demo-frontend-ingress
namespace: frontend
annotations:
kubernetes.io/ingress.class: nginx
spec:
rules:
- host: "demo.com"
http:
paths:
- pathType: Prefix
path: "/"
backend:
service:
name: demo-frontend-svc
port:
number: 8080
4.5. hosts 설정
- C:\Windows\System32\drivers\etc\hosts 파일에 추가 (Window 일 경우)
# C:\Windows\System32\drivers\etc\hosts
127.0.0.1 demo.com
4.6. ingress 확인
10:11:48 ubuntu@DESKTOP k8s ±|main ✗|→ k get ingress -A
NAMESPACE NAME CLASS HOSTS ADDRESS PORTS AGE
frontend demo-frontend-ingress <none> demo.com localhost 80 3d20h
참고
- kind 공식홈페이지 https://kind.sigs.k8s.io/docs/user/ingress/
kind – Ingress
Ingress This guide covers setting up ingress on a kind cluster. Setting Up An Ingress Controller 🔗︎ We can leverage KIND's extraPortMapping config option when creating a cluster to forward ports from the host to an ingress controller running on a node
kind.sigs.k8s.io
https://kind.sigs.k8s.io/docs/user/using-wsl2/
kind – Using WSL2
Kind can run using Windows Subsystem for Linux 2 (WSL2) on Windows 10 May 2020 Update (build 19041). All the tools needed to build or run kind work in WSL2, but some extra steps are needed to switch to WSL2. This page covers these steps in brief but also l
kind.sigs.k8s.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 |
k3d & nginx igress - 로컬 PC 에 쿠버네티스 설치 (0) | 2022.12.26 |