NGINX NIC / NSM のセットアップ
1. 事前セットアップ、HELMのインストール
必要なファイルを取得します。
cd ~/
git clone https://github.com/BeF5/f5j-nsm-lab.git
cd ~/f5j-nsm-lab/prep
NSMテスト用のNamespaceを作成します
# cd ~/f5j-nsm-lab/prep
kubectl apply -f nsm-demo-ns.yaml
1namespace/prod created
2namespace/staging created
3namespace/legacy created
こちらのラボでは、HELMを使って環境をセットアップします。 HELMをinstallします。
curl https://baltocdn.com/helm/signing.asc | gpg --dearmor | sudo tee /usr/share/keyrings/helm.gpg > /dev/null
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/helm.gpg] https://baltocdn.com/helm/stable/debian/ all main" | sudo tee /etc/apt/sources.list.d/helm-stable-debian.list
sudo apt-get update
sudo apt-get install helm
正しくHELMがインストールされたことを確認します
helm version
1version.BuildInfo{Version:"v3.10.2", GitCommit:"50f003e5ee8704ec937a756c646870227d7c8b58", GitTreeState:"clean", GoVersion:"go1.18.8"}
必要なファイルを取得します
cd ~/
git clone https://github.com/BeF5/f5j-nginx-observability-lab.git --branch v1.1.0
2. NSMのセットアップ
必要なファイルを取得します
cd ~/
git clone https://github.com/nginxinc/nginx-service-mesh --branch v1.6.0
cd ~/nginx-service-mesh
取得した内容が意図したVersionであることを確認します
## cd ~/nginx-service-mesh
git show -s
1commit bb6d6f4e8443deda81932057d0f97d9ab4f6e23a (HEAD, tag: v1.6.0, origin/main, origin/HEAD)
2Merge: e0297f0 066bc5d
3Author: Saylor Berman <s.berman@f5.com>
4Date: Tue Nov 1 12:06:58 2022 -0600
5
6 Merge pull request #82 from nginxinc/release-1.6.0
7
8 Helm release - 1.6.0
cat ~/f5j-nginx-observability-lab/prep/helm/nsm-values.yaml
1# NGINX Service Mesh image registry settings.
2registry:
3 # Hostname:port (if needed) for registry and path to images.
4 # Affects: nginx-mesh-api, nginx-mesh-cert-reloader, nginx-mesh-init, nginx-mesh-metrics, nginx-mesh-sidecar
5 server: "docker-registry.nginx.com/nsm"
6
7 # Tag used for pulling images from registry
8 # Affects: nginx-mesh-api, nginx-mesh-cert-reloader, nginx-mesh-init, nginx-mesh-metrics, nginx-mesh-sidecar
9 imageTag: "1.6.0"
10
11# Environment to deploy the mesh into.
12# Valid values: kubernetes, openshift
13environment: "kubernetes"
14
15# Enable UDP traffic proxying (beta). Linux kernel 4.18 or greater is required.
16enableUDP: false
17
18# NGINX log format.
19# Valid values: default, json
20nginxLogFormat: "json"
21
22# NGINX load balancing method.
23# Valid values: [least_conn, least_time, least_time last_byte, least_time last_byte inflight,
24# random, random two, random two least_conn, random two least_time, random two least_time=last_byte, round_robin]
25nginxLBMethod: "round_robin"
26
27# The address of a Prometheus server deployed in your Kubernetes cluster.
28# Address should be in the format <service-name>.<namespace>:<service-port>.
29prometheusAddress: "prometheus-server.monitor:80"
30
31# Globally disable automatic sidecar injection upon resource creation.
32# Use either "enabledNamespaces" or a namespace label to enable automatic injection.
33disableAutoInjection: true
34
35# Enable automatic sidecar injection for specific namespaces.
36# Must be used with "disableAutoInjection".
37enabledNamespaces: [ staging , prod ]
38
39# NGINX Service Mesh tracing settings. Deprecated in favor of telemetry.
40# Cannot be set when telemetry is set.
41# If deploying with tracing, uncomment the following object and set the telemetry object to {}.
42tracing:
43 # The address of a tracing server deployed in your Kubernetes cluster.
44 # Address should be in the format <service-name>.<namespace>:<service_port>.
45 address: "jaeger-agent.monitor:6831"
46
47 # The tracing backend that you want to use.
48 # Valid values: datadog, jaeger, zipkin
49 backend: "jaeger"
50
51 # The sample rate to use for tracing. Float between 0 and 1.
52 sampleRate: 1
53
54mtls:
55 # mTLS mode for pod-to-pod communication.
56 # Valid values: off, permissive, strict
57 mode: "strict"
58
59 # Use persistent storage; "on" assumes that a StorageClass exists.
60 # Valid values: on, off
61 persistentStorage: "off"
29行目でPrometheus、45行目・49行目でJaegerの設定を指定します
52行目ですが、この例ではTraceの情報の結果を容易に確認するため、SampleRate 1 と指定します
33,37行目 Injectの対象となるNamespaceを指定
NSMをデプロイします
cd ~/nginx-service-mesh/helm-chart
cp ~/f5j-nginx-observability-lab/prep/helm/nsm-values.yaml .
helm upgrade --install nsm -f nsm-values.yaml . \
--namespace nginx-mesh \
--create-namespace
-f オプションで先程のファイルをしていすることにより、Helmのデプロイのパラメータとして付与します
–namespace オプションでHelmで展開するNamespaceを指定します
–create-namespace により対象のNamespaceが存在しない場合、Helmコマンド実行時に作成します
1Release "nsm" does not exist. Installing it now.
2NAME: nsm
3LAST DEPLOYED: Thu Jun 30 06:46:04 2022
4NAMESPACE: nginx-mesh
5STATUS: deployed
6REVISION: 1
7TEST SUITE: None
8NOTES:
9NGINX Service Mesh has been installed. Ensure all NGINX Service Mesh Pods are in the Ready state before deploying your apps.
デプロイの結果を確認します
helm list -n nginx-mesh
1NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
2nsm nginx-mesh 1 2022-06-30 06:46:04.963589733 +0000 UTC deployed nginx-service-mesh-0.4.1 1.4.1
Podが正しく作成され、以下のようになることを確認してください
kubectl get pod -n nginx-mesh
1NAME READY STATUS RESTARTS AGE
2nats-server-cf97cf4f4-9ggnq 2/2 Running 0 92s
3nginx-mesh-api-5c99b4df77-8kmw9 1/1 Running 0 92s
4nginx-mesh-metrics-5d856c4dfc-fhw7d 1/1 Running 0 92s
5spire-agent-x4smj 1/1 Running 0 93s
6spire-server-66c596b85c-gfkz2 2/2 Running 0 92s
3. NICのセットアップ
必要なファイルを取得します
cd ~/
git clone https://github.com/nginxinc/kubernetes-ingress.git --branch v2.4.1
cd ~/kubernetes-ingress/
取得した内容が意図したVersionであることを確認します
## cd ~/kubernetes-ingress/
git show -s
1commit 413c0bb5761b1796d2e8490f4bb34881e144ab8d (HEAD, tag: v2.4.1)
2Author: Jakub Jarosz <99677300+jjngx@users.noreply.github.com>
3Date: Thu Oct 20 00:07:37 2022 +0100
4
5 Release 2.4.1 (#3184)
6
7 Co-authored-by: Luca Comellini <luca.com@gmail.com>
NAP DoS の Arbitator をデプロイします
cd ~/kubernetes-ingress/deployments/helm-chart-dos-arbitrator
helm upgrade --install appdos-arbitrator . \
--namespace nginx-ingress \
--create-namespace
1Release "appdos-arbitrator" does not exist. Installing it now.
2NAME: appdos-arbitrator
3LAST DEPLOYED: Tue Jun 28 12:32:37 2022
4NAMESPACE: nginx-ingress
5STATUS: deployed
6REVISION: 1
7TEST SUITE: None
デプロイの結果を確認します
helm list -n nginx-ingress
1NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
2appdos-arbitrator nginx-ingress 1 2022-06-28 12:32:37.157945967 +0000 UTC deployed nginx-appprotect-dos-arbitrator-0.1.0 1.1.0
Podが正しく作成され、以下のようになることを確認してください
kubectl get pod -n nginx-ingress | grep dos
1appdos-arbitrator-nginx-appprotect-dos-arbitrator-844bdf64qjw9l 1/1 Running 0 23s
cd ~/kubernetes-ingress/
cp ~/nginx-repo* .
ls nginx-repo.*
make debian-image-nap-dos-plus PREFIX=registry.example.com/root/nic/nginxplus-ingress-nap-dos TARGET=container TAG=2.4.1
docker login registry.example.com
Username: root << 左の文字列を入力
Password: password << 左の文字列を入力
docker push registry.example.com/root/nic/nginxplus-ingress-nap-dos:2.4.1
NICをデプロイします。
nic1
と、nic2
をデプロイします。nic1
で指定するパラメータの内容を確認します。cat ~/f5j-nginx-observability-lab/prep/helm/nic1-addvalue.yaml
1nginxServiceMesh:
2 enable: true
3 enableEgress: true
4
5controller:
6 nginxplus: true
7 image:
8 repository: registry.example.com/root/nic/nginxplus-ingress-nap-dos
9 tag: "2.4.1"
10
11 ## Support for App Protect
12 appprotect:
13 enable: true
14
15 ## Support for App Protect Dos
16 appprotectdos:
17 enable: true
18
19 ingressClass: nginx
20
21 ## Enable the custom resources.
22 enableCustomResources: true
23
24 ## Enable preview policies. This parameter is deprecated. To enable OIDC Policies please use controller.enableOIDC instead.
25 enablePreviewPolicies: false
26
27 ## Enable OIDC policies.
28 enableOIDC: true
29
30 globalConfiguration:
31 ## Creates the GlobalConfiguration custom resource. Requires controller.enableCustomResources.
32 create: true
33
34 ## The spec of the GlobalConfiguration for defining the global configuration parameters of the Ingress Controller.
35 spec: {}
36 # listeners:
37 # - name: dns-udp
38 # port: 5353
39 # protocol: UDP
40 # - name: dns-tcp
41 # port: 5353
42 # protocol: TCP
43
44 ## Enable custom NGINX configuration snippets in Ingress, VirtualServer, VirtualServerRoute and TransportServer resources.
45 enableSnippets: true
46
47 service:
48 ## Creates a service to expose the Ingress Controller pods.
49 create: true
50 ## The type of service to create for the Ingress Controller.
51 type: NodePort
52
53 ## Enable collection of latency metrics for upstreams. Requires prometheus.create.
54 enableLatencyMetrics: true
55
56prometheus:
57 ## Expose NGINX or NGINX Plus metrics in the Prometheus format.
58 create: true
59
60 ## Configures the port to scrape the metrics.
61 port: 9113
62
63 ## Specifies the namespace/name of a Kubernetes TLS Secret which will be used to protect the Prometheus endpoint.
64 secret: ""
65
66 ## Configures the HTTP scheme used.
67 scheme: http
1-3行目でNSMとの接続を有効にしています
6-9行目でNGINX Plusを有効にし、先程作成したImageを指定しています
12-13行目でNAP WAFを、16-17行目でNAP DoSを有効にしています
19行目でIngress Classとして
nginx
を指定しています56-67行目でPrometheusに必要なパラメータを指定しています
続けて nic2
で指定するパラメータの内容を確認します。
nic1 との差分を中心に確認します
cat ~/f5j-nginx-observability-lab/prep/helm/nic2-addvalue.yaml
1nginxServiceMesh:
2 enable: false
3 enableEgress: false
4
5controller:
6 nginxplus: true
7 image:
8 repository: registry.example.com/root/nic/nginxplus-ingress-nap-dos
9 tag: "2.4.1"
10
11 ## Support for App Protect
12 appprotect:
13 enable: true
14
15 ## Support for App Protect Dos
16 appprotectdos:
17 enable: true
18
19 ingressClass: nginx2
20
21 ## Enable the custom resources.
22 enableCustomResources: true
23
24 ## Enable preview policies. This parameter is deprecated. To enable OIDC Policies please use controller.enableOIDC instead.
25 enablePreviewPolicies: false
26
27 ## Enable OIDC policies.
28 enableOIDC: true
29
30 globalConfiguration:
31 ## Creates the GlobalConfiguration custom resource. Requires controller.enableCustomResources.
32 create: true
33
34 ## The spec of the GlobalConfiguration for defining the global configuration parameters of the Ingress Controller.
35 spec: {}
36 # listeners:
37 # - name: dns-udp
38 # port: 5353
39 # protocol: UDP
40 # - name: dns-tcp
41 # port: 5353
42 # protocol: TCP
43
44 ## Enable custom NGINX configuration snippets in Ingress, VirtualServer, VirtualServerRoute and TransportServer resources.
45 enableSnippets: true
46
47 service:
48 ## Creates a service to expose the Ingress Controller pods.
49 create: true
50 ## The type of service to create for the Ingress Controller.
51 type: NodePort
52
53 ## Enable collection of latency metrics for upstreams. Requires prometheus.create.
54 enableLatencyMetrics: true
55
56prometheus:
57 ## Expose NGINX or NGINX Plus metrics in the Prometheus format.
58 create: true
59
60 ## Configures the port to scrape the metrics.
61 port: 9113
62
63 ## Specifies the namespace/name of a Kubernetes TLS Secret which will be used to protect the Prometheus endpoint.
64 secret: ""
65
66 ## Configures the HTTP scheme used.
67 scheme: http
NSMとの接続を利用しないため、1-3行目の設定を無効(false)にしています
19行目でIngress Classとして nginx2 を指定しています。 (nic1はnginx)
NICをそれぞれデプロイします
cd ~/kubernetes-ingress/deployments/helm-chart
cp ~/f5j-nginx-observability-lab/prep/helm/nic1-addvalue.yaml .
cp ~/f5j-nginx-observability-lab/prep/helm/nic2-addvalue.yaml .
helm upgrade --install nic1 -f nic1-addvalue.yaml . -n nginx-ingress
helm upgrade --install nic2 -f nic2-addvalue.yaml . -n nginx-ingress
デプロイした結果を確認します
helm list -n nginx-ingress
1NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
2appdos-arbitrator nginx-ingress 1 2024-12-26 11:28:09.549936455 +0900 JST deployed nginx-appprotect-dos-arbitrator-0.1.0 1.1.0
3nic1 nginx-ingress 1 2024-12-26 11:43:47.022460423 +0900 JST deployed nginx-ingress-0.15.1 2.4.1
4nic2 nginx-ingress 1 2024-12-26 11:43:56.851796991 +0900 JST deployed nginx-ingress-0.15.1 2.4.1
Podが正しく作成されていることを確認します
kubectl get pod -n nginx-ingress
1NAME READY STATUS RESTARTS AGE
2appdos-arbitrator-nginx-appprotect-dos-arbitrator-844bdf64qjw9l 1/1 Running 1 (25h ago) 32h
3nic1-nginx-ingress-69d574d9fb-lnv9f 1/1 Running 0 81s
4nic2-nginx-ingress-857cf9d78d-vzh9w 1/1 Running 0 12s
NICへ通信を転送するための設定を行います。
NodePortの情報を確認します。
kubectl get svc -n nginx-ingress | grep nginx-ingress
1nic1-nginx-ingress NodePort 10.104.228.200 <none> 80:31430/TCP,443:32486/TCP 154m
2nic2-nginx-ingress NodePort 10.106.138.240 <none> 80:30730/TCP,443:31903/TCP 152m
それぞれに表示されているポート番号を確認してください。これらの情報を元に、NGINXの設定を作成します。
vi ~/f5j-nsm-lab/prep/nginx.conf
以下の内容を参考に、先程確認したNodePortで割り当てられたポート番号宛に通信を転送するように、NGINXを設定します。
1# TCP/UDP load balancing
2#
3stream {
4 ## TCP/UDP LB for NIC/NSM ingressclass
5 server {
6 listen 80;
7 proxy_pass localhost:31430; # nic1 http port of NodePort
8 }
9 server {
10 listen 443;
11 proxy_pass localhost:32486; # nic 1 https port of NodePort
12 }
13
14
15 ## TCP/UDP LB for NIC2 nginx2 ingressclass
16 server {
17 listen 8080;
18 proxy_pass localhost:30730; # nic2 http port of NodePort
19 }
20 server {
21 listen 8443;
22 proxy_pass localhost:31903; # nic2 https port of NodePort
23 }
24
25}
設定をコピーし、反映します
sudo cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf-
sudo cp ~/f5j-nsm-lab/prep/nginx.conf /etc/nginx/nginx.conf
sudo nginx -s reload