问题描述
我是Prometheus的新手,而Kubernetes则相对较新,所以请多多包涵。我正在尝试测试Prometheus,并尝试了两种不同的方法。
-
在kubernetes外部将Prometheus作为docker容器运行。为此,我创建了这个Dockerfile:
FROM prom / prometheus
添加prometheus.yml / etc / prometheus /
和这个Yaml文件:
global:
scrape_interval:15s
external_labels:
monitor:'codelab-monitor'
scrape_configs:
-job_name:'kubernetes- apiserver的
方案: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:本地主机:443
当我运行此命令时,我得到:
未能列出* v1.Pod:获取http :// localhost:443 / api / v1 / pods?limit = 500& resourceVersion = 0:拨打tcp 127.0.0.1:443:连接:连接被拒绝
无法列出* v1。服务:获取http:/ / localhost:443 / api / v1 / pods?limit = 500& resourceVersion = 0:拨打tcp 127.0.0.1:443:连接:连接被拒绝
无法列出* v1。端点:获取http:// localhost:443 / api / v1 / pods?limit = 500& resourceVersion = 0:拨打tcp 127.0。 0.1:443:connect:连接被拒绝
循环执行。当我转到localhost:9090时,Prometheus将加载,但是没有数据。并部署了它。
种类:部署
apiVersion:extensions / v1beta1
元数据:
名称:prometheus-monitor
规范:
选择器:
matchLabel:
应用程序:prometheus
模板:
元数据:
标签:
应用程序:prometheus
规范:
容器:
-名称:prometheus-monitor
图片:prom / prometheus
#args:
#-' -config.file = / etc / prometheus / prometheus.yaml'
imagePullPolicy:IfNotPresent
端口:
-名称:webui
containerPort:9090
部署成功,但是如果我转至localhost:9090,则会得到 ERR_SOCKET_NOT_CONNECTED。 (我的端口已转发)
任何人都可以告诉我in进出vs Kubernetes的优势以及如何解决这些问题中至少有一个?
此外,我的配置文件被抑制了,因为它给出了错误,一旦能够加载Prometheus,我将进行调查。
在部署容器时,Kubernetes不会在群集的外部映射端口。
您还必须创建一个服务(可以在同一文件中),以使其可从您的工作站使用(将其添加到prometheus yaml):
---
api版本:v1
类型:Service
元数据:
名称:prometheus-web
标签:
应用程序:prometheus
规范:
类型:NodePort
端口:
-端口:9090
协议:TCP
targetPort:9090
nodePort:30090
名称:webui
选择器:
应用:Prometheus
NodePort在您拥有的所有节点上打开给定的端口。您应该可以看到
的前端
默认情况下,kubernetes允许端口30000至32767用于NodePort类型()。
请考虑阅读以下文档:有关kubernetes中服务的更多信息的常规信息:
I am new to Prometheus and relatively new to kubernetes so bear with me, please. I am trying to test Prometheus out and have tried two different approaches.
Run Prometheus as a docker container outside of kubernetes. To accomplish this I have created this Dockerfile:
FROM prom/prometheus ADD prometheus.yml /etc/prometheus/
and this yaml file:
global: scrape_interval: 15s external_labels: monitor: 'codelab-monitor' scrape_configs: - job_name: 'kubernetes-apiservers' 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: - role: endpoints api_server: localhost:443
When I run this I get:
Failed to list *v1.Pod: Get http://localhost:443/api/v1/pods?limit=500&resourceVersion=0: dial tcp 127.0.0.1:443: connect: connection refused" Failed to list *v1.Service: Get http://localhost:443/api/v1/pods?limit=500&resourceVersion=0: dial tcp 127.0.0.1:443: connect: connection refused" Failed to list *v1.Endpoints: Get http://localhost:443/api/v1/pods?limit=500&resourceVersion=0: dial tcp 127.0.0.1:443: connect: connection refused"
on a loop. Prometheus will load when I go to localhost:9090 but there is no data.
I thought deploying Prometheus as a Kubernetes deployment may help, so I made this yaml and deployed it.
kind: Deployment apiVersion: extensions/v1beta1 metadata: name: prometheus-monitor spec: selector: matchLabels: app: prometheus template: metadata: labels: app: prometheus spec: containers: - name: prometheus-monitor image: prom/prometheus # args: # - '-config.file=/etc/prometheus/prometheus.yaml' imagePullPolicy: IfNotPresent ports: - name: webui containerPort: 9090
The deployment was successful, but if I go to localhost:9090 I get 'ERR_SOCKET_NOT_CONNECTED'. (my port is forwarded)
Can anyone tell me the advantage of in vs out of Kubernetes and how to fix at least one of these issues?
Also, my config file is suppressed because it was giving an error, and I will look into that once I am able to get Prometheus loaded.
Kubernetes does not map the port outside it's cluster when you deploy your container.
You also have to create a service (can be inside the same file) to make it available from your workstation (append this to your prometheus yaml):
---
apiVersion: v1
kind: Service
metadata:
name: prometheus-web
labels:
app: prometheus
spec:
type: NodePort
ports:
- port: 9090
protocol: TCP
targetPort: 9090
nodePort: 30090
name: webui
selector:
app: prometheus
NodePort opens the given port on all nodes you have. You should be able to see the frontend with http://localhost:30090/
Per default, kubernetes allow ports 30000 to 32767 for NodePort type (https://kubernetes.io/docs/concepts/services-networking/service/#nodeport).
Please consider reading the documentation in general for more information on services in kubernetes: https://kubernetes.io/docs/concepts/services-networking/service/
这篇关于“连接:拒绝连接”。将Prometheus连接到Kubernetes时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!