From a825875d2064d0504927ce573a5e709ff95b64ff Mon Sep 17 00:00:00 2001 From: baba230896 Date: Thu, 10 Mar 2022 07:59:12 +0000 Subject: [PATCH 1/5] [PLAT-520] Added kube-state-metrics support Summary - Users can provide the custom endpoint for kube-state-metrics. - Users can install the kube-state-metrics and the platform in the same namespace with a single flag modification. Testing I have done the following testing - - Custom kube-state-metrics endpoint. - kube-state-metrics installation. - Platform chart will use the custom endpoint if the user provides both installation flag and custom endpoint. I have provided a higher priority to the custom endpoint than the installation. - Default platform chart installation works as intended. --- stable/yugaware/templates/_helpers.tpl | 13 ++ stable/yugaware/templates/configs.yaml | 2 +- .../kube-state-metrics-clusterrole.yaml | 179 ++++++++++++++++++ ...kube-state-metrics-clusterrolebinding.yaml | 18 ++ .../kube-state-metrics-deployment.yaml | 66 +++++++ .../kube-state-metrics-service-account.yaml | 14 ++ .../templates/kube-state-metrics-service.yaml | 23 +++ stable/yugaware/values.yaml | 33 ++++ 8 files changed, 347 insertions(+), 1 deletion(-) create mode 100644 stable/yugaware/templates/kube-state-metrics-clusterrole.yaml create mode 100644 stable/yugaware/templates/kube-state-metrics-clusterrolebinding.yaml create mode 100644 stable/yugaware/templates/kube-state-metrics-deployment.yaml create mode 100644 stable/yugaware/templates/kube-state-metrics-service-account.yaml create mode 100644 stable/yugaware/templates/kube-state-metrics-service.yaml diff --git a/stable/yugaware/templates/_helpers.tpl b/stable/yugaware/templates/_helpers.tpl index 386404776f..c25b111f99 100644 --- a/stable/yugaware/templates/_helpers.tpl +++ b/stable/yugaware/templates/_helpers.tpl @@ -112,3 +112,16 @@ Make list of allowed CORS origins {{- end -}} ] {{- end -}} + +{{/* +kube-state-metrics +*/}} +{{- define "kubeStateMetric.endpoint" -}} +{{- if .Values.kubeStateMetric.customEndpoint -}} +{{- .Values.kubeStateMetric.customEndpoint -}} +{{- else if .Values.kubeStateMetric.install -}} +{{- printf "%s-ksm.%s.svc.%s:8080" .Release.Name .Release.Namespace .Values.domainName -}} +{{- else -}} +{{- printf "kube-state-metrics.kube-system.svc.%s:8080" .Values.domainName -}} +{{- end -}} +{{- end -}} diff --git a/stable/yugaware/templates/configs.yaml b/stable/yugaware/templates/configs.yaml index 2397b82c39..944c8586a4 100644 --- a/stable/yugaware/templates/configs.yaml +++ b/stable/yugaware/templates/configs.yaml @@ -332,7 +332,7 @@ data: - job_name: 'kube-state-metrics' static_configs: - - targets: ['kube-state-metrics.kube-system.svc.{{.Values.domainName}}:8080'] + - targets: ['{{ template "kubeStateMetric.endpoint" . }}'] metric_relabel_configs: # Save the name of the metric so we can group_by since we cannot by __name__ directly... - source_labels: ["__name__"] diff --git a/stable/yugaware/templates/kube-state-metrics-clusterrole.yaml b/stable/yugaware/templates/kube-state-metrics-clusterrole.yaml new file mode 100644 index 0000000000..6514befbf4 --- /dev/null +++ b/stable/yugaware/templates/kube-state-metrics-clusterrole.yaml @@ -0,0 +1,179 @@ +{{- if and .Values.kubeStateMetric.install (not .Values.kubeStateMetric.customEndpoint) -}} +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + labels: + app: {{ .Release.Name }}-yugaware-ksm + chart: {{ template "yugaware.chart" . }} + release: {{ .Release.Name }} + name: {{ .Release.Name }}-ksm +rules: +{{ if has "certificatesigningrequests" $.Values.kubeStateMetric.collectors }} +- apiGroups: ["certificates.k8s.io"] + resources: + - certificatesigningrequests + verbs: ["list", "watch"] +{{ end -}} +{{ if has "configmaps" $.Values.kubeStateMetric.collectors }} +- apiGroups: [""] + resources: + - configmaps + verbs: ["list", "watch"] +{{ end -}} +{{ if has "cronjobs" $.Values.kubeStateMetric.collectors }} +- apiGroups: ["batch"] + resources: + - cronjobs + verbs: ["list", "watch"] +{{ end -}} +{{ if has "daemonsets" $.Values.kubeStateMetric.collectors }} +- apiGroups: ["extensions", "apps"] + resources: + - daemonsets + verbs: ["list", "watch"] +{{ end -}} +{{ if has "deployments" $.Values.kubeStateMetric.collectors }} +- apiGroups: ["extensions", "apps"] + resources: + - deployments + verbs: ["list", "watch"] +{{ end -}} +{{ if has "endpoints" $.Values.kubeStateMetric.collectors }} +- apiGroups: [""] + resources: + - endpoints + verbs: ["list", "watch"] +{{ end -}} +{{ if has "horizontalpodautoscalers" $.Values.kubeStateMetric.collectors }} +- apiGroups: ["autoscaling"] + resources: + - horizontalpodautoscalers + verbs: ["list", "watch"] +{{ end -}} +{{ if has "ingresses" $.Values.kubeStateMetric.collectors }} +- apiGroups: ["extensions", "networking.k8s.io"] + resources: + - ingresses + verbs: ["list", "watch"] +{{ end -}} +{{ if has "jobs" $.Values.kubeStateMetric.collectors }} +- apiGroups: ["batch"] + resources: + - jobs + verbs: ["list", "watch"] +{{ end -}} +{{ if has "limitranges" $.Values.kubeStateMetric.collectors }} +- apiGroups: [""] + resources: + - limitranges + verbs: ["list", "watch"] +{{ end -}} +{{ if has "mutatingwebhookconfigurations" $.Values.kubeStateMetric.collectors }} +- apiGroups: ["admissionregistration.k8s.io"] + resources: + - mutatingwebhookconfigurations + verbs: ["list", "watch"] +{{ end -}} +{{ if has "namespaces" $.Values.kubeStateMetric.collectors }} +- apiGroups: [""] + resources: + - namespaces + verbs: ["list", "watch"] +{{ end -}} +{{ if has "networkpolicies" $.Values.kubeStateMetric.collectors }} +- apiGroups: ["networking.k8s.io"] + resources: + - networkpolicies + verbs: ["list", "watch"] +{{ end -}} +{{ if has "nodes" $.Values.kubeStateMetric.collectors }} +- apiGroups: [""] + resources: + - nodes + verbs: ["list", "watch"] +{{ end -}} +{{ if has "persistentvolumeclaims" $.Values.kubeStateMetric.collectors }} +- apiGroups: [""] + resources: + - persistentvolumeclaims + verbs: ["list", "watch"] +{{ end -}} +{{ if has "persistentvolumes" $.Values.kubeStateMetric.collectors }} +- apiGroups: [""] + resources: + - persistentvolumes + verbs: ["list", "watch"] +{{ end -}} +{{ if has "poddisruptionbudgets" $.Values.kubeStateMetric.collectors }} +- apiGroups: ["policy"] + resources: + - poddisruptionbudgets + verbs: ["list", "watch"] +{{ end -}} +{{ if has "pods" $.Values.kubeStateMetric.collectors }} +- apiGroups: [""] + resources: + - pods + verbs: ["list", "watch"] +{{ end -}} +{{ if has "replicasets" $.Values.kubeStateMetric.collectors }} +- apiGroups: ["extensions", "apps"] + resources: + - replicasets + verbs: ["list", "watch"] +{{ end -}} +{{ if has "replicationcontrollers" $.Values.kubeStateMetric.collectors }} +- apiGroups: [""] + resources: + - replicationcontrollers + verbs: ["list", "watch"] +{{ end -}} +{{ if has "resourcequotas" $.Values.kubeStateMetric.collectors }} +- apiGroups: [""] + resources: + - resourcequotas + verbs: ["list", "watch"] +{{ end -}} +{{ if has "secrets" $.Values.kubeStateMetric.collectors }} +- apiGroups: [""] + resources: + - secrets + verbs: ["list", "watch"] +{{ end -}} +{{ if has "services" $.Values.kubeStateMetric.collectors }} +- apiGroups: [""] + resources: + - services + verbs: ["list", "watch"] +{{ end -}} +{{ if has "statefulsets" $.Values.kubeStateMetric.collectors }} +- apiGroups: ["apps"] + resources: + - statefulsets + verbs: ["list", "watch"] +{{ end -}} +{{ if has "storageclasses" $.Values.kubeStateMetric.collectors }} +- apiGroups: ["storage.k8s.io"] + resources: + - storageclasses + verbs: ["list", "watch"] +{{ end -}} +{{ if has "validatingwebhookconfigurations" $.Values.kubeStateMetric.collectors }} +- apiGroups: ["admissionregistration.k8s.io"] + resources: + - validatingwebhookconfigurations + verbs: ["list", "watch"] +{{ end -}} +{{ if has "volumeattachments" $.Values.kubeStateMetric.collectors }} +- apiGroups: ["storage.k8s.io"] + resources: + - volumeattachments + verbs: ["list", "watch"] +{{ end -}} +{{ if has "verticalpodautoscalers" $.Values.kubeStateMetric.collectors }} +- apiGroups: ["autoscaling.k8s.io"] + resources: + - verticalpodautoscalers + verbs: ["list", "watch"] +{{ end -}} +{{- end -}} diff --git a/stable/yugaware/templates/kube-state-metrics-clusterrolebinding.yaml b/stable/yugaware/templates/kube-state-metrics-clusterrolebinding.yaml new file mode 100644 index 0000000000..580889f450 --- /dev/null +++ b/stable/yugaware/templates/kube-state-metrics-clusterrolebinding.yaml @@ -0,0 +1,18 @@ +{{- if and .Values.kubeStateMetric.install (not .Values.kubeStateMetric.customEndpoint) -}} +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + labels: + app: {{ .Release.Name }}-yugaware-ksm + chart: {{ template "yugaware.chart" . }} + release: {{ .Release.Name }} + name: {{ .Release.Name }}-ksm +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: {{ .Release.Name }}-ksm +subjects: +- kind: ServiceAccount + name: {{ .Release.Name }}-ksm + namespace: {{ .Release.Namespace }} +{{- end -}} diff --git a/stable/yugaware/templates/kube-state-metrics-deployment.yaml b/stable/yugaware/templates/kube-state-metrics-deployment.yaml new file mode 100644 index 0000000000..411f4df749 --- /dev/null +++ b/stable/yugaware/templates/kube-state-metrics-deployment.yaml @@ -0,0 +1,66 @@ +{{- if and .Values.kubeStateMetric.install (not .Values.kubeStateMetric.customEndpoint) -}} +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ .Release.Name }}-ksm + {{- if .Values.yugaware.service.annotations }} + annotations: +{{ toYaml .Values.yugaware.service.annotations | indent 4 }} + {{- end }} + labels: + app: {{ .Release.Name }}-yugaware-ksm + chart: {{ template "yugaware.chart" . }} + release: {{ .Release.Name }} +spec: + selector: + matchLabels: + app: {{ .Release.Name }}-yugaware-ksm + replicas: {{ .Values.kubeStateMetric.replicas }} + template: + metadata: + labels: + app: {{ .Release.Name }}-yugaware-ksm + annotations: +{{- if .Values.yugaware.pod.annotations }} +{{ toYaml .Values.yugaware.pod.annotations | indent 8 }} +{{- end }} + spec: + serviceAccountName: {{ .Release.Name }} + {{- if .Values.kubeStateMetric.securityContext.enabled }} + securityContext: + fsGroup: {{ .Values.kubeStateMetric.securityContext.fsGroup }} + runAsGroup: {{ .Values.kubeStateMetric.securityContext.runAsGroup }} + runAsUser: {{ .Values.kubeStateMetric.securityContext.runAsUser }} + {{- end }} + containers: + - name: kube-state-metrics-yugaware + args: + {{- if .Values.kubeStateMetric.extraArgs }} + {{- range .Values.kubeStateMetric.extraArgs }} + - {{ . }} + {{- end }} + {{- end }} + - --port=8080 + - --resources={{ .Values.kubeStateMetric.collectors | join "," }} + imagePullPolicy: {{ .Values.kubeStateMetric.image.pullPolicy }} + image: "{{ .Values.kubeStateMetric.image.repository }}:{{ .Values.kubeStateMetric.image.tag }}" + ports: + - containerPort: 8080 + name: "http" + livenessProbe: + httpGet: + path: /healthz + port: 8080 + initialDelaySeconds: 5 + timeoutSeconds: 5 + readinessProbe: + httpGet: + path: / + port: 8080 + initialDelaySeconds: 5 + timeoutSeconds: 5 + {{- if .Values.kubeStateMetric.resources }} + resources: +{{ toYaml .Values.kubeStateMetric.resources | indent 10 }} +{{- end }} +{{- end -}} diff --git a/stable/yugaware/templates/kube-state-metrics-service-account.yaml b/stable/yugaware/templates/kube-state-metrics-service-account.yaml new file mode 100644 index 0000000000..4f202f994e --- /dev/null +++ b/stable/yugaware/templates/kube-state-metrics-service-account.yaml @@ -0,0 +1,14 @@ +{{- if and .Values.kubeStateMetric.install (not .Values.kubeStateMetric.customEndpoint) -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + labels: + app: {{ .Release.Name }}-yugaware-ksm + chart: {{ template "yugaware.chart" . }} + release: {{ .Release.Name }} + name: {{ .Release.Name }}-ksm +{{- if .Values.yugaware.serviceAccountAnnotations }} + annotations: +{{ toYaml .Values.yugaware.serviceAccountAnnotations | indent 4 }} +{{- end }} +{{- end -}} \ No newline at end of file diff --git a/stable/yugaware/templates/kube-state-metrics-service.yaml b/stable/yugaware/templates/kube-state-metrics-service.yaml new file mode 100644 index 0000000000..37b493a76e --- /dev/null +++ b/stable/yugaware/templates/kube-state-metrics-service.yaml @@ -0,0 +1,23 @@ +{{- if and .Values.kubeStateMetric.install (not .Values.kubeStateMetric.customEndpoint) -}} +apiVersion: v1 +kind: Service +metadata: + name: {{ .Release.Name }}-ksm + labels: + app: {{ .Release.Name }}-yugaware-ksm + chart: {{ template "yugaware.chart" . }} + release: {{ .Release.Name }} + {{- if .Values.yugaware.service.annotations }} + annotations: + {{ toYaml .Values.yugaware.service.annotations | indent 4 }} + {{- end }} +spec: + type: "ClusterIP" + ports: + - name: "http" + protocol: TCP + port: 8080 + targetPort: 8080 + selector: + app: {{ .Release.Name }}-yugaware-ksm +{{- end -}} diff --git a/stable/yugaware/values.yaml b/stable/yugaware/values.yaml index e7a1ce7f7d..40a768d58b 100644 --- a/stable/yugaware/values.yaml +++ b/stable/yugaware/values.yaml @@ -176,3 +176,36 @@ additionalAppConf: ## to modify this unless you are using helm template command i.e. GKE ## app's deployer image against a Kubernetes cluster >= 1.21. # pdbPolicyVersionOverride: "v1beta1" + +## kube-state-metric support +## Custom endpoint has higher priority than installation. +kubeStateMetric: + ## To provide custom kube-state-metric endpoint + # customEndpoint: "kube-state-metrics.svc.cluster.local:8080" + ## To enable the kube-state-metric installation along with platform + install: false + image: + repository: k8s.gcr.io/kube-state-metrics/kube-state-metrics + tag: v2.4.1 + pullPolicy: IfNotPresent + replicas: 1 + securityContext: + enabled: true + runAsGroup: 65534 + runAsUser: 65534 + fsGroup: 65534 + resources: + limits: + cpu: 100m + memory: 64Mi + requests: + cpu: 10m + memory: 32Mi + ## List of additional cli arguments to configure kube-state-metrics + ## for example: --enable-gzip-encoding, --log-file, etc. + ## all the possible args can be found here: https://github.com/kubernetes/kube-state-metrics/blob/master/docs/cli-arguments.md + extraArgs: [] + ## As we know platform need only nodes and pods metrics from kube-state-metrics + ## So we just enable the collector for nodes and pods. + collectors: + - pods From 94f7443c4f34933ac255ee0666e26dad02d0c507 Mon Sep 17 00:00:00 2001 From: baba230896 Date: Tue, 29 Mar 2022 06:44:48 +0000 Subject: [PATCH 2/5] [Plat-520] Added metric relabel for CPU metrics Summary - The kube-state-metric changed the following CPU metric name. And the Yugabyte Platform java code still uses the old metric name to show the CPU metric on Platform UI. At this place, we had two ways to solve this. Either update the java code or handle it in the Prometheus scrape configuration. We have chosen the second approach and fixed the Prometheus scrape configuration. Test - Deployed the platform using without this change and created the universe. We didn't have CPU metrics in the Platform UI at this time. Once I modified the Prometheus config using the helm upgrade, it started showing the CPU metrics. --- stable/yugaware/templates/configs.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/stable/yugaware/templates/configs.yaml b/stable/yugaware/templates/configs.yaml index 944c8586a4..ea9a760573 100644 --- a/stable/yugaware/templates/configs.yaml +++ b/stable/yugaware/templates/configs.yaml @@ -347,6 +347,10 @@ data: regex: "(.*)" target_label: "container_name" replacement: "$1" + - source_labels: ["__name__", "unit"] + regex: "kube_pod_container_resource_requests;core" + target_label: "__name__" + replacement: "kube_pod_container_resource_requests_cpu_cores" - job_name: 'kubernetes-cadvisor' From c9a54dabd0f7867c4799a943fa8939a513a5d486 Mon Sep 17 00:00:00 2001 From: baba230896 Date: Mon, 11 Apr 2022 06:25:50 +0000 Subject: [PATCH 3/5] [plat-520][k8s] Added relabel to modify old CPU metrics based on Kube-state-metric --- stable/yugaware/templates/configs.yaml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/stable/yugaware/templates/configs.yaml b/stable/yugaware/templates/configs.yaml index ea9a760573..3386d9a41d 100644 --- a/stable/yugaware/templates/configs.yaml +++ b/stable/yugaware/templates/configs.yaml @@ -347,10 +347,14 @@ data: regex: "(.*)" target_label: "container_name" replacement: "$1" - - source_labels: ["__name__", "unit"] - regex: "kube_pod_container_resource_requests;core" + - source_labels: ["__name__"] + regex: "kube_pod_container_resource_requests_cpu_cores" + target_label: "unit" + replacement: "core" + - source_labels: ["__name__"] + regex: "kube_pod_container_resource_requests_cpu_cores" target_label: "__name__" - replacement: "kube_pod_container_resource_requests_cpu_cores" + replacement: "kube_pod_container_resource_requests" - job_name: 'kubernetes-cadvisor' From a1a1b0444d6471bf224ac8222c5960afc437aa20 Mon Sep 17 00:00:00 2001 From: Yatish Sharma Date: Fri, 6 May 2022 13:12:40 +0530 Subject: [PATCH 4/5] Apply suggestions from code review 1. kubeStateMetric to kubeStateMetrics 2. Added a few explanatory comments Co-authored-by: Bhavin Gandhi --- stable/yugaware/templates/_helpers.tpl | 2 +- stable/yugaware/templates/configs.yaml | 2 ++ .../yugaware/templates/kube-state-metrics-clusterrole.yaml | 1 + .../yugaware/templates/kube-state-metrics-deployment.yaml | 1 + stable/yugaware/values.yaml | 6 +++--- 5 files changed, 8 insertions(+), 4 deletions(-) diff --git a/stable/yugaware/templates/_helpers.tpl b/stable/yugaware/templates/_helpers.tpl index c25b111f99..3ec9f3dc8b 100644 --- a/stable/yugaware/templates/_helpers.tpl +++ b/stable/yugaware/templates/_helpers.tpl @@ -116,7 +116,7 @@ Make list of allowed CORS origins {{/* kube-state-metrics */}} -{{- define "kubeStateMetric.endpoint" -}} +{{- define "yugaware.kubeStateMetrics.endpoint" -}} {{- if .Values.kubeStateMetric.customEndpoint -}} {{- .Values.kubeStateMetric.customEndpoint -}} {{- else if .Values.kubeStateMetric.install -}} diff --git a/stable/yugaware/templates/configs.yaml b/stable/yugaware/templates/configs.yaml index 3386d9a41d..b65f492c42 100644 --- a/stable/yugaware/templates/configs.yaml +++ b/stable/yugaware/templates/configs.yaml @@ -347,6 +347,8 @@ data: regex: "(.*)" target_label: "container_name" replacement: "$1" + # rename old name of the CPU metric to the new name and label + # ref: https://github.com/kubernetes/kube-state-metrics/blob/master/CHANGELOG.md#v200-alpha--2020-09-16 - source_labels: ["__name__"] regex: "kube_pod_container_resource_requests_cpu_cores" target_label: "unit" diff --git a/stable/yugaware/templates/kube-state-metrics-clusterrole.yaml b/stable/yugaware/templates/kube-state-metrics-clusterrole.yaml index 6514befbf4..5661b4e85b 100644 --- a/stable/yugaware/templates/kube-state-metrics-clusterrole.yaml +++ b/stable/yugaware/templates/kube-state-metrics-clusterrole.yaml @@ -1,3 +1,4 @@ +# Adapted from https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-state-metrics (Apache-2.0 license) {{- if and .Values.kubeStateMetric.install (not .Values.kubeStateMetric.customEndpoint) -}} apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole diff --git a/stable/yugaware/templates/kube-state-metrics-deployment.yaml b/stable/yugaware/templates/kube-state-metrics-deployment.yaml index 411f4df749..bfd337f273 100644 --- a/stable/yugaware/templates/kube-state-metrics-deployment.yaml +++ b/stable/yugaware/templates/kube-state-metrics-deployment.yaml @@ -1,3 +1,4 @@ +# Adapted from https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-state-metrics (Apache-2.0 license) {{- if and .Values.kubeStateMetric.install (not .Values.kubeStateMetric.customEndpoint) -}} apiVersion: apps/v1 kind: Deployment diff --git a/stable/yugaware/values.yaml b/stable/yugaware/values.yaml index 40a768d58b..377945e2bc 100644 --- a/stable/yugaware/values.yaml +++ b/stable/yugaware/values.yaml @@ -178,7 +178,7 @@ additionalAppConf: # pdbPolicyVersionOverride: "v1beta1" ## kube-state-metric support -## Custom endpoint has higher priority than installation. +## Custom endpoint has higher priority than installation. The endpoint value defaults to kube-state-metrics.kube-system.svc.:8080. kubeStateMetric: ## To provide custom kube-state-metric endpoint # customEndpoint: "kube-state-metrics.svc.cluster.local:8080" @@ -205,7 +205,7 @@ kubeStateMetric: ## for example: --enable-gzip-encoding, --log-file, etc. ## all the possible args can be found here: https://github.com/kubernetes/kube-state-metrics/blob/master/docs/cli-arguments.md extraArgs: [] - ## As we know platform need only nodes and pods metrics from kube-state-metrics - ## So we just enable the collector for nodes and pods. + ## As we know platform need only pods metrics from kube-state-metrics + ## So we just enable the collector for pods. collectors: - pods From c00d400426adb02be001e67908fd23df509cc221 Mon Sep 17 00:00:00 2001 From: baba230896 Date: Mon, 9 May 2022 06:14:52 +0000 Subject: [PATCH 5/5] Moved kube-state-metrics related templates to directory --- stable/yugaware/templates/_helpers.tpl | 6 +- stable/yugaware/templates/configs.yaml | 2 +- .../kube-state-metrics-deployment.yaml | 67 ------------------- .../kube-state-metrics-service-account.yaml | 14 ---- .../kube-state-metrics-clusterrole.yaml | 62 ++++++++--------- ...kube-state-metrics-clusterrolebinding.yaml | 2 +- .../kube-state-metrics-deployment.yaml | 61 +++++++++++++++++ .../kube-state-metrics-service-account.yaml | 10 +++ .../kube-state-metrics-service.yaml | 6 +- stable/yugaware/values.yaml | 4 +- 10 files changed, 111 insertions(+), 123 deletions(-) delete mode 100644 stable/yugaware/templates/kube-state-metrics-deployment.yaml delete mode 100644 stable/yugaware/templates/kube-state-metrics-service-account.yaml rename stable/yugaware/templates/{ => kube-state-metrics}/kube-state-metrics-clusterrole.yaml (61%) rename stable/yugaware/templates/{ => kube-state-metrics}/kube-state-metrics-clusterrolebinding.yaml (82%) create mode 100644 stable/yugaware/templates/kube-state-metrics/kube-state-metrics-deployment.yaml create mode 100644 stable/yugaware/templates/kube-state-metrics/kube-state-metrics-service-account.yaml rename stable/yugaware/templates/{ => kube-state-metrics}/kube-state-metrics-service.yaml (61%) diff --git a/stable/yugaware/templates/_helpers.tpl b/stable/yugaware/templates/_helpers.tpl index 3ec9f3dc8b..84e557a5d0 100644 --- a/stable/yugaware/templates/_helpers.tpl +++ b/stable/yugaware/templates/_helpers.tpl @@ -117,9 +117,9 @@ Make list of allowed CORS origins kube-state-metrics */}} {{- define "yugaware.kubeStateMetrics.endpoint" -}} -{{- if .Values.kubeStateMetric.customEndpoint -}} -{{- .Values.kubeStateMetric.customEndpoint -}} -{{- else if .Values.kubeStateMetric.install -}} +{{- if .Values.kubeStateMetrics.customEndpoint -}} +{{- .Values.kubeStateMetrics.customEndpoint -}} +{{- else if .Values.kubeStateMetrics.install -}} {{- printf "%s-ksm.%s.svc.%s:8080" .Release.Name .Release.Namespace .Values.domainName -}} {{- else -}} {{- printf "kube-state-metrics.kube-system.svc.%s:8080" .Values.domainName -}} diff --git a/stable/yugaware/templates/configs.yaml b/stable/yugaware/templates/configs.yaml index b65f492c42..9fc6c96c0d 100644 --- a/stable/yugaware/templates/configs.yaml +++ b/stable/yugaware/templates/configs.yaml @@ -332,7 +332,7 @@ data: - job_name: 'kube-state-metrics' static_configs: - - targets: ['{{ template "kubeStateMetric.endpoint" . }}'] + - targets: ['{{ template "yugaware.kubeStateMetrics.endpoint" . }}'] metric_relabel_configs: # Save the name of the metric so we can group_by since we cannot by __name__ directly... - source_labels: ["__name__"] diff --git a/stable/yugaware/templates/kube-state-metrics-deployment.yaml b/stable/yugaware/templates/kube-state-metrics-deployment.yaml deleted file mode 100644 index bfd337f273..0000000000 --- a/stable/yugaware/templates/kube-state-metrics-deployment.yaml +++ /dev/null @@ -1,67 +0,0 @@ -# Adapted from https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-state-metrics (Apache-2.0 license) -{{- if and .Values.kubeStateMetric.install (not .Values.kubeStateMetric.customEndpoint) -}} -apiVersion: apps/v1 -kind: Deployment -metadata: - name: {{ .Release.Name }}-ksm - {{- if .Values.yugaware.service.annotations }} - annotations: -{{ toYaml .Values.yugaware.service.annotations | indent 4 }} - {{- end }} - labels: - app: {{ .Release.Name }}-yugaware-ksm - chart: {{ template "yugaware.chart" . }} - release: {{ .Release.Name }} -spec: - selector: - matchLabels: - app: {{ .Release.Name }}-yugaware-ksm - replicas: {{ .Values.kubeStateMetric.replicas }} - template: - metadata: - labels: - app: {{ .Release.Name }}-yugaware-ksm - annotations: -{{- if .Values.yugaware.pod.annotations }} -{{ toYaml .Values.yugaware.pod.annotations | indent 8 }} -{{- end }} - spec: - serviceAccountName: {{ .Release.Name }} - {{- if .Values.kubeStateMetric.securityContext.enabled }} - securityContext: - fsGroup: {{ .Values.kubeStateMetric.securityContext.fsGroup }} - runAsGroup: {{ .Values.kubeStateMetric.securityContext.runAsGroup }} - runAsUser: {{ .Values.kubeStateMetric.securityContext.runAsUser }} - {{- end }} - containers: - - name: kube-state-metrics-yugaware - args: - {{- if .Values.kubeStateMetric.extraArgs }} - {{- range .Values.kubeStateMetric.extraArgs }} - - {{ . }} - {{- end }} - {{- end }} - - --port=8080 - - --resources={{ .Values.kubeStateMetric.collectors | join "," }} - imagePullPolicy: {{ .Values.kubeStateMetric.image.pullPolicy }} - image: "{{ .Values.kubeStateMetric.image.repository }}:{{ .Values.kubeStateMetric.image.tag }}" - ports: - - containerPort: 8080 - name: "http" - livenessProbe: - httpGet: - path: /healthz - port: 8080 - initialDelaySeconds: 5 - timeoutSeconds: 5 - readinessProbe: - httpGet: - path: / - port: 8080 - initialDelaySeconds: 5 - timeoutSeconds: 5 - {{- if .Values.kubeStateMetric.resources }} - resources: -{{ toYaml .Values.kubeStateMetric.resources | indent 10 }} -{{- end }} -{{- end -}} diff --git a/stable/yugaware/templates/kube-state-metrics-service-account.yaml b/stable/yugaware/templates/kube-state-metrics-service-account.yaml deleted file mode 100644 index 4f202f994e..0000000000 --- a/stable/yugaware/templates/kube-state-metrics-service-account.yaml +++ /dev/null @@ -1,14 +0,0 @@ -{{- if and .Values.kubeStateMetric.install (not .Values.kubeStateMetric.customEndpoint) -}} -apiVersion: v1 -kind: ServiceAccount -metadata: - labels: - app: {{ .Release.Name }}-yugaware-ksm - chart: {{ template "yugaware.chart" . }} - release: {{ .Release.Name }} - name: {{ .Release.Name }}-ksm -{{- if .Values.yugaware.serviceAccountAnnotations }} - annotations: -{{ toYaml .Values.yugaware.serviceAccountAnnotations | indent 4 }} -{{- end }} -{{- end -}} \ No newline at end of file diff --git a/stable/yugaware/templates/kube-state-metrics-clusterrole.yaml b/stable/yugaware/templates/kube-state-metrics/kube-state-metrics-clusterrole.yaml similarity index 61% rename from stable/yugaware/templates/kube-state-metrics-clusterrole.yaml rename to stable/yugaware/templates/kube-state-metrics/kube-state-metrics-clusterrole.yaml index 5661b4e85b..d277ec3c65 100644 --- a/stable/yugaware/templates/kube-state-metrics-clusterrole.yaml +++ b/stable/yugaware/templates/kube-state-metrics/kube-state-metrics-clusterrole.yaml @@ -1,5 +1,7 @@ -# Adapted from https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-state-metrics (Apache-2.0 license) -{{- if and .Values.kubeStateMetric.install (not .Values.kubeStateMetric.customEndpoint) -}} +{{- /* + Adapted from https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-state-metrics (Apache-2.0 license). + */}} +{{- if and .Values.kubeStateMetrics.install (not .Values.kubeStateMetrics.customEndpoint) -}} apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: @@ -9,169 +11,169 @@ metadata: release: {{ .Release.Name }} name: {{ .Release.Name }}-ksm rules: -{{ if has "certificatesigningrequests" $.Values.kubeStateMetric.collectors }} +{{ if has "certificatesigningrequests" $.Values.kubeStateMetrics.collectors }} - apiGroups: ["certificates.k8s.io"] resources: - certificatesigningrequests verbs: ["list", "watch"] {{ end -}} -{{ if has "configmaps" $.Values.kubeStateMetric.collectors }} +{{ if has "configmaps" $.Values.kubeStateMetrics.collectors }} - apiGroups: [""] resources: - configmaps verbs: ["list", "watch"] {{ end -}} -{{ if has "cronjobs" $.Values.kubeStateMetric.collectors }} +{{ if has "cronjobs" $.Values.kubeStateMetrics.collectors }} - apiGroups: ["batch"] resources: - cronjobs verbs: ["list", "watch"] {{ end -}} -{{ if has "daemonsets" $.Values.kubeStateMetric.collectors }} +{{ if has "daemonsets" $.Values.kubeStateMetrics.collectors }} - apiGroups: ["extensions", "apps"] resources: - daemonsets verbs: ["list", "watch"] {{ end -}} -{{ if has "deployments" $.Values.kubeStateMetric.collectors }} +{{ if has "deployments" $.Values.kubeStateMetrics.collectors }} - apiGroups: ["extensions", "apps"] resources: - deployments verbs: ["list", "watch"] {{ end -}} -{{ if has "endpoints" $.Values.kubeStateMetric.collectors }} +{{ if has "endpoints" $.Values.kubeStateMetrics.collectors }} - apiGroups: [""] resources: - endpoints verbs: ["list", "watch"] {{ end -}} -{{ if has "horizontalpodautoscalers" $.Values.kubeStateMetric.collectors }} +{{ if has "horizontalpodautoscalers" $.Values.kubeStateMetrics.collectors }} - apiGroups: ["autoscaling"] resources: - horizontalpodautoscalers verbs: ["list", "watch"] {{ end -}} -{{ if has "ingresses" $.Values.kubeStateMetric.collectors }} +{{ if has "ingresses" $.Values.kubeStateMetrics.collectors }} - apiGroups: ["extensions", "networking.k8s.io"] resources: - ingresses verbs: ["list", "watch"] {{ end -}} -{{ if has "jobs" $.Values.kubeStateMetric.collectors }} +{{ if has "jobs" $.Values.kubeStateMetrics.collectors }} - apiGroups: ["batch"] resources: - jobs verbs: ["list", "watch"] {{ end -}} -{{ if has "limitranges" $.Values.kubeStateMetric.collectors }} +{{ if has "limitranges" $.Values.kubeStateMetrics.collectors }} - apiGroups: [""] resources: - limitranges verbs: ["list", "watch"] {{ end -}} -{{ if has "mutatingwebhookconfigurations" $.Values.kubeStateMetric.collectors }} +{{ if has "mutatingwebhookconfigurations" $.Values.kubeStateMetrics.collectors }} - apiGroups: ["admissionregistration.k8s.io"] resources: - mutatingwebhookconfigurations verbs: ["list", "watch"] {{ end -}} -{{ if has "namespaces" $.Values.kubeStateMetric.collectors }} +{{ if has "namespaces" $.Values.kubeStateMetrics.collectors }} - apiGroups: [""] resources: - namespaces verbs: ["list", "watch"] {{ end -}} -{{ if has "networkpolicies" $.Values.kubeStateMetric.collectors }} +{{ if has "networkpolicies" $.Values.kubeStateMetrics.collectors }} - apiGroups: ["networking.k8s.io"] resources: - networkpolicies verbs: ["list", "watch"] {{ end -}} -{{ if has "nodes" $.Values.kubeStateMetric.collectors }} +{{ if has "nodes" $.Values.kubeStateMetrics.collectors }} - apiGroups: [""] resources: - nodes verbs: ["list", "watch"] {{ end -}} -{{ if has "persistentvolumeclaims" $.Values.kubeStateMetric.collectors }} +{{ if has "persistentvolumeclaims" $.Values.kubeStateMetrics.collectors }} - apiGroups: [""] resources: - persistentvolumeclaims verbs: ["list", "watch"] {{ end -}} -{{ if has "persistentvolumes" $.Values.kubeStateMetric.collectors }} +{{ if has "persistentvolumes" $.Values.kubeStateMetrics.collectors }} - apiGroups: [""] resources: - persistentvolumes verbs: ["list", "watch"] {{ end -}} -{{ if has "poddisruptionbudgets" $.Values.kubeStateMetric.collectors }} +{{ if has "poddisruptionbudgets" $.Values.kubeStateMetrics.collectors }} - apiGroups: ["policy"] resources: - poddisruptionbudgets verbs: ["list", "watch"] {{ end -}} -{{ if has "pods" $.Values.kubeStateMetric.collectors }} +{{ if has "pods" $.Values.kubeStateMetrics.collectors }} - apiGroups: [""] resources: - pods verbs: ["list", "watch"] {{ end -}} -{{ if has "replicasets" $.Values.kubeStateMetric.collectors }} +{{ if has "replicasets" $.Values.kubeStateMetrics.collectors }} - apiGroups: ["extensions", "apps"] resources: - replicasets verbs: ["list", "watch"] {{ end -}} -{{ if has "replicationcontrollers" $.Values.kubeStateMetric.collectors }} +{{ if has "replicationcontrollers" $.Values.kubeStateMetrics.collectors }} - apiGroups: [""] resources: - replicationcontrollers verbs: ["list", "watch"] {{ end -}} -{{ if has "resourcequotas" $.Values.kubeStateMetric.collectors }} +{{ if has "resourcequotas" $.Values.kubeStateMetrics.collectors }} - apiGroups: [""] resources: - resourcequotas verbs: ["list", "watch"] {{ end -}} -{{ if has "secrets" $.Values.kubeStateMetric.collectors }} +{{ if has "secrets" $.Values.kubeStateMetrics.collectors }} - apiGroups: [""] resources: - secrets verbs: ["list", "watch"] {{ end -}} -{{ if has "services" $.Values.kubeStateMetric.collectors }} +{{ if has "services" $.Values.kubeStateMetrics.collectors }} - apiGroups: [""] resources: - services verbs: ["list", "watch"] {{ end -}} -{{ if has "statefulsets" $.Values.kubeStateMetric.collectors }} +{{ if has "statefulsets" $.Values.kubeStateMetrics.collectors }} - apiGroups: ["apps"] resources: - statefulsets verbs: ["list", "watch"] {{ end -}} -{{ if has "storageclasses" $.Values.kubeStateMetric.collectors }} +{{ if has "storageclasses" $.Values.kubeStateMetrics.collectors }} - apiGroups: ["storage.k8s.io"] resources: - storageclasses verbs: ["list", "watch"] {{ end -}} -{{ if has "validatingwebhookconfigurations" $.Values.kubeStateMetric.collectors }} +{{ if has "validatingwebhookconfigurations" $.Values.kubeStateMetrics.collectors }} - apiGroups: ["admissionregistration.k8s.io"] resources: - validatingwebhookconfigurations verbs: ["list", "watch"] {{ end -}} -{{ if has "volumeattachments" $.Values.kubeStateMetric.collectors }} +{{ if has "volumeattachments" $.Values.kubeStateMetrics.collectors }} - apiGroups: ["storage.k8s.io"] resources: - volumeattachments verbs: ["list", "watch"] {{ end -}} -{{ if has "verticalpodautoscalers" $.Values.kubeStateMetric.collectors }} +{{ if has "verticalpodautoscalers" $.Values.kubeStateMetrics.collectors }} - apiGroups: ["autoscaling.k8s.io"] resources: - verticalpodautoscalers diff --git a/stable/yugaware/templates/kube-state-metrics-clusterrolebinding.yaml b/stable/yugaware/templates/kube-state-metrics/kube-state-metrics-clusterrolebinding.yaml similarity index 82% rename from stable/yugaware/templates/kube-state-metrics-clusterrolebinding.yaml rename to stable/yugaware/templates/kube-state-metrics/kube-state-metrics-clusterrolebinding.yaml index 580889f450..c4de9f9020 100644 --- a/stable/yugaware/templates/kube-state-metrics-clusterrolebinding.yaml +++ b/stable/yugaware/templates/kube-state-metrics/kube-state-metrics-clusterrolebinding.yaml @@ -1,4 +1,4 @@ -{{- if and .Values.kubeStateMetric.install (not .Values.kubeStateMetric.customEndpoint) -}} +{{- if and .Values.kubeStateMetrics.install (not .Values.kubeStateMetrics.customEndpoint) -}} apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: diff --git a/stable/yugaware/templates/kube-state-metrics/kube-state-metrics-deployment.yaml b/stable/yugaware/templates/kube-state-metrics/kube-state-metrics-deployment.yaml new file mode 100644 index 0000000000..5797b21495 --- /dev/null +++ b/stable/yugaware/templates/kube-state-metrics/kube-state-metrics-deployment.yaml @@ -0,0 +1,61 @@ +{{- /* + Adapted from https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-state-metrics (Apache-2.0 license) + */}} +{{- if and .Values.kubeStateMetrics.install (not .Values.kubeStateMetrics.customEndpoint) -}} +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ .Release.Name }}-ksm + labels: + app: {{ .Release.Name }}-yugaware-ksm + chart: {{ template "yugaware.chart" . }} + release: {{ .Release.Name }} +spec: + selector: + matchLabels: + app: {{ .Release.Name }}-yugaware-ksm + replicas: {{ .Values.kubeStateMetrics.replicas }} + template: + metadata: + labels: + app: {{ .Release.Name }}-yugaware-ksm + spec: + serviceAccountName: {{ .Release.Name }} + {{- if .Values.kubeStateMetrics.securityContext.enabled }} + securityContext: + fsGroup: {{ .Values.kubeStateMetrics.securityContext.fsGroup }} + runAsGroup: {{ .Values.kubeStateMetrics.securityContext.runAsGroup }} + runAsUser: {{ .Values.kubeStateMetrics.securityContext.runAsUser }} + {{- end }} + containers: + - name: kube-state-metrics-yugaware + args: + {{- if .Values.kubeStateMetrics.extraArgs }} + {{- range .Values.kubeStateMetrics.extraArgs }} + - {{ . }} + {{- end }} + {{- end }} + - --port=8080 + - --resources={{ .Values.kubeStateMetrics.collectors | join "," }} + imagePullPolicy: {{ .Values.kubeStateMetrics.image.pullPolicy }} + image: "{{ .Values.kubeStateMetrics.image.repository }}:{{ .Values.kubeStateMetrics.image.tag }}" + ports: + - containerPort: 8080 + name: "http" + livenessProbe: + httpGet: + path: /healthz + port: 8080 + initialDelaySeconds: 5 + timeoutSeconds: 5 + readinessProbe: + httpGet: + path: / + port: 8080 + initialDelaySeconds: 5 + timeoutSeconds: 5 + {{- if .Values.kubeStateMetrics.resources }} + resources: +{{ toYaml .Values.kubeStateMetrics.resources | indent 10 }} +{{- end }} +{{- end -}} diff --git a/stable/yugaware/templates/kube-state-metrics/kube-state-metrics-service-account.yaml b/stable/yugaware/templates/kube-state-metrics/kube-state-metrics-service-account.yaml new file mode 100644 index 0000000000..a499333f9d --- /dev/null +++ b/stable/yugaware/templates/kube-state-metrics/kube-state-metrics-service-account.yaml @@ -0,0 +1,10 @@ +{{- if and .Values.kubeStateMetrics.install (not .Values.kubeStateMetrics.customEndpoint) -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + labels: + app: {{ .Release.Name }}-yugaware-ksm + chart: {{ template "yugaware.chart" . }} + release: {{ .Release.Name }} + name: {{ .Release.Name }}-ksm +{{- end -}} \ No newline at end of file diff --git a/stable/yugaware/templates/kube-state-metrics-service.yaml b/stable/yugaware/templates/kube-state-metrics/kube-state-metrics-service.yaml similarity index 61% rename from stable/yugaware/templates/kube-state-metrics-service.yaml rename to stable/yugaware/templates/kube-state-metrics/kube-state-metrics-service.yaml index 37b493a76e..ae91ce65f8 100644 --- a/stable/yugaware/templates/kube-state-metrics-service.yaml +++ b/stable/yugaware/templates/kube-state-metrics/kube-state-metrics-service.yaml @@ -1,4 +1,4 @@ -{{- if and .Values.kubeStateMetric.install (not .Values.kubeStateMetric.customEndpoint) -}} +{{- if and .Values.kubeStateMetrics.install (not .Values.kubeStateMetrics.customEndpoint) -}} apiVersion: v1 kind: Service metadata: @@ -7,10 +7,6 @@ metadata: app: {{ .Release.Name }}-yugaware-ksm chart: {{ template "yugaware.chart" . }} release: {{ .Release.Name }} - {{- if .Values.yugaware.service.annotations }} - annotations: - {{ toYaml .Values.yugaware.service.annotations | indent 4 }} - {{- end }} spec: type: "ClusterIP" ports: diff --git a/stable/yugaware/values.yaml b/stable/yugaware/values.yaml index 377945e2bc..311884e42c 100644 --- a/stable/yugaware/values.yaml +++ b/stable/yugaware/values.yaml @@ -177,9 +177,9 @@ additionalAppConf: ## app's deployer image against a Kubernetes cluster >= 1.21. # pdbPolicyVersionOverride: "v1beta1" -## kube-state-metric support +## kube-state-metrics support ## Custom endpoint has higher priority than installation. The endpoint value defaults to kube-state-metrics.kube-system.svc.:8080. -kubeStateMetric: +kubeStateMetrics: ## To provide custom kube-state-metric endpoint # customEndpoint: "kube-state-metrics.svc.cluster.local:8080" ## To enable the kube-state-metric installation along with platform