콘텐츠로 이동

프록시 배포

개요

로컬에 배포된 Kubernetes 클러스터에서는 LoadBalancer 서비스를 사용할 수 없으므로, Nginx 또는 Haproxy를 프록시로 사용할 수 있습니다.

전제 조건

  • Kubernetes 클러스터가 배포되어 있어야 합니다. 배포되지 않은 경우 Kubernetes 배포를 참고하세요.
  • Ingress-nginx 서비스가 배포되어 있어야 합니다. 배포되지 않은 경우 Ingress-nginx를 참고하세요.

기본 정보 및 호환성

이름 설명
구성 서브도메인 dataflux.cn
클러스터 노드 IP 192.168.100.101,192.168.100.102,192.168.100.103
Ingress-nginx 포트 번호 32280
오프라인 설치 지원 여부 아니요
지원 아키텍처 amd64/arm64
배포 머신 IP 192.168.100.104

설치 단계

1. 포트 조회

Ingress-nginx NodePort 포트 번호를 확인합니다.

kubectl get svc -n ingress-nginx
ingress-nginx-svc.png

2. 설치 및 구성

  • 설치

별도 머신에 배포

## 설치
yum install -y nginx
## 시작
nginx 
  • 구성
주의

구성 파일의 IP, 포트 번호 및 도메인을 반드시 수정하세요. 이 구성의 도메인은 dataflux.cn입니다.

다음 구성을 수정하여 /etc/nginx/conf.d 디렉토리에 dataflux.conf 이름으로 저장합니다.

dataflux.conf(클릭하여 보기)
upstream httpbakend {
server 192.168.100.101:32280;
server 192.168.100.102:32280;
server 192.168.100.103:32280;
}

server {
  listen 80;
  server_name *.dataflux.cn;
  location / {
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass http://httpbakend;
   }
}
  • 구성 적용
    nginx -s reload
    
  • 설치

192.168.100.104 머신에 배포

## 설치
yum install -y haproxy

  • 구성
주의

구성 파일의 IP, 포트 번호 및 도메인을 반드시 수정하세요. 이 구성의 도메인은 dataflux.cn입니다.

다음 구성을 수정하여 /etc/haproxy/ 디렉토리에 haproxy.cfg 이름으로 저장합니다.

haproxy.cfg(클릭하여 보기)
#---------------------------------------------------------------------
# Example configuration for a possible web application.  See the
# full configuration options online.
#
#   http://haproxy.1wt.eu/download/1.4/doc/configuration.txt
#
#---------------------------------------------------------------------

#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global
    # to have these messages end up in /var/log/haproxy.log you will
    # need to:
    #
    # 1) configure syslog to accept network log events.  This is done
    #    by adding the '-r' option to the SYSLOGD_OPTIONS in
    #    /etc/sysconfig/syslog
    #
    # 2) configure local2 events to go to the /var/log/haproxy.log
    #   file. A line like the following can be added to
    #   /etc/sysconfig/syslog
    #
    #    local2.*                       /var/log/haproxy.log
    #
    log         127.0.0.1 local2

    chroot      /var/lib/haproxy
    pidfile     /var/run/haproxy.pid
    maxconn     4000
    user        haproxy
    group       haproxy
    daemon

    # turn on stats unix socket
    stats socket /var/lib/haproxy/stats

#---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults
    mode                    http
    log                     global
    option                  httplog
    option                  dontlognull
    option http-server-close
    option forwardfor       except 127.0.0.0/8
    option                  redispatch
    retries                 3
    timeout http-request    10s
    timeout queue           1m
    timeout connect         10s
    timeout client          1m
    timeout server          1m
    timeout http-keep-alive 10s
    timeout check           10s
    maxconn                 3000

