共计 2352 个字符,预计需要花费 6 分钟才能阅读完成。
在 prometheus-prometheus.yaml 减少 thanos 的配置当前:
thanos:
image: thanosio/thanos:v0.18.0
objectStorageConfig:
key: thanos.yaml
name: thanos-objstore-config
prometheus-operator 做了上面的事件:
- 创立一个 thanos 的 container 作为 prometheus 的 sidecar;
- 为 prometheus service 减少了 1 个 grpc 端口:10901;
创立 thanos sidecar
# kubectl describe pod prometheus-k8s-0 -n monitoring
Name: prometheus-k8s-0
Namespace: monitoring
Containers:
......
thanos-sidecar:
Container ID: docker://e5d123d91752f941b9081d553ce49361154c0a26f9dc7c46dc7975b709575285
Image: thanosio/thanos:v0.18.0
Image ID: docker-pullable://thanosio/thanos@sha256:b94171aed499b2f1f81b6d3d385e0eeeca885044c59cef28ce6a9a9e8a827217
Ports: 10902/TCP, 10901/TCP
Host Ports: 0/TCP, 0/TCP
Args:
sidecar
--prometheus.url=http://localhost:9090/
--tsdb.path=/prometheus
--grpc-address=[$(POD_IP)]:10901
--http-address=[$(POD_IP)]:10902
--objstore.config=$(OBJSTORE_CONFIG)
State: Running
Started: Sun, 04 Jul 2021 17:35:11 +0800
......
创立 sidecar container 的代码在 prometheus-operator 中:
// pkg/prometheus/statefulset.go
func makeStatefulSetSpec(p monitoringv1.Prometheus, c *Config, ruleConfigMapNames []string) (*appsv1.StatefulSetSpec, error) {
......
if p.Spec.Thanos != nil {
....
container := v1.Container{
Name: "thanos-sidecar",
Image: thanosImage,
TerminationMessagePolicy: v1.TerminationMessageFallbackToLogsOnError,
Args: thanosArgs,
Env: []v1.EnvVar{
{
Name: "POD_IP",
ValueFrom: &v1.EnvVarSource{
FieldRef: &v1.ObjectFieldSelector{FieldPath: "status.podIP",},
},
},
},
Ports: []v1.ContainerPort{
{
Name: "http",
ContainerPort: 10902,
},
{
Name: "grpc",
ContainerPort: 10901,
},
},
VolumeMounts: []v1.VolumeMount{
{
Name: volName,
MountPath: storageDir,
SubPath: subPathForStorage(p.Spec.Storage),
},
},
Resources: p.Spec.Thanos.Resources,
}
}
}
减少 grpc 端口
减少 prometheus-operator grpc 端口的代码:
// pkg/prometheus/statefulset.go
func makeStatefulSetService(p *monitoringv1.Prometheus, config Config) *v1.Service {p = p.DeepCopy()
if p.Spec.PortName == "" {p.Spec.PortName = defaultPortName}
svc := &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: governingServiceName,
Labels: config.Labels.Merge(map[string]string{"operated-prometheus": "true",}),
},
Spec: v1.ServiceSpec{
ClusterIP: "None",
Ports: []v1.ServicePort{
{
Name: p.Spec.PortName,
Port: 9090,
TargetPort: intstr.FromString(p.Spec.PortName),
},
},
Selector: map[string]string{"app": "prometheus",},
},
}
if p.Spec.Thanos != nil {
svc.Spec.Ports = append(svc.Spec.Ports, v1.ServicePort{
Name: "grpc",
Port: 10901,
TargetPort: intstr.FromString("grpc"),
})
}
return svc
}
能够看到 10901 的端口是 hardcoding 在代码中的。
正文完