我在我的应用中添加了端点/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。
答案 0 :(得分:0)
我发现了这个问题,实际上这个问题与rbac有关。我没有在部署文件中添加serviceAccountName。现在它正在顺利进行新的改变。