Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Introduction to the method of calling Rancher-API under Kubernetes

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

这篇文章主要介绍"Kubernetes下Rancher-API调用方法介绍",在日常操作中,相信很多人在Kubernetes下Rancher-API调用方法介绍问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答"Kubernetes下Rancher-API调用方法介绍"的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

基础信息

基础信息,需要另外方式获取 (目前是在rancher浏览器中截取下的信息;系统对接,需要在rancher登录时获取并保存)

export RANCHER_HOST="Rancher Server 部署的 IP"export R_USERNAME="admin"export R_SESS="token-x5jrv:xs5ckr9nv25bpcpcsw5wt8wrmhr2mjgp9zzz98jcw7vhqqkrbz4tcc"export cookie="R_USERNAME=${R_USERNAME}; R_SESS=${R_SESS}"登录 login curl http://${RANCHER_HOST}/v3-public/localProviders/local?action=login -k POST数据如下: {"username":"${R_USERNAME}","password":"${PASSWORD}","description":"UI Session","responseType":"cookie","ttl":57600000,"labels":{"ui-session":"true"}}

当验证通过时,返回

httpcode=200 header字段,取出 R_SESS 备用: Set-Cookie: R_SESS=token-knjhs:cc5mgzxs8nnpl9vdjbj8fzg68jl4dnhj74l96ktp5n2jr9xbwdppm6; Path=/; HttpOnly; Secure

当验证失败时,返回

httpcode=401 data内容,{"baseType":"error","code":"Unauthorized","message":"authentication failed","status":401,"type":"error"}apiRoot

以下所有模块的基本地址(apiRoot)

curl http://${RANCHER_HOST}/v3 -L -k --cookie "${cookie}"

具体要访问资源的地址,在返回的 links 段中获取

接口太多,以下列表不全,只做示范

资源:token

获取token基本信息和操作入口:

curl http://${RANCHER_HOST}/v3/tokens -L -k --cookie "${cookie}"

返回

正常数据,或无权限时如下 {"type":"error","status":"401","message":"must authenticate"}

authProvider:

curl http://${RANCHER_HOST}/v3/tokens?sort=authProvider -L -k --cookie "${cookie}"

tokens/helm-token-user-xtmvc:

curl http://${RANCHER_HOST}/v3/tokens/helm-token-user-xtmvc -L -k --cookie "${cookie}"资源:node

获取节点基本信息和操作入口:

curl http://${RANCHER_HOST}/v3/nodes -L -k --cookie "${cookie}"资源:clusters

获取集群基本信息和操作入口:

curl http://${RANCHER_HOST}/v3/clusters -L -k --cookie "${cookie}"版本变化API

v2.x相较于v1.6,api和api实现有较大变化 (sad,更封闭了~.~)

API v1.6的websocket接口被去掉,参看 v1.6说明 末尾一段websocket部分。 对比看 v2.x说明 (websocket部分已被删去)

gitee 上有个 rancher-exporter 项目在新版上应该不可用了(anyway,项目本身好像也缺少维护,反正没编译成功 ( ╯□╰ ))

API实现 v1.6基于 go-rancher 项目 v2.x基于 types 项目,其又依赖 norman 项目

到此,关于"Kubernetes下Rancher-API调用方法介绍"的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注网站,小编会继续努力为大家带来更多实用的文章!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report