[运维]2.elasticsearch-svc连接问题

Serverless 与容器决战在即?有了弹性伸缩就不一样了 - 阿里云云原生 - 博客园

当我部署好elasticsearch的服务后,由于个人习惯,一般服务会在name里带上svc,所以我elasticsearch服务的名字是elasticsearch-svc:

复制代码
[root@master ~]# kubectl get svc -n kube-logging31
NAME                TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)             AGE
elasticsearch-svc   ClusterIP   None          <none>        9200/TCP,9300/TCP   10h
kibana-svc          NodePort    10.105.0.72   <none>        5601:31231/TCP      14m

但是当我部署好elasticsearch和kibana后,发现kibana无法连接到elasticsearch,查看kibana pod的日志,发现如下报错:

复制代码
{"type":"log","@timestamp":"2024-10-02T13:24:30Z","tags":["warning","elasticsearch","admin"],"pid":1,"message":"No living connections"}
{"type":"log","@timestamp":"2024-10-02T13:24:30Z","tags":["warning","elasticsearch","admin"],"pid":1,"message":"Unable to revive connection: http://elasticsearch:9200/"}

这里说kibana试图连接到elasticsearch:9200。随后进入kibana的pod,进行验证:

复制代码
[root@master 31efk]# kubectl exec -it kibana-deploy-6bc6b7cd49-z7rzh -n kube-logging31 -- sh
sh-4.2$ curl -v http://elasticsearch-svc:9200
* About to connect() to elasticsearch-svc port 9200 (#0)
*   Trying 10.244.104.12...
* Connected to elasticsearch-svc (10.244.104.12) port 9200 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.29.0
> Host: elasticsearch-svc:9200
> Accept: */*
> 
< HTTP/1.1 200 OK
< content-type: application/json; charset=UTF-8
< content-length: 502
< 
{
  "name" : "es-cluster-2",
  "cluster_name" : "k8s-logs",
  "cluster_uuid" : "mgDmrtT-TGucWXpj7CkakQ",
  "version" : {
    "number" : "7.2.0",
    "build_flavor" : "default",
    "build_type" : "docker",
    "build_hash" : "508c38a",
    "build_date" : "2019-06-20T15:54:18.811730Z",
    "build_snapshot" : false,
    "lucene_version" : "8.0.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}
* Connection #0 to host elasticsearch-svc left intact
sh-4.2$ exit
exit

发现在kibana内部可以成功解析elasticsearch-svc。

定位到问题可能是kibana的默认elasticsearch服务的配置是elasticsearch:9200。

复制代码
[root@master 31efk]# kubectl exec -it kibana-deploy-6bc6b7cd49-z7rzh -n kube-logging31 -- cat /usr/share/kibana/config/kibana.yml
#
# ** THIS IS AN AUTO-GENERATED FILE **
#

# Default Kibana configuration for docker target
server.name: kibana
server.host: "0"
elasticsearch.hosts: [ "http://elasticsearch:9200" ]

可以看到默认的hosts就是 [ "http://elasticsearch:9200" ]。

所以解决办法是,在kibana的deployment文件里增加下面环境变量(一开始只有ELASTICSEARCH_URL)

复制代码
env:
  - name: ELASTICSEARCH_HOSTS
    value: "http://elasticsearch-svc:9200"
相关推荐
abigriver8 小时前
打造 Linux 离线大模型级语音输入法:Whisper.cpp + 3090 显卡加速与 Rime 中英混输终极调优指南
linux·运维·whisper
阿星AI工作室8 小时前
刘润年中大课笔记:一句话说清AI落地之战的本质
大数据·人工智能·创业创新·商业
charlie1145141919 小时前
嵌入式Linux驱动开发pinctrl篇(1)——从寄存器到子系统:驱动演进之路
linux·运维·驱动开发
Agent手记10 小时前
异常考勤智能预警与处理与流程优化方案 | 基于企业级Agent的超自动化实战教程
运维·人工智能·ai·自动化
cen__y10 小时前
Linux12(Git01)
linux·运维·服务器·c语言·开发语言·git
不仙52011 小时前
VMware Workstation 26.0.0 在 Ubuntu 24.04 (内核 6.17.0) 上的安装与内核模块编译问题
linux·ubuntu·elasticsearch
1892280486112 小时前
NY352固态MT29F32T08GWLBHD6-24QJ:B
大数据·服务器·人工智能·科技·缓存
dapeng-大鹏12 小时前
KVM+LVM 零停机在线扩容 Ubuntu 根分区:从磁盘添加到逻辑卷扩展完整
linux·运维·ubuntu·磁盘空间扩展
不开大的凯207712 小时前
麦当秀AiPPT战略转向:从SaaS订阅迈向Token经济,AI办公定价模式迎来新探索
大数据·人工智能
乐维_lwops12 小时前
案例解读|运维监控助力某大型卷烟厂构建高效运维监控体系
运维·运维案例