`__, as shown in the following figure.
|image2|
Deploy **nginx:exporter** and **nginx-prometheus-exporter** in the same pod.
.. code-block::
kind: Deployment
apiVersion: apps/v1
metadata:
name: nginx-exporter
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: nginx-exporter
template:
metadata:
labels:
app: nginx-exporter
annotations:
metrics.alpha.kubernetes.io/custom-endpoints: '[{"api":"prometheus","path":"/metrics","port":"9113","names":""}]'
spec:
containers:
- name: container-0
image: 'nginx:exporter' # Replace it with the address of the image you uploaded to SWR.
resources:
limits:
cpu: 250m
memory: 512Mi
requests:
cpu: 250m
memory: 512Mi
- name: container-1
image: 'nginx/nginx-prometheus-exporter:0.9.0'
command:
- nginx-prometheus-exporter
args:
- '-nginx.scrape-uri=http://127.0.0.1:8080/stub_status'
imagePullSecrets:
- name: default-secret
.. note::
The nginx/nginx-prometheus-exporter:0.9.0 image needs to be pulled from the public network. Therefore, each node in the cluster must have a public IP address.
nginx-prometheus-exporter requires a startup command. **nginx-prometheus-exporter -nginx.scrape-uri=http://127.0.0.1:8080/stub_status** is used to obtain Nginx monitoring data.
In addition, you need to add an annotation **metrics.alpha.kubernetes.io/custom-endpoints: '[{"api":"prometheus","path":"/metrics","port":"9113","names":""}]'** to the pod.
Verification
------------
After an application is deployed, you can access Nginx to construct some access data and check whether the corresponding monitoring data can be obtained in AOM.
.. code-block::
$ kubectl get pod
NAME READY STATUS RESTARTS AGE
nginx-exporter-78859765db-6j8sw 2/2 Running 0 4m
$ kubectl exec -it nginx-exporter-78859765db-6j8sw -- /bin/sh
Defaulting container name to container-0.
Use 'kubectl describe pod/nginx-exporter-78859765db-6j8sw -n default' to see all of the containers in this pod.
/ # curl http://localhost
Welcome to nginx!
Welcome to nginx!
If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.
For online documentation and support please refer to
nginx.org.
Commercial support is available at
nginx.com.
Thank you for using nginx.
/ #
You can see that Nginx has been accessed once.
Log in to AOM. In the navigation pane, choose **Monitoring** > **Metric Monitoring**. You can view Nginx-related metrics, for example, **nginx_connections_active**.
.. |image1| image:: /_static/images/en-us_image_0000001517743384.png
.. |image2| image:: /_static/images/en-us_image_0000001568822693.png