今年早些时候,我们推出了 NGINX 管理套件作为 NGINX 软件解决方案的新控制平面,使您能够从单一窗口配置、扩展、保护和监控 NGINX 数据平面上的用户应用和 REST API。
NGINX 管理套件采用模块化设计:其核心是实例管理器模块,它为整个 NGINX 开源和 NGINX Plus 实例提供跟踪、配置和可见性。 在撰写本文时, API Connectivity Manager是另一个可用模块,用于管理和协调作为 API 网关运行的 NGINX Plus。
NGINX 管理套件可以在裸机、Linux虚拟机或容器中运行。 在 Kubernetes 上部署它的推荐方法是使用我们提供的Helm 图表,但出于特定目的,您可能需要构建自己的 Docker 镜像并通过不一定依赖于 Helm 的自定义 CI/CD 管道管理其生命周期。
[编辑-本文于 2023 年 2 月更新,以完全自动化构建 Docker 映像的过程。]
我们提供了一个GitHub 存储库,其中包含为 NGINX 管理套件创建 Docker 映像所需的资源,并支持以下版本的实例管理器和 API 连接管理器:
要构建 Docker 映像,您需要:
要运行 Docker 映像,您需要:
kubectl
按照这些说明构建 Docker 映像。
笔记: 我们已尽一切努力在发布时准确地呈现 NGINX 管理套件 UI,但 UI 可能会发生变化。 使用这些说明作为参考,并根据需要使其适应当前 UI。
克隆 GitHub 存储库:
$ git clone https://github.com/nginxinc/NGINX-DemosCloning into 'NGINX-Demos'...
remote: Enumerating objects: 215, done.
remote: Counting objects: 100% (215/215), done.
remote: Compressing objects: 100% (137/137), done.
remote: Total 215 (delta 108), reused 171 (delta 64), pack-reused 0
Receiving objects: 100% (215/215), 2.02 MiB | 1.04 MiB/s, done.
Resolving deltas: 100% (108/108), done.
切换到构建目录:
$ cd NGINX-Demos/nginx-nms-docker/
运行docker
ps
来验证 Docker 是否正在运行,然后运行buildNIM.sh脚本来构建 Docker 镜像。 ‑i
选项设置自动构建模式, ‑C
和‑K
是必需选项,分别命名 NGINX 管理套件证书和密钥, ‑t
选项指定将映像推送到的私有注册表的位置和名称。
$ ./scripts/buildNIM.sh -i -C nginx-repo.crt -K nginx-repo.key -t registry.ff.lan:31005/nginx-nms:2.5.1
==> Building NGINX Management Suite docker image
Sending build context to Docker daemon 92.19MB
Step 1/18 : FROM ubuntu:22.04
---> a8780b506fa4
Step 2/18 : ARG NIM_DEBFILE
---> Running in 0f2354280c34
Removing intermediate container 0f2354280c34
[...]
---> 0588a050c852
Step 18/18 : CMD /deployment/startNIM.sh
---> Running in d0cc5466a43d
Removing intermediate container d0cc5466a43d
---> 25117ec0410a
Successfully built 25117ec0410a
Successfully tagged registry.ff.lan:31005/nginx-nms:2.5.1
The push refers to repository [registry.ff.lan:31005/nginx-nms]
9c4918474e3a: Pushed
42543d044dbb: Pushed
1621b2ec0a5e: Pushed
c6a464fc6a79: Pushed
75fa1d3c61bb: Pushed
3501fcf5dbd8: Pushed
d4a221057e67: Pushed
9ad05eafed57: Pushed
f4a670ac65b6: Pushed
2.5.1: digest: sha256:9a70cfdb63b71dc31ef39e4f20a1420d8202c85784cb037b45dc0e884dad74c9 size: 2425
按照这些说明准备部署清单并在 Kubernetes 上启动 NGINX 管理套件。
对上一节第 4 步下载的 NGINX 管理套件许可证进行 Base64 编码,然后将输出复制到剪贴板:
$ base64 -w0 nginx-mgmt-suite.licTulNRS1WZXJz...
使用您最喜欢的编辑器,打开manifests/1.nginx-nim.yaml并进行以下更改:
在spec.template.spec.containers
部分中,将默认镜像名称( your.registry.tld/nginx-nim2:tag
)替换为您在上一节第 3 步中使用‑t
选项指定的 Docker 镜像名称(在我们的例子中为 registry.ff.lan:31005/nginx-nms:2.5.1 ):
spec: ...
template:
...
spec:
containers:
- name: nginx-nim2
image: your.registry.tld/nginx-nim2:tag
在spec.template.spec.containers.env
部分中,通过在每个指示名称
的值
字段中进行以下替换来配置身份验证凭据:
NIM_USERNAME
– (可选)用管理员帐户名替换默认管理员
。NIM_PASSWORD
-(必需)用强密码替换默认的nimadmin
。许可证
– (必填)替换默认 <BASE64编码许可证文件>
使用您在上述步骤 1 中生成的 base64 编码许可证。spec: ...
template:
...
spec:
containers:
...
env:
...
- name: NIM_USERNAME
value: admin
- name: NIM_PASSWORD
value: nimadmin
- name: NIM_LICENSE
value: "<BASE64_ENCODED_LICENSE_FILE>"
或者,编辑manifests/3.vs.yaml并自定义用于访问 NGINX 管理套件的主机名。
运行nimDockerStart.sh以在您的 Kubernetes 集群中启动 NGINX 管理套件。 如跟踪所示,它作为nginx-nim2 pod 运行。 该脚本还初始化ClickHouse作为后端数据库和Grafana用于分析可视化的 pod。 有关更多信息,请参阅 GitHub repo 中的README 。
$ ./scripts/nimDockerStart.sh start namespace/nginx-nim2 created
~/NGINX-NIM2-Docker/manifests/certs ~/NGINX-NIM2-Docker
Generating a RSA private key
.....................................+++++
.....................................+++++
writing new private key to 'nim2.f5.ff.lan.key'
-----
secret/nim2.f5.ff.lan created
configmap/clickhouse-conf created
configmap/clickhouse-users created
persistentvolumeclaim/pvc-clickhouse created
deployment.apps/clickhouse created
service/clickhouse created
deployment.apps/nginx-nim2 created
service/nginx-nim2 created
service/nginx-nim2-grpc created
persistentvolumeclaim/pvc-grafana-data created
persistentvolumeclaim/pvc-grafana-log created
deployment.apps/grafana created
service/grafana created
virtualserver.k8s.nginx.org/nim2 created
virtualserver.k8s.nginx.org/grafana created
~/NGINX-NIM2-Docker
验证三个 Pod 现在正在运行:
$ kubectl get pods -n nginx-nim2 NAME READY STATUS RESTARTS AGE
clickhouse-759b65db8c-74pn5 1/1 Running 0 63s
grafana-95fbbf5c-jczgk 1/1 Running 0 63s
nginx-nim2-5f54664754-lrhmn 1/1 Running 0 63s
要访问 NGINX 管理套件,请在浏览器中导航至https://nim2.f5.ff.lan (或您在上一节步骤 4中设置的备用主机名)。 使用您在上一节第 2 步中设置的凭据登录。
要停止并删除 NGINX 管理套件的 Docker 实例,请运行以下命令:
$ ./scripts/nimDockerStart.sh stop namespace "nginx-nim2" deleted
要试用本文讨论的 NGINX 解决方案,请立即开始 30 天免费试用,或联系我们讨论您的用例:
“这篇博文可能引用了不再可用和/或不再支持的产品。 有关 F5 NGINX 产品和解决方案的最新信息,请探索我们的NGINX 产品系列。 NGINX 现在是 F5 的一部分。 所有之前的 NGINX.com 链接都将重定向至 F5.com 上的类似 NGINX 内容。”