[英]A sample containerized application in Kubernetes unable to be shown as targets in Prometheus for scraping metrics
[英]prometheus is not scraping the metrics from the app deployed on kubernetes
我在我的應用程序中添加了端點/metrics
,這是我為 prometheus 編寫的配置文件
kind: ConfigMap
metadata:
name: prometheus-config
apiVersion: v1
data:
prometheus.yml: |-
global:
scrape_interval: 5s
evaluation_interval: 5s
scrape_configs:
- job_name: 'goserver'
scheme: http
tls_config:
ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
kubernetes_sd_configs:
- api_server: https://kubernets.default.svc
role: pod
relabel_configs:
- source_labels: [__meta_kubernetes_pod_label_app]
regex: goserver
action: keep
- source_labels: [__meta_kubernetes_pod_name]
target_label: k8s_pod
action: replace
下面是部署文件
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: prometheus-deployment
spec:
replicas: 1
template:
metadata:
labels:
app: prometheus-server
spec:
containers:
- name: prometheus
image: prom/prometheus:latest
args:
- "-config.file=/etc/prometheus/conf/prometheus.yml"
# Metrics are stored in an emptyDir volume which
# exists as long as the Pod is running on that Node.
# The data in an emptyDir volume is safe across container crashes.
- "-storage.local.path=/prometheus"
ports:
- containerPort: 9090
volumeMounts:
- name: prometheus-server-volume
mountPath: /etc/prometheus/conf
- name: prometheus-storage-volume
mountPath: /prometheus
volumes:
- name: prometheus-server-volume
configMap:
name: prometheus-config
- name: prometheus-storage-volume
emptyDir: {} # containers in the Pod can all read and write the same files here.
這是應用程序的部署文件
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: server-deployment
namespace: default
spec:
replicas: 1
template:
metadata:
labels:
app: goserver
spec:
containers:
- name: goserver
imagePullPolicy: Always
image: utkarshmani1997/goserver:v1.4
ports:
- containerPort: 8080
我已經分別在 NodePort 類型的端口 32514 和 32520 上創建了 prometheus 和 goserver 的服務。 這是工作的罰款與minikube和我的應用程序刮的指標,但不與虛框(多節點集群)的kubeadm設置工作。 為了獲得 kubernetes 的指標,我必須進行哪些更改。 我也嘗試對rbac-setup.yaml和prometheus-kubernetes.yaml進行一些更改,但它不起作用。
我正在通過 ssh -NL 1234:localhost:32514 從集群外部訪問瀏覽器,因為 vagrant box 沒有 ubuntu 桌面 ui。
我發現了這個問題,實際上這個問題與 rbac 有關。 我沒有在部署文件中添加 serviceAccountName。 現在它在新的變化下工作正常。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.