-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
contrib/kube-prometheus: Create prometheus-adapter component
contrib/kube-prometheus: Add section on Prometheus Adapter requirements to README.md
- Loading branch information
1 parent
70722ae
commit 556153e
Showing
16 changed files
with
378 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
198 changes: 198 additions & 0 deletions
198
...b/kube-prometheus/jsonnet/kube-prometheus/prometheus-adapter/prometheus-adapter.libsonnet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,198 @@ | ||
local k = import 'ksonnet/ksonnet.beta.3/k.libsonnet'; | ||
|
||
{ | ||
_config+:: { | ||
namespace: 'default', | ||
|
||
versions+:: { | ||
prometheusAdapter: 'v0.3.0', | ||
}, | ||
|
||
imageRepos+:: { | ||
prometheusAdapter: 'quay.io/coreos/k8s-prometheus-adapter-amd64', | ||
}, | ||
|
||
prometheusAdapter+:: { | ||
name: 'prometheus-adapter', | ||
labels: { name: $._config.prometheusAdapter.name }, | ||
config: ||| | ||
resourceRules: | ||
cpu: | ||
containerQuery: sum(rate(container_cpu_usage_seconds_total{<<.LabelMatchers>>}[1m])) by (<<.GroupBy>>) | ||
nodeQuery: sum(rate(container_cpu_usage_seconds_total{<<.LabelMatchers>>, id='/'}[1m])) by (<<.GroupBy>>) | ||
resources: | ||
overrides: | ||
node: | ||
resource: node | ||
namespace: | ||
resource: namespace | ||
pod_name: | ||
resource: pod | ||
containerLabel: container_name | ||
memory: | ||
containerQuery: sum(container_memory_working_set_bytes{<<.LabelMatchers>>}) by (<<.GroupBy>>) | ||
nodeQuery: sum(container_memory_working_set_bytes{<<.LabelMatchers>>,id='/'}) by (<<.GroupBy>>) | ||
resources: | ||
overrides: | ||
node: | ||
resource: node | ||
namespace: | ||
resource: namespace | ||
pod_name: | ||
resource: pod | ||
containerLabel: container_name | ||
window: 1m | ||
|||, | ||
}, | ||
}, | ||
|
||
prometheusAdapter+:: { | ||
apiService: | ||
{ | ||
apiVersion: 'apiregistration.k8s.io/v1beta1', | ||
kind: 'APIService', | ||
metadata: { | ||
name: 'v1beta1.metrics.k8s.io', | ||
}, | ||
spec: { | ||
service: { | ||
name: $.prometheusAdapter.service.metadata.name, | ||
namespace: $._config.namespace, | ||
}, | ||
group: 'metrics.k8s.io', | ||
version: 'v1beta1', | ||
insecureSkipTLSVerify: true, | ||
groupPriorityMinimum: 100, | ||
versionPriority: 100, | ||
}, | ||
}, | ||
|
||
configMap: | ||
local configmap = k.core.v1.configMap; | ||
|
||
configmap.new('adapter-config', { 'config.yaml': $._config.prometheusAdapter.config }) + | ||
configmap.mixin.metadata.withNamespace($._config.namespace), | ||
|
||
service: | ||
local service = k.core.v1.service; | ||
local servicePort = k.core.v1.service.mixin.spec.portsType; | ||
|
||
service.new( | ||
$._config.prometheusAdapter.name, | ||
$._config.prometheusAdapter.labels, | ||
servicePort.newNamed('https', 443, 6443), | ||
) + | ||
service.mixin.metadata.withNamespace($._config.namespace) + | ||
service.mixin.metadata.withLabels($._config.prometheusAdapter.labels), | ||
|
||
deployment: | ||
local deployment = k.apps.v1beta2.deployment; | ||
local volume = deployment.mixin.spec.template.spec.volumesType; | ||
local container = deployment.mixin.spec.template.spec.containersType; | ||
local containerVolumeMount = container.volumeMountsType; | ||
|
||
local c = | ||
container.new($._config.prometheusAdapter.name, $._config.imageRepos.prometheusAdapter + ':' + $._config.versions.prometheusAdapter) + | ||
container.withArgs([ | ||
'--cert-dir=/var/run/serving-cert', | ||
'--config=/etc/adapter/config.yaml', | ||
'--logtostderr=true', | ||
'--metrics-relist-interval=1m', | ||
'--prometheus-url=http://prometheus-' + $._config.prometheus.name + '.' + $._config.namespace + '.svc:9090/', | ||
'--secure-port=6443', | ||
]) + | ||
container.withPorts([{ containerPort: 6443 }]) + | ||
container.withVolumeMounts([ | ||
containerVolumeMount.new('volume-serving-cert', '/var/run/serving-cert'), | ||
containerVolumeMount.new('config', '/etc/adapter'), | ||
],); | ||
|
||
deployment.new($._config.prometheusAdapter.name, 1, c, $._config.prometheusAdapter.labels) + | ||
deployment.mixin.metadata.withNamespace($._config.namespace) + | ||
deployment.mixin.spec.selector.withMatchLabels($._config.prometheusAdapter.labels) + | ||
deployment.mixin.spec.template.spec.withServiceAccountName($.prometheusAdapter.serviceAccount.metadata.name) + | ||
deployment.mixin.spec.template.spec.withVolumes([ | ||
// volume.fromSecret('volume-serving-cert', 'cm-adapter-serving-certs'), | ||
volume.fromEmptyDir(name='volume-serving-cert'), | ||
{ name: 'config', configMap: { name: 'adapter-config' } }, | ||
]), | ||
|
||
serviceAccount: | ||
local serviceAccount = k.core.v1.serviceAccount; | ||
|
||
serviceAccount.new($._config.prometheusAdapter.name) + | ||
serviceAccount.mixin.metadata.withNamespace($._config.namespace), | ||
|
||
clusterRole: | ||
local clusterRole = k.rbac.v1.clusterRole; | ||
local policyRule = clusterRole.rulesType; | ||
|
||
local rules = | ||
policyRule.new() + | ||
policyRule.withApiGroups(['']) + | ||
policyRule.withResources(['nodes', 'namespaces', 'pods', 'services']) + | ||
policyRule.withVerbs(['get', 'list', 'watch']); | ||
|
||
clusterRole.new() + | ||
clusterRole.mixin.metadata.withName($._config.prometheusAdapter.name) + | ||
clusterRole.withRules(rules), | ||
|
||
clusterRoleBinding: | ||
local clusterRoleBinding = k.rbac.v1.clusterRoleBinding; | ||
|
||
clusterRoleBinding.new() + | ||
clusterRoleBinding.mixin.metadata.withName($._config.prometheusAdapter.name) + | ||
clusterRoleBinding.mixin.metadata.withNamespace($._config.namespace) + | ||
clusterRoleBinding.mixin.roleRef.withApiGroup('rbac.authorization.k8s.io') + | ||
clusterRoleBinding.mixin.roleRef.withName($.prometheusAdapter.clusterRole.metadata.name) + | ||
clusterRoleBinding.mixin.roleRef.mixinInstance({ kind: 'ClusterRole' }) + | ||
clusterRoleBinding.withSubjects([{ | ||
kind: 'ServiceAccount', | ||
name: $.prometheusAdapter.serviceAccount.metadata.name, | ||
namespace: $._config.namespace, | ||
}]), | ||
|
||
clusterRoleBindingDelegator: | ||
local clusterRoleBinding = k.rbac.v1.clusterRoleBinding; | ||
|
||
clusterRoleBinding.new() + | ||
clusterRoleBinding.mixin.metadata.withName('resource-metrics:system:auth-delegator') + | ||
clusterRoleBinding.mixin.roleRef.withApiGroup('rbac.authorization.k8s.io') + | ||
clusterRoleBinding.mixin.roleRef.withName('system:auth-delegator') + | ||
clusterRoleBinding.mixin.roleRef.mixinInstance({ kind: 'ClusterRole' }) + | ||
clusterRoleBinding.withSubjects([{ | ||
kind: 'ServiceAccount', | ||
name: $.prometheusAdapter.serviceAccount.metadata.name, | ||
namespace: $._config.namespace, | ||
}]), | ||
|
||
clusterRoleServerResources: | ||
local clusterRole = k.rbac.v1.clusterRole; | ||
local policyRule = clusterRole.rulesType; | ||
|
||
local rules = | ||
policyRule.new() + | ||
policyRule.withApiGroups(['metrics.k8s.io']) + | ||
policyRule.withResources(['*']) + | ||
policyRule.withVerbs(['*']); | ||
|
||
clusterRole.new() + | ||
clusterRole.mixin.metadata.withName('resource-metrics-server-resources') + | ||
clusterRole.withRules(rules), | ||
|
||
roleBindingAuthReader: | ||
local roleBinding = k.rbac.v1.roleBinding; | ||
|
||
roleBinding.new() + | ||
roleBinding.mixin.metadata.withName('resource-metrics-auth-reader') + | ||
roleBinding.mixin.metadata.withNamespace('kube-system') + | ||
roleBinding.mixin.roleRef.withApiGroup('rbac.authorization.k8s.io') + | ||
roleBinding.mixin.roleRef.withName('extension-apiserver-authentication-reader') + | ||
roleBinding.mixin.roleRef.mixinInstance({ kind: 'Role' }) + | ||
roleBinding.withSubjects([{ | ||
kind: 'ServiceAccount', | ||
name: $.prometheusAdapter.serviceAccount.metadata.name, | ||
namespace: $._config.namespace, | ||
}]), | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
contrib/kube-prometheus/manifests/prometheus-adapter-apiService.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
apiVersion: apiregistration.k8s.io/v1beta1 | ||
kind: APIService | ||
metadata: | ||
name: v1beta1.metrics.k8s.io | ||
spec: | ||
group: metrics.k8s.io | ||
groupPriorityMinimum: 100 | ||
insecureSkipTLSVerify: true | ||
service: | ||
name: prometheus-adapter | ||
namespace: monitoring | ||
version: v1beta1 | ||
versionPriority: 100 |
16 changes: 16 additions & 0 deletions
16
contrib/kube-prometheus/manifests/prometheus-adapter-clusterRole.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRole | ||
metadata: | ||
name: prometheus-adapter | ||
rules: | ||
- apiGroups: | ||
- "" | ||
resources: | ||
- nodes | ||
- namespaces | ||
- pods | ||
- services | ||
verbs: | ||
- get | ||
- list | ||
- watch |
13 changes: 13 additions & 0 deletions
13
contrib/kube-prometheus/manifests/prometheus-adapter-clusterRoleBinding.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: prometheus-adapter | ||
namespace: monitoring | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: ClusterRole | ||
name: prometheus-adapter | ||
subjects: | ||
- kind: ServiceAccount | ||
name: prometheus-adapter | ||
namespace: monitoring |
12 changes: 12 additions & 0 deletions
12
contrib/kube-prometheus/manifests/prometheus-adapter-clusterRoleBindingDelegator.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: resource-metrics:system:auth-delegator | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: ClusterRole | ||
name: system:auth-delegator | ||
subjects: | ||
- kind: ServiceAccount | ||
name: prometheus-adapter | ||
namespace: monitoring |
11 changes: 11 additions & 0 deletions
11
contrib/kube-prometheus/manifests/prometheus-adapter-clusterRoleServerResources.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRole | ||
metadata: | ||
name: resource-metrics-server-resources | ||
rules: | ||
- apiGroups: | ||
- metrics.k8s.io | ||
resources: | ||
- '*' | ||
verbs: | ||
- '*' |
33 changes: 33 additions & 0 deletions
33
contrib/kube-prometheus/manifests/prometheus-adapter-configMap.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
apiVersion: v1 | ||
data: | ||
config.yaml: | | ||
resourceRules: | ||
cpu: | ||
containerQuery: sum(rate(container_cpu_usage_seconds_total{<<.LabelMatchers>>}[1m])) by (<<.GroupBy>>) | ||
nodeQuery: sum(rate(container_cpu_usage_seconds_total{<<.LabelMatchers>>, id='/'}[1m])) by (<<.GroupBy>>) | ||
resources: | ||
overrides: | ||
node: | ||
resource: node | ||
namespace: | ||
resource: namespace | ||
pod_name: | ||
resource: pod | ||
containerLabel: container_name | ||
memory: | ||
containerQuery: sum(container_memory_working_set_bytes{<<.LabelMatchers>>}) by (<<.GroupBy>>) | ||
nodeQuery: sum(container_memory_working_set_bytes{<<.LabelMatchers>>,id='/'}) by (<<.GroupBy>>) | ||
resources: | ||
overrides: | ||
node: | ||
resource: node | ||
namespace: | ||
resource: namespace | ||
pod_name: | ||
resource: pod | ||
containerLabel: container_name | ||
window: 1m | ||
kind: ConfigMap | ||
metadata: | ||
name: adapter-config | ||
namespace: monitoring |
Oops, something went wrong.