# On-premise에 로드밸런서를 설치한다.
절차는 아래와 같다.
1. ingress-nginx-controller 설치
2. metallb 설치 및 구성
3. 테스트 → nginx 배포 및 서비스 확인
1. ingress-nginx-controller 설치 (이건 설치 안해도 서비스 실행하는데에는 이상 없음.)
- 설치를 하면 일단 ExternalIP는 <Pending>으로 나온다.
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.1.3/deploy/static/provider/cloud/deploy.yaml
- 참고 사이트
4.1.1 NGINX Ingress Controller 설치하기
4.1.1 NGINX Ingress Controller 설치하기 OKE에서 Kubernetes에서 사용가능한 여러가지 오픈 소스 ingress controller를 사용할 수 있습니다. 본 문서에서는 그중에서 가
thekoguryo.github.io
2. metallb 설치 및 구성 (최근 업데이트 됨), 위의 nginx 잉그레스 설치 안하고 metallb만 설치해도 됨.
- metallb namespace 생성
kubectl create ns metallb-system
- metallb 설치 아래내용 참고
# see what changes would be made, returns nonzero returncode if different
kubectl get configmap kube-proxy -n kube-system -o yaml | \
sed -e "s/strictARP: false/strictARP: true/" | \
kubectl diff -f - -n kube-system
# actually apply the changes, returns nonzero returncode on errors only
kubectl get configmap kube-proxy -n kube-system -o yaml | \
sed -e "s/strictARP: false/strictARP: true/" | \
kubectl apply -f - -n kube-system
kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.13.9/config/manifests/metallb-native.yaml
https://metallb.universe.tf/installation/
MetalLB, bare metal load-balancer for Kubernetes
Installation Before starting with installation, make sure you meet all the requirements. In particular, you should pay attention to network addon compatibility. If you’re trying to run MetalLB on a cloud platform, you should also look at the cloud compat
metallb.universe.tf
- secret을 생성한다.
kubectl create secret generic -n metallb-system memberlist --from-literal=secretkey="$(openssl rand -base64 128)"
- 라우팅 처리를 위한 IP 주소 풀 생성, 파일명은 임의로 지정한다. file.yaml 등, ip 대역대 확인은 minikube의 경우 minikube ip로 확인가능
apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
name: first-pool
namespace: metallb-system
spec:
addresses:
- 192.168.1.240-192.168.1.250
- 참고 사이트
k3s + MetalLB: metallb-controller Failed to allocate IP for "default/nginx": no available IPs
I created a k3s cluster and disabled the service loadbalancer & traefik. I installed metallb via a manifest file. Also, I created a ConfigMap for Metallb below named "config" with an
stackoverflow.com
3. 테스트 nginx 서비스 생성 및 배포
- namespace 생성
kubectl create ns nginx
- deployment.yaml 파일 생성
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
namespace: nginx
labels:
app: nginx
spec:
replicas: 8
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
- service.yaml 파일 생성
apiVersion: v1
kind: Service
metadata:
name: nginx-service
namespace: nginx
annotations:
alb.ingress.kubernetes.io/healthcheck-path: "/healthy"
spec:
selector:
app: nginx
type: NodePort
ports:
- port: 8088
protocol: TCP
targetPort: 80
- ingress.yaml 파일 생성
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: nginx-ingress
namespace: nginx
annotations:
#kubernetes.io/ingress.class: alb
#alb.ingress.kubernetes.io/scheme: internet-facing
#alb.ingress.kubernetes.io/target-type: instance
nginx.ingress.kubernetes.io/rewrite-target: /
nginx.ingress.kubernetes.io/ssl-redirect: "false"
spec:
rules:
- http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: "nginx-service"
port:
number: 8088
- 서비스 배포하기
seungkim@DESKTOP:~$ kubectl get svc -A
NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
default kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 4d22h
kube-system kube-dns ClusterIP 10.96.0.10 <none> 53/UDP,53/TCP,9153/TCP 4d22h
metallb-system webhook-service ClusterIP 10.99.230.74 <none> 443/TCP 62m
nginx nginx-service LoadBalancer 10.105.92.144 192.168.xx.x 8088:32579/TCP 49m
seungkim@DESKTOP:~$ minikube service nginx-service -n nginx
|-----------|---------------|-------------|---------------------------|
| NAMESPACE | NAME | TARGET PORT | URL |
|-----------|---------------|-------------|---------------------------|
| nginx | nginx-service | 8088 | http://192.168.xx.x:32579 |
|-----------|---------------|-------------|---------------------------|
🏃 Starting tunnel for service nginx-service.
|-----------|---------------|-------------|------------------------|
| NAMESPACE | NAME | TARGET PORT | URL |
|-----------|---------------|-------------|------------------------|
| nginx | nginx-service | | http://127.0.0.1:32771 |
|-----------|---------------|-------------|------------------------|
🎉 Opening service nginx/nginx-service in default browser...
👉 http://127.0.0.1:32771
❗ Because you are using a Docker driver on linux, the terminal needs to be open to run it.
4. 서비스 확인 및 리소스 확인
- 위에서 조회된 url로 접속을 하면 아래와 같은 nginx 화면을 볼 수 있다.
http://localhost:32771/
- 웹 서비스 확인