# 443 https 포트 구성 (구성하지 않아도 됨, 구성 시 주석 해제)
#frontend https_frontend
#        bind *:443 ssl crt /etc/ssl/certs/dataflux.cn.pem # ssl 인증서
#        mode http
#        option httpclose
#        option forwardfor
#        reqadd X-Forwarded-Proto:\ https
#        #default_backend web_server
#        # ingress를 거치지 않음
#        acl kodo           hdr(Host)  -i df-kodo.dataflux.cn
#
#        acl launcher       hdr(Host)  -i launcher.dataflux.cn
#        acl dataflux       hdr(Host)  -i dataflux.dataflux.cn
#        acl func           hdr(Host)  -i df-func.dataflux.cn
#        acl api            hdr(Host)  -i df-api.dataflux.cn
#        acl management     hdr(Host)  -i df-management.dataflux.cn
#        acl management-api hdr(Host)  -i df-management-api.dataflux.cn
#        acl static         hdr(Host)  -i df-static-res.dataflux.cn
#
#        use_backend vip_1_servers if dataflux
#        use_backend vip_1_servers if func
#        use_backend vip_1_servers if launcher
#        use_backend vip_1_servers if static
#        use_backend vip_1_servers if api
#        use_backend vip_1_servers if management
#        use_backend vip_1_servers if management-api
#
#       # ingress를 거치지 않음
#        use_backend vip_2_servers if kodo

# 동적-정적 분리
frontend http_web
        mode http
        bind *:80
#        redirect scheme https if !{ ssl_fc}
        option httpclose
        option forwardfor
        ###### 도메인을 수정하세요. dataflux.cn를 사용자 도메인으로 변경
        acl kodo           hdr(Host)  -i df-kodo.dataflux.cn
        acl test           hdr(Host)  -i test.dataflux.cn
        acl launcher       hdr(Host)  -i launcher.dataflux.cn
        acl dataflux       hdr(Host)  -i dataflux.dataflux.cn
        acl func           hdr(Host)  -i df-func.dataflux.cn
        acl api            hdr(Host)  -i df-api.dataflux.cn
        acl management     hdr(Host)  -i df-management.dataflux.cn
        acl management-api hdr(Host)  -i df-management-api.dataflux.cn
        acl static         hdr(Host)  -i df-static-res.dataflux.cn
        acl docs            hdr(Host)  -i df-docs.dataflux.cn

        acl dataway         hdr(Host)  -i df-dataway.dataflux.cn
        use_backend vip_1_servers if dataflux
        use_backend vip_1_servers if func
        use_backend vip_1_servers if launcher
        use_backend vip_1_servers if static
        use_backend vip_1_servers if api
        use_backend vip_1_servers if management
        use_backend vip_1_servers if management-api
        use_backend vip_1_servers if kodo
        use_backend vip_1_servers if docs
        use_backend vip_1_servers if test
# ingress 포트, IP는 k8s 클러스터의 IP입니다. IP를 변경하세요.
backend vip_1_servers
        balance roundrobin
        server ingress_1 192.168.100.101:32280 check inter 1500 rise 3 fall 3
        server ingress_2 192.168.100.102:32280 check inter 1500 rise 3 fall 3
        server ingress_3 192.168.100.103:32280 check inter 1500 rise 3 fall 3
  • 시작
    systemctl start haproxy
    

3. 테스트

3.1 테스트 서비스 생성

# 테스트 deployment 생성
kubectl create deployment ingress-test --image=nginx --port=80
# 테스트 svc 생성
kubectl expose deployment ingress-test --port=80 --target-port=80
# 테스트 ingress 생성
kubectl create ingress ingress-test --rule='test.dataflux.cn/=ingress-test:80'

3.2 테스트

주의

192.168.100.104는 프록시 서버 IP입니다.

 curl -H 'Host:test.dataflux.cn' 192.168.100.104

성공 결과:

<!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>

3.3 테스트 서비스 정리

kubectl delete deployment ingress-test
kubectl delete svc ingress-test
kubectl delete ingress ingress-test

제거

rpm -e --nodeps nginx 
rpm -e --nodeps haproxy 

문서 평가

이 페이지가 도움이 되었나요?