diff --git a/charts/apisix-ingress-controller/README.md b/charts/apisix-ingress-controller/README.md index 3fe6505b..4eeedd75 100644 --- a/charts/apisix-ingress-controller/README.md +++ b/charts/apisix-ingress-controller/README.md @@ -154,6 +154,11 @@ The same for container level, you need to set: | gateway.nginx.workerRlimitNofile | string | `"20480"` | Nginx workerRlimitNoFile | | gateway.resources | object | `{}` | | | gateway.securityContext | object | `{}` | | +| gateway.serviceMonitor | object | `{"annotations":{},"enabled":false,"interval":"15s","labels":{},"metricRelabelings":{},"namespace":"monitoring","path":"/apisix/prometheus/metrics"}` | Create ServiceMonitor object for apisix gateway for Prometheus operator Requires Prometheus operator v0.38.0 or higher. | +| gateway.serviceMonitor.annotations | object | `{}` | @param serviceMonitor.annotations ServiceMonitor annotations | +| gateway.serviceMonitor.labels | object | `{}` | @param serviceMonitor.labels ServiceMonitor extra labels | +| gateway.serviceMonitor.metricRelabelings | object | `{}` | @param serviceMonitor.metricRelabelings MetricRelabelConfigs to apply to samples before ingestion. ref: https://prometheus.io/docs/prometheus/latest/configuration/configuration/#metric_relabel_configs | +| gateway.serviceMonitor.path | string | `"/apisix/prometheus/metrics"` | @param serviceMonitor.path ServiceMonitor scrape path | | gateway.tls.additionalContainerPorts | list | `[]` | Support multiple https ports, See [Configuration](https://github.com/apache/apisix/blob/0bc65ea9acd726f79f80ae0abd8f50b7eb172e3d/conf/config-default.yaml#L99) | | gateway.tls.certCAFilename | string | `""` | Filename be used in the gateway.tls.existingCASecret | | gateway.tls.containerPort | int | `9443` | | diff --git a/charts/apisix-ingress-controller/templates/apisix-configmap.yaml b/charts/apisix-ingress-controller/templates/apisix-configmap.yaml index cb41c4fe..9ec1c957 100644 --- a/charts/apisix-ingress-controller/templates/apisix-configmap.yaml +++ b/charts/apisix-ingress-controller/templates/apisix-configmap.yaml @@ -164,12 +164,12 @@ data: plugin_attr: prometheus: - enable_export_server: {{ .Values.serviceMonitor.enabled }} - {{- if .Values.serviceMonitor.enabled }} + enable_export_server: {{ .Values.gateway.serviceMonitor.enabled }} + {{- if .Values.gateway.serviceMonitor.enabled }} export_addr: ip: 0.0.0.0 port: 9091 - export_uri: /apisix/prometheus/metrics + export_uri: {{ .Values.gateway.serviceMonitor.path }} metric_prefix: apisix_ {{- end }} {{ end }} diff --git a/charts/apisix-ingress-controller/templates/deployment.yaml b/charts/apisix-ingress-controller/templates/deployment.yaml index 76d74858..767727f4 100644 --- a/charts/apisix-ingress-controller/templates/deployment.yaml +++ b/charts/apisix-ingress-controller/templates/deployment.yaml @@ -94,7 +94,7 @@ spec: image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" imagePullPolicy: {{ .Values.image.pullPolicy }} ports: - - name: http + - name: http-controller containerPort: {{ (.Values.config.httpListen | split ":")._1 }} protocol: TCP {{ if .Values.config.etcdserver.enabled }} @@ -146,7 +146,7 @@ spec: - name: https containerPort: {{ .Values.gateway.tls.containerPort }} protocol: TCP - {{- if .Values.serviceMonitor.enabled }} + {{- if .Values.gateway.serviceMonitor.enabled }} - containerPort: 9091 name: prometheus protocol: TCP diff --git a/charts/apisix-ingress-controller/templates/service-apisix.yaml b/charts/apisix-ingress-controller/templates/service-apisix.yaml index 4abf0f3a..8326b1a7 100644 --- a/charts/apisix-ingress-controller/templates/service-apisix.yaml +++ b/charts/apisix-ingress-controller/templates/service-apisix.yaml @@ -1,3 +1,4 @@ +{{- if .Values.config.etcdserver.enabled }} apiVersion: v1 kind: Service metadata: @@ -41,4 +42,5 @@ spec: {{- range $ip := .Values.gateway.externalIPs }} - {{ $ip }} {{- end }} - {{- end }} \ No newline at end of file + {{- end }} + {{- end }} diff --git a/charts/apisix-ingress-controller/templates/servicemonitor-apisix.yaml b/charts/apisix-ingress-controller/templates/servicemonitor-apisix.yaml new file mode 100644 index 00000000..e9ec40ec --- /dev/null +++ b/charts/apisix-ingress-controller/templates/servicemonitor-apisix.yaml @@ -0,0 +1,48 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +{{- if and .Values.config.etcdserver.enabled .Values.gateway.serviceMonitor.enabled }} +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + name: {{ template "apisix-ingress-controller.fullname" . }}-apisix-gateway + {{- if .Values.gateway.serviceMonitor.namespace }} + namespace: {{ .Values.gateway.serviceMonitor.namespace }} + {{- end }} + {{- if .Values.gateway.serviceMonitor.labels }} + labels: {{- toYaml .Values.gateway.serviceMonitor.labels | nindent 4 }} + {{- end }} + {{- if .Values.gateway.serviceMonitor.annotations }} + annotations: {{- toYaml .Values.gateway.serviceMonitor.annotations | nindent 4 }} + {{- end }} +spec: + endpoints: + - targetPort: prometheus + scheme: http + path: {{ .Values.gateway.serviceMonitor.path }} + {{- if .Values.gateway.serviceMonitor.interval }} + interval: {{ .Values.gateway.serviceMonitor.interval }} + {{- end }} + {{- with .Values.gateway.serviceMonitor.metricRelabelings }} + metricRelabelings: {{ toYaml . | nindent 6 }} + {{- end }} + namespaceSelector: + matchNames: + - {{ template "apisix-ingress-controller.namespace" . }} + selector: + matchLabels: + {{- include "apisix-ingress-controller.labels" . | nindent 6 }} +{{- end }} diff --git a/charts/apisix-ingress-controller/templates/servicemonitor.yaml b/charts/apisix-ingress-controller/templates/servicemonitor.yaml index 7f37908f..a371ab90 100644 --- a/charts/apisix-ingress-controller/templates/servicemonitor.yaml +++ b/charts/apisix-ingress-controller/templates/servicemonitor.yaml @@ -30,7 +30,7 @@ metadata: {{- end }} spec: endpoints: - - targetPort: http + - targetPort: http-controller scheme: http {{- if .Values.serviceMonitor.interval }} interval: {{ .Values.serviceMonitor.interval }} @@ -46,4 +46,3 @@ spec: matchLabels: {{- include "apisix-ingress-controller.labels" . | nindent 6 }} {{- end }} - diff --git a/charts/apisix-ingress-controller/values.yaml b/charts/apisix-ingress-controller/values.yaml index 928cc75e..70937cc0 100644 --- a/charts/apisix-ingress-controller/values.yaml +++ b/charts/apisix-ingress-controller/values.yaml @@ -255,6 +255,21 @@ gateway: # readOnlyRootFilesystem: true # runAsNonRoot: true # runAsUser: 636 + # -- Create ServiceMonitor object for apisix gateway for Prometheus operator + # Requires Prometheus operator v0.38.0 or higher. + serviceMonitor: + enabled: false + namespace: "monitoring" + # -- @param serviceMonitor.path ServiceMonitor scrape path + path: "/apisix/prometheus/metrics" + interval: 15s + # -- @param serviceMonitor.labels ServiceMonitor extra labels + labels: {} + # -- @param serviceMonitor.annotations ServiceMonitor annotations + annotations: {} + # -- @param serviceMonitor.metricRelabelings MetricRelabelConfigs to apply to samples before ingestion. + # ref: https://prometheus.io/docs/prometheus/latest/configuration/configuration/#metric_relabel_configs + metricRelabelings: {} tls: enabled: false servicePort: 443