[运维]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"
相关推荐
程序员-Benothing10 小时前
Vim编辑器从入门到精通:模式、快捷键、配置、插件
linux·运维·服务器
Leo.yuan10 小时前
2026年实时数据同步工具怎么选?GoldenGate、Striim、SeaTunnel、FineDataLink 5.0横评
大数据
sm_9267870510 小时前
RFID 标签打印的技术实现要点与二次开发实践
java·大数据·前端·c++·编辑器
龙亘川10 小时前
AI 协同赋能城市治理:支撑政协数字化履职的技术路径探析
大数据·人工智能·智慧城市·开源软件·数据可视化
m0_6464299710 小时前
Docker 完整核心知识点总结(超通俗易懂版)
运维·docker·容器
逸模10 小时前
BIM在连锁餐饮装修中的应用:不只是画三维图
大数据·数据库·人工智能·物联网·建模
亚川楼宇自控系统数据中心厂家11 小时前
IBMS 集成管理系统:如何打通楼宇自控实现建筑一体化管控
运维
迪康Defender11 小时前
终端安全审批体系设计:如何平衡安全管控与业务连续性
运维·服务器·安全·运维开发·学习方法·业界资讯·远程工作
liliangcsdn11 小时前
Deepseek R1与V4 Pro参数量对比
大数据
不开大的凯207712 小时前
AI权力游戏:同一天,两种答案,一场算力暗战
大数据·人工智能·ai·ai office