mirror of
https://github.com/kubernetes-sigs/prometheus-adapter.git
synced 2026-04-07 10:17:51 +00:00
Merge pull request #1 from briano-addepar/briano/get-stuff-working
Briano/get stuff working
This commit is contained in:
commit
ae55c3fe01
12 changed files with 239 additions and 1 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -2,3 +2,5 @@
|
||||||
*~
|
*~
|
||||||
/vendor
|
/vendor
|
||||||
/adapter
|
/adapter
|
||||||
|
deploy/addepar/certs/test
|
||||||
|
.idea
|
||||||
|
|
|
||||||
16
deploy/Makefile
Normal file
16
deploy/Makefile
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
# Run in custom metrics namespace
|
||||||
|
deploy-adapter-local:
|
||||||
|
kubectl apply -f manifests/
|
||||||
|
|
||||||
|
# Run in custom metrics namespace
|
||||||
|
delete-adapter-local:
|
||||||
|
kubectl delete -f manifests/
|
||||||
|
|
||||||
|
namespace:
|
||||||
|
kubectl create namespace custom-metrics
|
||||||
|
|
||||||
|
raw:
|
||||||
|
kubectl get --raw /apis/custom.metrics.k8s.io/v1beta1
|
||||||
|
|
||||||
|
shell:
|
||||||
|
kubectl run -it --rm --restart=Never alpine --image=alpine sh --limits="cpu=500m,memory=512Mi"
|
||||||
16
deploy/addepar/certs/Makefile
Normal file
16
deploy/addepar/certs/Makefile
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
.PHONY: build clean deploy
|
||||||
|
|
||||||
|
all: clean build deploy
|
||||||
|
|
||||||
|
build:
|
||||||
|
$(shell cd test && ../gencerts.sh)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf test
|
||||||
|
mkdir test
|
||||||
|
|
||||||
|
deploy:
|
||||||
|
kubectl -n custom-metrics create -f test/cm-adapter-serving-certs.yaml
|
||||||
|
|
||||||
|
delete:
|
||||||
|
kubectl -n custom-metrics delete -f test/cm-adapter-serving-certs.yaml
|
||||||
37
deploy/addepar/certs/gencerts.sh
Executable file
37
deploy/addepar/certs/gencerts.sh
Executable file
|
|
@ -0,0 +1,37 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
# exit immediately when a command fails
|
||||||
|
set -e
|
||||||
|
# only exit with zero if all commands of the pipeline exit successfully
|
||||||
|
set -o pipefail
|
||||||
|
# error on unset variables
|
||||||
|
set -u
|
||||||
|
|
||||||
|
# Detect if we are on mac or should use GNU base64 options
|
||||||
|
case $(uname) in
|
||||||
|
Darwin)
|
||||||
|
b64_opts='-b=0'
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
b64_opts='--wrap=0'
|
||||||
|
esac
|
||||||
|
|
||||||
|
#go get -v -u github.com/cloudflare/cfssl/cmd/...
|
||||||
|
|
||||||
|
export PURPOSE=metrics
|
||||||
|
openssl req -x509 -sha256 -new -nodes -days 365 -newkey rsa:2048 -keyout ${PURPOSE}-ca.key -out ${PURPOSE}-ca.crt -subj "/CN=ca"
|
||||||
|
echo '{"signing":{"default":{"expiry":"43800h","usages":["signing","key encipherment","'${PURPOSE}'"]}}}' > "${PURPOSE}-ca-config.json"
|
||||||
|
|
||||||
|
export SERVICE_NAME=custom-metrics-apiserver
|
||||||
|
export ALT_NAMES='"custom-metrics-apiserver.monitoring","custom-metrics-apiserver.monitoring.svc"'
|
||||||
|
echo "{\"CN\":\"${SERVICE_NAME}\", \"hosts\": [${ALT_NAMES}], \"key\": {\"algo\": \"rsa\",\"size\": 2048}}" | \
|
||||||
|
cfssl gencert -ca=metrics-ca.crt -ca-key=metrics-ca.key -config=metrics-ca-config.json - | cfssljson -bare apiserver
|
||||||
|
|
||||||
|
cat <<-EOF > cm-adapter-serving-certs.yaml
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: cm-adapter-serving-certs
|
||||||
|
data:
|
||||||
|
serving.crt: $(base64 ${b64_opts} < apiserver.pem)
|
||||||
|
serving.key: $(base64 ${b64_opts} < apiserver-key.pem)
|
||||||
|
EOF
|
||||||
5
deploy/addepar/prometheus/Makefile
Normal file
5
deploy/addepar/prometheus/Makefile
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
deploy:
|
||||||
|
kubectl create -n prom -f prometheus.yaml
|
||||||
|
|
||||||
|
namespace:
|
||||||
|
kubectl create namespace prom
|
||||||
63
deploy/addepar/prometheus/prometheus.yaml
Normal file
63
deploy/addepar/prometheus/prometheus.yaml
Normal file
|
|
@ -0,0 +1,63 @@
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ServiceAccount
|
||||||
|
metadata:
|
||||||
|
name: prometheus
|
||||||
|
---
|
||||||
|
apiVersion: rbac.authorization.k8s.io/v1beta1
|
||||||
|
kind: ClusterRole
|
||||||
|
metadata:
|
||||||
|
name: prometheus
|
||||||
|
rules:
|
||||||
|
- apiGroups: [""]
|
||||||
|
resources:
|
||||||
|
- nodes
|
||||||
|
- services
|
||||||
|
- endpoints
|
||||||
|
- pods
|
||||||
|
verbs: ["get", "list", "watch"]
|
||||||
|
- apiGroups: [""]
|
||||||
|
resources:
|
||||||
|
- configmaps
|
||||||
|
verbs: ["get"]
|
||||||
|
- nonResourceURLs: ["/metrics"]
|
||||||
|
verbs: ["get"]
|
||||||
|
---
|
||||||
|
apiVersion: rbac.authorization.k8s.io/v1beta1
|
||||||
|
kind: ClusterRoleBinding
|
||||||
|
metadata:
|
||||||
|
name: prometheus
|
||||||
|
roleRef:
|
||||||
|
apiGroup: rbac.authorization.k8s.io
|
||||||
|
kind: ClusterRole
|
||||||
|
name: prometheus
|
||||||
|
subjects:
|
||||||
|
- kind: ServiceAccount
|
||||||
|
name: prometheus
|
||||||
|
namespace: prom
|
||||||
|
---
|
||||||
|
apiVersion: monitoring.coreos.com/v1
|
||||||
|
kind: Prometheus
|
||||||
|
metadata:
|
||||||
|
name: prometheus
|
||||||
|
spec:
|
||||||
|
# Match all service monitors in all namespaces
|
||||||
|
serviceMonitorNamespaceSelector: {}
|
||||||
|
serviceMonitorSelector: {}
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
memory: 400Mi
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: prometheus
|
||||||
|
spec:
|
||||||
|
type: NodePort
|
||||||
|
ports:
|
||||||
|
- name: web
|
||||||
|
nodePort: 30900
|
||||||
|
port: 9090
|
||||||
|
protocol: TCP
|
||||||
|
targetPort: web
|
||||||
|
selector:
|
||||||
|
prometheus: prometheus
|
||||||
25
deploy/addepar/sample-hpa/Makefile
Normal file
25
deploy/addepar/sample-hpa/Makefile
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
sample-app:
|
||||||
|
kubectl create -n default -f sample-app.deploy.yaml
|
||||||
|
kubectl create -n default -f sample-app.service.yaml
|
||||||
|
|
||||||
|
delete-sample-app:
|
||||||
|
kubectl delete -n default -f sample-app.deploy.yaml
|
||||||
|
kubectl delete -n default -f sample-app.service.yaml
|
||||||
|
|
||||||
|
monitor:
|
||||||
|
kubectl create -n default -f service-monitor.yaml
|
||||||
|
|
||||||
|
hpa:
|
||||||
|
kubectl delete -f sample-app.hpa.yaml
|
||||||
|
kubectl create -f sample-app.hpa.yaml
|
||||||
|
|
||||||
|
test:
|
||||||
|
kubectl get --raw "/apis/custom.metrics.k8s.io/v1beta1/namespaces/default/pods/*/http_requests?selector=app%3Dsample-app"
|
||||||
|
|
||||||
|
get-ip:
|
||||||
|
kubectl get service sample-app -o jsonpath='{ .spec.clusterIP }'
|
||||||
|
|
||||||
|
busybox:
|
||||||
|
# run wget -qO- IP_ADDRESS
|
||||||
|
kubectl run -it --rm --restart=Never busybox --image=gcr.io/google-containers/busybox sh
|
||||||
|
|
||||||
22
deploy/addepar/sample-hpa/sample-app.deploy.yaml
Normal file
22
deploy/addepar/sample-hpa/sample-app.deploy.yaml
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: sample-app
|
||||||
|
labels:
|
||||||
|
app: sample-app
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: sample-app
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: sample-app
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- image: luxas/autoscale-demo:v0.1.2
|
||||||
|
name: metrics-provider
|
||||||
|
ports:
|
||||||
|
- name: http
|
||||||
|
containerPort: 8080
|
||||||
24
deploy/addepar/sample-hpa/sample-app.hpa.yaml
Normal file
24
deploy/addepar/sample-hpa/sample-app.hpa.yaml
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
kind: HorizontalPodAutoscaler
|
||||||
|
apiVersion: autoscaling/v2beta1
|
||||||
|
metadata:
|
||||||
|
name: sample-app
|
||||||
|
spec:
|
||||||
|
scaleTargetRef:
|
||||||
|
# point the HPA at the sample application
|
||||||
|
# you created above
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
name: sample-app
|
||||||
|
# autoscale between 1 and 10 replicas
|
||||||
|
minReplicas: 1
|
||||||
|
maxReplicas: 10
|
||||||
|
metrics:
|
||||||
|
# use a "Pods" metric, which takes the average of the
|
||||||
|
# given metric across all pods controlled by the autoscaling target
|
||||||
|
- type: Pods
|
||||||
|
pods:
|
||||||
|
# use the metric that you used above: pods/http_requests
|
||||||
|
metricName: http_requests
|
||||||
|
# target 500 milli-requests per second,
|
||||||
|
# which is 1 request every two seconds
|
||||||
|
targetAverageValue: 20m
|
||||||
15
deploy/addepar/sample-hpa/sample-app.service.yaml
Normal file
15
deploy/addepar/sample-hpa/sample-app.service.yaml
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: sample-app
|
||||||
|
name: sample-app
|
||||||
|
spec:
|
||||||
|
ports:
|
||||||
|
- name: http
|
||||||
|
port: 80
|
||||||
|
protocol: TCP
|
||||||
|
targetPort: 8080
|
||||||
|
selector:
|
||||||
|
app: sample-app
|
||||||
|
type: ClusterIP
|
||||||
12
deploy/addepar/sample-hpa/service-monitor.yaml
Normal file
12
deploy/addepar/sample-hpa/service-monitor.yaml
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
kind: ServiceMonitor
|
||||||
|
apiVersion: monitoring.coreos.com/v1
|
||||||
|
metadata:
|
||||||
|
name: sample-app
|
||||||
|
labels:
|
||||||
|
app: sample-app
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: sample-app
|
||||||
|
endpoints:
|
||||||
|
- port: http
|
||||||
|
|
@ -19,7 +19,8 @@ spec:
|
||||||
serviceAccountName: custom-metrics-apiserver
|
serviceAccountName: custom-metrics-apiserver
|
||||||
containers:
|
containers:
|
||||||
- name: custom-metrics-apiserver
|
- name: custom-metrics-apiserver
|
||||||
image: gcr.io/k8s-staging-prometheus-adapter-amd64
|
image: gcr.io/k8s-staging-prometheus-adapter/prometheus-adapter-amd64
|
||||||
|
imagePullPolicy: Never
|
||||||
args:
|
args:
|
||||||
- --secure-port=6443
|
- --secure-port=6443
|
||||||
- --tls-cert-file=/var/run/serving-cert/serving.crt
|
- --tls-cert-file=/var/run/serving-cert/serving.crt
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue