gpt4 book ai didi

annotations - Kubernetes/Prometheus - 无法在服务文件中注释

转载 作者:行者123 更新时间:2023-12-04 03:56:21 24 4
gpt4 key购买 nike

我的 Kubernetes 版本是:

# kubectl --version
Kubernetes v1.4.0

我打算使用 Prometheus 来监控我的 Kube 集群。为此,我需要对指标 URL 进行注释。

我当前的指标 URL 是这样的:

http://172.16.33.7:8080/metrics

但我希望它是这样的:

http://172.16.33.7:8080/websocket/metrics

首先我尝试手动执行此操作::

kubectl annotate pods websocket-backend-controller-db83999c5b534b277b82badf6c152cb9m1 prometheus.io/path=/websocket/metrics
kubectl annotate pods websocket-backend-controller-db83999c5b534b277b82badf6c152cb9m1 prometheus.io/scrape='true'
kubectl annotate pods websocket-backend-controller-db83999c5b534b277b82badf6c152cb9m1 prometheus.io/port='8080'

所有这些命令都可以正常工作,我可以看到注释。

{
"metadata": {
"name": "websocket-backend-controller-v1krf",
"generateName": "websocket-backend-controller-",
"namespace": "default",
"selfLink": "/api/v1/namespaces/default/pods/websocket-backend-controller-v1krf",
"uid": "e323994b-4081-11e7-8bd0-0050569b6f44",
"resourceVersion": "27534379",
"creationTimestamp": "2017-05-24T13:07:06Z",
"labels": {
"name": "websocket-backend"
},
"annotations": {
"kubernetes.io/created-by": "{\"kind\":\"SerializedReference\",\"apiVersion\":\"v1\",\"reference\":{\"kind\":\"ReplicationController\",\"namespace\":\"default\",\"name\":\"websocket-backend-controller\",\"uid\":\"e321f1a8-4081-11e7-8bd0-0050569b6f44\",\"apiVersion\":\"v1\",\"resourceVersion\":\"27531840\"}}\n",
"prometheus.io/path": "/websocket/metrics",
"prometheus.io/port": "8080",
"prometheus.io/scrape": "true"
}

但由于我希望此配置保持不变,因此我在我的服务文件中设置了以下注释。

# cat websocket-service.yaml 
apiVersion: v1
kind: Service
metadata:
name: websocket-service
labels:
baseApi: websocket
annotations:
prometheus.io/scrape: 'true'
prometheus.io/path: /websocket/metrics
prometheus.io/port: '8080'
spec:
selector:
name: websocket-backend
ports:
- port: 8080
targetPort: 8080
nodePort: 30800
protocol: TCP
type: NodePort
clusterIP: 10.100.10.45

我重新启动了我的 websocket 服务和相应的 pod,但这些配置似乎没有生效。

kubectl create -f websocket-service.yaml
kubectl create -f ../controllers/websocket-replication-controller.yaml

结果没有显示配置的注解。

{
"metadata": {
"name": "websocket-backend-controller-v1krf",
"generateName": "websocket-backend-controller-",
"namespace": "default",
"selfLink": "/api/v1/namespaces/default/pods/websocket-backend-controller-v1krf",
"uid": "e323994b-4081-11e7-8bd0-0050569b6f44",
"resourceVersion": "27531879",
"creationTimestamp": "2017-05-24T13:07:06Z",
"labels": {
"name": "websocket-backend"
},
"annotations": {
"kubernetes.io/created-by": "{\"kind\":\"SerializedReference\",\"apiVersion\":\"v1\",\"reference\":{\"kind\":\"ReplicationController\",\"namespace\":\"default\",\"name\":\"websocket-backend-controller\",\"uid\":\"e321f1a8-4081-11e7-8bd0-0050569b6f44\",\"apiVersion\":\"v1\",\"resourceVersion\":\"27531840\"}}\n"
}

我所做的不是使用命令行,而是使用服务配置设置配置,但它似乎不起作用。

最佳答案

如果您对服务进行注释,它不会对可能匹配的 pod 产生任何影响。您的 pod 由 ReplicationController 或通过 ReplicaSet/Deployment 管理。在这种情况下,注释这些资源以使注释到达 pod。在部署示例中,您必须使用模板部分,例如:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
# Unique key of the Deployment instance
name: deployment-example
spec:
# 3 Pods should exist at all times.
replicas: 3
# Keep record of 2 revisions for rollback
revisionHistoryLimit: 2
template:
metadata:
annotations:
prometheus.io/scrape: 'true'
prometheus.io/path: /websocket/metrics
prometheus.io/port: '8080'

关于annotations - Kubernetes/Prometheus - 无法在服务文件中注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44159808/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com