라즈베리 파이로 쿠버네티스 클러스터에 MetalLB와 nginx-ingress를 설치해보자.

MetalLB?
MetalLB, bare metal load-balancer for Kubernetes

라즈베리 파이 클러스터 (어떤 관점에선 베어메탈)에 Load Balancer를 사용하기 위한 가장 심플한 방법 중 하나라고 생각된다.
설치
Helm 차트를 이용하여 클러스터에 MetalLB를 배포한다. Helm 레포를 추가하여 MetalLB를 설치할 준비.
helm repo add metallb https://metallb.github.io/metallb
helm repo update
그리고 Cluster가 속해있는 네트워크에 맞는 간단한 추가 세팅이 필요하다.
configInline:
address-pools:
- name: default
protocol: layer2
addresses:
- 192.168.24.136-192.168.24.255
간단하게 MetalLB를 위한 주소 영역대를 결정한다. CIDR로 해주는게 제일 좋아보이지만.. 이 values.yaml
을 작성하고 아래의 커맨드를 실행하여 Helm 차트를 설치한다.
helm install --namespace metallb metallb metallb/metallb -f values.yaml
nginx-ingress
Bare-metal considerations - NGINX Ingress Controller

helm repo add nginx-stable https://helm.nginx.com/stable
helm repo update
helm install --namespace ingress nginx-ingress nginx-stable/nginx-ingress -f values.yaml
values.yaml에는 사정에 맞게 잘 세팅하도록 한다. 모두 세팅하고 나면, 아래와 같은 상황을 맞이할 수 있을 것이다.

Cert manager 배포
HTTPS 통신을 위한 인증서를 생성해주고 만료 기간이 되면 자동으로 인증서를 갱신해주는 역할을 해준다. 아무 걱정 없이 Let's encrypt 인증서 발급을 통해 외부로부터 HTTPS 서비스를 할 수 있게된다.
cert-manager Documentation
cert-manager documentation homepage

kubectl apply --validate=false -f https://github.com/cert-manager/cert-manager/releases/download/v1.8.0/cert-manager.yaml
---
apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
name: letsencrypt-staging
spec:
acme:
email: ...
server: https://acme-staging-v02.api.letsencrypt.org/directory
privateKeySecretRef:
name: letsencrypt-staging
solvers:
- http01:
ingress:
class: nginx
---
apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
name: letsencrypt-prod
spec:
acme:
email: ...
server: https://acme-v02.api.letsencrypt.org/directory
privateKeySecretRef:
name: letsencrypt-prod
solvers:
- http01:
ingress:
class: nginx
cluster-issuer.yaml
: 이메일 주소는 잘 바꾸시길...kubectl apply -f cluster-issuer.yaml
kubectl get clusterissuer -o wide
어플리케이션 배포
Hello API 서버의 Deployment는 아래와 같다.
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-api
spec:
replicas: 2
selector:
matchLabels:
app: hello-api
template:
metadata:
labels:
app: hello-api
spec:
containers:
- name: hello-api
image: <✨>/<✨>:latest
Service는 아래와 같이 정의한다.
apiVersion: v1
kind: Service
metadata:
name: hello-api
spec:
selector:
app: hello-api
ports:
- name: http
protocol: TCP
port: 3000
targetPort: 3000
Ingress는 아래와 같이 정의한다.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: hello-api
annotations:
cert-manager.io/cluster-issuer: letsencrypt-prod
acme.cert-manager.io/http01-edit-in-place: "true"
spec:
tls:
- hosts:
- hello.example.com
secretName: hello-api-cert
rules:
- host: hello.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: hello-api
port:
number: 3000
ingressClassName: nginx
지금은 example.com 이라는 도메인을 연결해두었다는 것을 가정한다. hello.example.com으로 metallb 로드밸런서에 접근하면 해당 인그레스로 연결시켜줄 것이다.
kubectl -n hello apply -f deploy.yaml
kubectl -n hello apply -f service.yaml
kubectl -n hello apply -f ingress.yaml