drze7794 2017-11-18 22:02
浏览 37

如何从Kubernetes中的服务描述中导出端点IP-Go模板

i have a service runinig inside kubernetes, and i need to extract the exndpoint ip in environment variable

Here's the informations about the service

 kubectl get endpoints
NAME                ENDPOINTS                                                     AGE
kubernetes          10.0.2.15:8443                                                5h
locations-service   172.17.0.4:8080,172.17.0.5:8080,172.17.0.4:8081 + 1 more...   2h
mysql               172.17.0.7:3306                                               3h
phpmyadmin          172.17.0.6:80                                                 5h

How i can get the Endpoints value and export it to a variable? i tried the following but it's not working

export PORT=$(kubectl describe service  mysql -o go-template='{{range.spec.endpoints}}')
  • 写回答

1条回答 默认 最新

  • douyongwan5946 2017-11-19 21:42
    关注

    this will get the ip value of mysql service

     export PORT=$(kubectl get endpoints -o go-template='{{range.items}}{{if eq .metadata.name "mysql"}}{{(index (index .subsets 0).addresses 0).ip}}{{end}}{{end}}')
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?