Kubernetes Ingress コンポーネントのデプロイ¶
概要¶
Nginx Ingress は、Kubernetes Ingress の一種です。Kubernetes クラスターの Ingress リソースを監視(watch)し、Ingress ルールを Nginx の設定に変換して、Nginx によるレイヤー7 のトラフィック転送を実現します。
前提条件¶
- Kubernetes クラスターがデプロイ済みであること(未デプロイの場合は Kubernetes のデプロイ を参照)
- (オプション)Helm ツールがデプロイ済みであること(未デプロイの場合は Helm のインストール を参照)
基本情報と互換性¶
| 名称 | 説明 |
|---|---|
| Ingress-nginx バージョン | 1.3.0 |
| 対応クラスターバージョン | 1.18+ |
| Ingress-nginx ポート番号 | 32280 |
| オフラインインストール対応 | はい |
| 対応アーキテクチャ | amd64/arm64 |
デプロイ手順¶
1、インストール¶
Kubernetes Ingress コンポーネントのデプロイについては、https://github.com/kubernetes/ingress-nginx を参照してください。
- Kubernetes > 1.18
helm install ingress-nginx ingress-nginx \
--repo https://pubrepo.guance.com/chartrepo/dataflux-chart \
-n ingress-nginx --create-namespace
- Kubernetes = 1.18
- Kubernetes > 1.18
ingress-nginx.yaml をダウンロードします。
以下のコマンドを実行してインストールします。
- Kubernetes = 1.18
ingress-nginx4.1.4.yaml をダウンロードします。
以下のコマンドを実行してインストールします。
2、デプロイの検証¶
2.1 Pod の状態を確認する¶
kubectl get pods -n ingress-nginx
NAME READY STATUS RESTARTS AGE
ingress-nginx-controller-7bf6c446bf-b7bq7 1/1 Running 1 26d
2.2 ポートを確認する¶
ingress-nginx の NodePort ポート番号を取得します。
注意
Helm と Yaml によるデプロイでは、NodePort のポート番号が異なる場合があります。図のように、ingress-nginx の NodePort は 32280、32483 です。
2.3 テストサービスを作成する¶
# テスト用のデプロイメントを作成
kubectl create deployment ingress-test --image=nginx --port=80
# テスト用の Service を作成
kubectl expose deployment ingress-test --port=80 --target-port=80
# テスト用の Ingress を作成
kubectl create ingress ingress-test --rule='foo.com/=ingress-test:80'
2.4 テスト¶
注意
192.168.100.101 は Kubernetes ノードの 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>
2.5 テストサービスを削除する¶
kubectl delete deployment ingress-test
kubectl delete svc ingress-test
kubectl delete ingress ingress-test