プロキシデプロイ¶
概要¶
ローカル環境にデプロイされた 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 ポート番号を取得します。
2. インストールと設定¶
- インストール
別のマシンにデプロイします。
- 設定
注意
設定内の 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;
}
}
- 設定の反映
- インストール
192.168.100.104 マシンにデプロイします。
- 設定
注意
設定内の 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 ポート(Kubernetes クラスターの 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
- 起動
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 です。
成功時の応答:
<!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