Skip to content
This repository has been archived by the owner on Feb 22, 2022. It is now read-only.

[stable/kong] Options to install Prometheus plugin with ServiceMonitor #14346

Merged
merged 10 commits into from
Aug 19, 2019
2 changes: 1 addition & 1 deletion stable/kong/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ maintainers:
name: kong
sources:
- https://github.com/Kong/kong
version: 0.15.0
version: 0.16.0
appVersion: 1.2
32 changes: 18 additions & 14 deletions stable/kong/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ and their default values.
| proxy.ingress.path | Ingress path. | `/` |
| proxy.ingress.annotations | Ingress annotations. See documentation for your ingress controller for details | `{}` |
| env | Additional [Kong configurations](https://getkong.org/docs/latest/configuration/) | |
| serviceMonitor.enabled | Create ServiceMonitor for Prometheus Operator | false |
| serviceMonitor.interval | Scrapping interval | 10s |
| serviceMonitor.namespace | Where to create ServiceMonitor | |
| runMigrations | Run Kong migrations job | `true` |
| readinessProbe | Kong readiness probe | |
| livenessProbe | Kong liveness probe | |
Expand All @@ -115,12 +118,12 @@ the value provided by you as opposed to constructing a listen variable
from fields like `proxy.http.containerPort` and `proxy.http.enabled`. This allows
you to be more prescriptive when defining listen directives.

**Note:** Overriding `env.proxy_listen` and `env.admin_listen` will potentially cause
`admin.containerPort`, `proxy.http.containerPort` and `proxy.tls.containerPort` to become out of sync,
**Note:** Overriding `env.proxy_listen` and `env.admin_listen` will potentially cause
`admin.containerPort`, `proxy.http.containerPort` and `proxy.tls.containerPort` to become out of sync,
and therefore must be updated accordingly.

I.E. updatating to `env.proxy_listen: 0.0.0.0:4444, 0.0.0.0:4443 ssl` will need
`proxy.http.containerPort: 4444` and `proxy.tls.containerPort: 4443` to be set in order
I.E. updatating to `env.proxy_listen: 0.0.0.0:4444, 0.0.0.0:4443 ssl` will need
`proxy.http.containerPort: 4444` and `proxy.tls.containerPort: 4443` to be set in order
for the service definition to work properly.

### Kong-specific parameters
Expand Down Expand Up @@ -168,7 +171,7 @@ kong:
key: kong
name: postgres
```


For complete list of Kong configurations please check https://getkong.org/docs/latest/configuration/.

Expand Down Expand Up @@ -374,12 +377,13 @@ The custom resources are:

You can can learn about kong ingress custom resource definitions [here](https://github.com/Kong/kubernetes-ingress-controller/blob/master/docs/custom-resources.md).

| Parameter | Description | Default |
| --------------- | ----------------------------------------- | ---------------------------------------------------------------------------- |
| enabled | Deploy the ingress controller, rbac and crd | false |
| replicaCount | Number of desired ingress controllers | 1 |
| image.repository | Docker image with the ingress controller | kong-docker-kubernetes-ingress-controller.bintray.io/kong-ingress-controller |
| image.tag | Version of the ingress controller | 0.2.0 |
| readinessProbe | Kong ingress controllers readiness probe | |
| livenessProbe | Kong ingress controllers liveness probe | |
| ingressClass | The ingress-class value for controller | nginx
| Parameter | Description | Default |
| --------------- | ------------------------------------------ | ---------------------------------------------------------------------------- |
| enabled | Deploy the ingress controller, rbac and crd | false |
| replicaCount | Number of desired ingress controllers | 1 |
| image.repository | Docker image with the ingress controller | kong-docker-kubernetes-ingress-controller.bintray.io/kong-ingress-controller |
| image.tag | Version of the ingress controller | 0.4.0 |
| readinessProbe | Kong ingress controllers readiness probe | |
| livenessProbe | Kong ingress controllers liveness probe | |
| ingressClass | The ingress-class value for controller | kong |
| installCRDs | Install Kong ingress controllers custom resource definitions | true |
2 changes: 1 addition & 1 deletion stable/kong/templates/config-custom-server-blocks.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-kong-default-custom-server-blocks
name: {{ template "kong.fullname" . }}-default-custom-server-blocks
labels:
app: {{ template "kong.name" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
Expand Down
2 changes: 1 addition & 1 deletion stable/kong/templates/crd-kongconsumer.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if and .Values.ingressController.enabled .Values.ingressController.installCRDs -}}
{{- if and .Release.IsInstall .Values.ingressController.enabled .Values.ingressController.installCRDs -}}
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
Expand Down
5 changes: 4 additions & 1 deletion stable/kong/templates/crd-kongcredential.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if and .Values.ingressController.enabled .Values.ingressController.installCRDs -}}
{{- if and .Release.IsInstall .Values.ingressController.enabled .Values.ingressController.installCRDs -}}
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
Expand All @@ -8,6 +8,9 @@ metadata:
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
annotations:
"helm.sh/hook": crd-install
"helm.sh/hook-delete-policy": "before-hook-creation"
spec:
group: configuration.konghq.com
version: v1
Expand Down
5 changes: 4 additions & 1 deletion stable/kong/templates/crd-kongingress.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if and .Values.ingressController.enabled .Values.ingressController.installCRDs -}}
{{- if and .Release.IsInstall .Values.ingressController.enabled .Values.ingressController.installCRDs -}}
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
Expand All @@ -8,6 +8,9 @@ metadata:
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
annotations:
"helm.sh/hook": crd-install
"helm.sh/hook-delete-policy": "before-hook-creation"
spec:
group: configuration.konghq.com
version: v1
Expand Down
5 changes: 4 additions & 1 deletion stable/kong/templates/crd-kongplugins.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if and .Values.ingressController.enabled .Values.ingressController.installCRDs -}}
{{- if and .Release.IsInstall .Values.ingressController.enabled .Values.ingressController.installCRDs -}}
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
Expand All @@ -8,6 +8,9 @@ metadata:
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
annotations:
"helm.sh/hook": crd-install
"helm.sh/hook-delete-policy": "before-hook-creation"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these changes to CRDs can be removed since the Prometheus plugin is not being automatically created.

Another problem that I see here:
If multiple Kong Ingress Controllers are being installed one after the other, then this will incorrectly delete the CRD first, and then re-install the CRD. This will lead to deletion of all the custom resources that were present in the cluster before the installation.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@decayofmind Could you address this comment?
Thanks!

spec:
group: configuration.konghq.com
version: v1
Expand Down
4 changes: 2 additions & 2 deletions stable/kong/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ spec:
volumes:
- name: custom-nginx-template-volume
configMap:
name: {{ .Release.Name }}-kong-default-custom-server-blocks
name: {{ template "kong.fullname" . }}-default-custom-server-blocks
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this changed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may not be the matter of this PR, but in general, all objects in a chart should be addressing {{ template "<chartname.fullname>" }} in its names.

It allows a user to override objects naming for the whole installation, by taking into account .Values.nameOverride and .Values.fullNameOverride (not yet in Kong chart) variables passed to the chart.

{{- if (and (not .Values.ingressController.enabled) (eq .Values.env.database "off")) }}
- name: kong-custom-dbless-config-volume
configMap:
Expand All @@ -273,4 +273,4 @@ spec:
{{- else }}
name: {{ template "kong.dblessConfig.fullname" . }}
{{- end }}
{{- end }}
{{- end }}
29 changes: 29 additions & 0 deletions stable/kong/templates/servicemonitor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{{- if and ( .Capabilities.APIVersions.Has "monitoring.coreos.com/v1" ) .Values.serviceMonitor.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: {{ template "kong.fullname" . }}
{{- if .Values.serviceMonitor.namespace }}
namespace: {{ .Values.serviceMonitor.namespace }}
{{- end }}
labels:
app: {{ template "kong.name" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
heritage: {{ .Release.Service }}
release: {{ .Release.Name }}
spec:
endpoints:
- targetPort: metrics
scheme: http
{{- if .Values.serviceMonitor.interval }}
interval: {{ .Values.serviceMonitor.interval }}
{{- end }}
jobLabel: {{ .Release.Name }}
namespaceSelector:
matchNames:
- {{ .Release.Namespace }}
selector:
matchLabels:
app: {{ template "kong.name" . }}
release: {{ .Release.Name }}
{{- end }}
7 changes: 7 additions & 0 deletions stable/kong/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,13 @@ ingressController:

ingressClass: kong

serviceMonitor:
# Specifies whether ServiceMonitor for Prometheus operator should be created
enabled: false
# interval: 10s
# Specifies namespace, where ServiceMonitor should be installed
# namespace: monitoring

# We pass the dbless (declarative) config over here.
dblessConfig:
# Either Kong's configuration is managed from an existing ConfigMap (with Key: kong.yml)
Expand Down