restful api访问k8s集群,增删改 查信息,做界面二次开发。

需要预先创建访问权限的配置。

下面罗列部分api

curl -u admin:admin "https://localhost:6443/api/v1" -k

curl -u admin:admin "https://localhost:6443/api/v1/pods" -k

curl -u admin:admin "https://localhost:6443/api/v1/namespaces/{namespace}/pods" -k

curl -u admin:admin "https://localhost:6443/api/v1/namespaces/default/pods" -k

获取节点信息

curl -u admin:admin "https://localhost:6443/api/v1/nodes/{nodename}" -k

curl -u admin:admin "https://localhost:6443/api/v1/nodes/tensorflow1" -k

...

"status": {

"capacity": {

"cpu": "4",

"memory": "7970316Ki",

"pods": "110"

},

"allocatable": {

"cpu": "4",

"memory": "7867916Ki",

"pods": "110"

},

...

获取namespace信息

curl -u admin:admin "https://localhost:6443/api/v1/namespaces/{namespace}" -k

curl -u admin:admin "https://localhost:6443/api/v1/namespaces/default" -k

获得quota信息

curl -u admin:admin "https://localhost:6443/api/v1/namespaces/{namespace}/resourcequotas/" -k

curl -u admin:admin "https://localhost:6443/api/v1/namespaces/default/resourcequotas/" -k

实践

k8s_master_ip:192.168.1.138

username 不同用户不同

password 不同用户不同

namespace 不同用户不同

查看容器

curl -u {username}:{password} "https://{k8s_master_ip}:6443/api/v1/namespaces/{namespace}/pods/" -k

curl -u admin:admin "https://192.168.1.138:6443/api/v1/namespaces/default/pods/" -k

看起来像是把所有的pod都拿出来了,包括活的和死的。

看了一下信息很多不过没有资源使用信息。

"phase": "Running"

这个是正在运行的pod

"phase": "Failed"

"reason":"Evicted"

这种是删除了的,状态是failed 原因是被驱逐

增加continue参数取出正在运行的容器

curl -u {username}:{password} "https://{k8s_master_ip}:6443/api/v1/namespaces/{namespace}/pods?continue" -k

curl -u admin:admin "https://192.168.1.138:6443/api/v1/namespaces/default/pods?continue" -k

查看replicationcontroller

curl -u admin:admin "https://192.168.1.138:6443/api/v1/namespaces/user1/replicationcontrollers/" -k

查看service

curl -u admin:admin "https://192.168.1.138:6443/api/v1/namespaces/user1/services/" -k

查看资源总览resourcequotas

curl -u {username}:{password} "https://{k8s_master_ip}:6443/api/v1/namespaces/{namespace}/resourcequotas/" -k

[root@tensorflow1 info]# curl -u admin:admin "https://localhost:6443/api/v1/namespaces/default/resourcequotas/" -k

...

"status": {

"hard": {

"limits.cpu": "2",

"limits.memory": "6Gi",

"pods": "20",

"requests.cpu": "1",

"requests.memory": "1Gi"

},

"used": {

"limits.cpu": "400m",

"limits.memory": "1Gi",

"pods": "2",

"requests.cpu": "200m",

"requests.memory": "512Mi"

}

}

...

hard是限额   used是当前申请的限额

limits 和 requests 的区别是 limits是上限,不能突破,但不保证能给。 requests是下限,保证能给。 举例说明:一个容器 requests.memory 512Mi,limits.memory 1Gi。宿主机内存使用量高时,一定会留512Mi内存给这个容器,不一定能拿到1Gi内存。宿主机内存使用量低时,容器不能突破1Gi内存。

Gi 和 G 的区别是 Gi是1024进制,G是1000进制,M Mi也是同理。就像一个U盘8G但实际能使用的是7.45G(其实这里单位就是Gi)

pods是指容器,单位个

cpu单位 m指千分之一,200m即0.2个cpu。这是绝对值,不是相对值。比如0.1CPU不管是在单核或者多核机器上都是一样的,都严格等于0.1CPU core

实时数据

下载 metrics-server 压缩包文件

下载 googlecontainer/metrics-server-amd64:v0.2.0

cd metrics-server-0.2.1/deploy

修改 metrics-server-deployment.yaml 文件 image 和 imagePullPolicy: IfNotPresent

kubectl create -f .

获取节点信息

curl -u {username}:{password} "https://{k8s_master_ip}:6443/apis/metrics.k8s.io/v1beta1/nodes" -k

curl -u admin:admin "https://192.168.1.138:6443/apis/metrics.k8s.io/v1beta1/nodes" -k

{

"kind": "NodeMetricsList",

"apiVersion": "metrics.k8s.io/v1beta1",

"metadata": {

"selfLink": "/apis/metrics.k8s.io/v1beta1/nodes"

},

"items": [

...

{

"metadata": {

"name": "tensorflow1",

"selfLink": "/apis/metrics.k8s.io/v1beta1/nodes/tensorflow1",

"creationTimestamp": "2018-04-09T08:44:17Z"

},

"timestamp": "2018-04-09T08:44:00Z",

"window": "1m0s",

"usage": {

"cpu": "265m",

"memory": "3448228Ki"

}

}

...

]

}

获取pod信息

curl -u {username}:{password} "https://{k8s_master_ip}:6443/apis/metrics.k8s.io/v1beta1/namespaces/{namespace}/pods" -k

curl -u admin:admin "https://192.168.1.138:6443/apis/metrics.k8s.io/v1beta1/namespaces/default/pods" -k

{

"kind": "PodMetricsList",

"apiVersion": "metrics.k8s.io/v1beta1",

"metadata": {

"selfLink": "/apis/metrics.k8s.io/v1beta1/namespaces/default/pods"

},

"items": [

...

{

"metadata": {

"name": "tensorflow-worker-rc-998wf",

"namespace": "default",

"selfLink": "/apis/metrics.k8s.io/v1beta1/namespaces/default/pods/tensorflow-worker-rc-998wf",

"creationTimestamp": "2018-04-09T08:52:38Z"

},

"timestamp": "2018-04-09T08:52:00Z",

"window": "1m0s",

"containers": [

{

"name": "worker",

"usage": {

"cpu": "0",

"memory": "39964Ki"

}

}

]

}

...

]

}

获取namespace信息

没找到url,就把上面获取pod的使用量全加起来就是namespace的使用量了

Metrics API 文档

网上找不到文档 只能从 kubectl top 命令帮助里找

[root@tensorflow1 ~]# kubectl top

Display Resource (CPU/Memory/Storage) usage.

The top command allows you to see the resource consumption for nodes or pods.

This command requires Heapster to be correctly configured and working on the server.

Available Commands:

node Display Resource (CPU/Memory/Storage) usage of nodes

pod Display Resource (CPU/Memory/Storage) usage of pods

Usage:

kubectl top [options]

Use "kubectl --help" for more information about a given command.

Use "kubectl options" for a list of global command-line options (applies to all commands).

[root@tensorflow1 ~]# kubectl top pod --help

Display Resource (CPU/Memory/Storage) usage of pods.

The 'top pod' command allows you to see the resource consumption of pods.

Due to the metrics pipeline delay, they may be unavailable for a few minutes since pod creation.

Aliases:

pod, pods, po

Examples:

# Show metrics for all pods in the default namespace

kubectl top pod

# Show metrics for all pods in the given namespace

kubectl top pod --namespace=NAMESPACE

# Show metrics for a given pod and its containers

kubectl top pod POD_NAME --containers

# Show metrics for the pods defined by label name=myLabel

kubectl top pod -l name=myLabel

Options:

--all-namespaces=false: If present, list the requested object(s) across all namespaces. Namespace in current

context is ignored even if specified with --namespace.

--containers=false: If present, print usage of containers within a pod.

--heapster-namespace='kube-system': Namespace Heapster service is located in

--heapster-port='': Port name in service to use

--heapster-scheme='http': Scheme (http or https) to connect to Heapster as

--heapster-service='heapster': Name of Heapster service

-l, --selector='': Selector (label query) to filter on, supports '=', '==', and '!='.(e.g. -l key1=value1,key2=value2)

Usage:

kubectl top pod [NAME | -l label] [options]

Use "kubectl options" for a list of global command-line options (applies to all commands).

获取heapster url

[root@tensorflow1 influxdb]kubectl cluster-info

Kubernetes master is running at https://192.168.1.138:6443

Heapster is running at https://192.168.1.138:6443/api/v1/namespaces/kube-system/services/heapster/proxy

KubeDNS is running at https://192.168.1.138:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

monitoring-grafana is running at https://192.168.1.138:6443/api/v1/namespaces/kube-system/services/monitoring-grafana/proxy

monitoring-influxdb is running at https://192.168.1.138:6443/api/v1/namespaces/kube-system/services/monitoring-influxdb/proxy

curl -u admin:admin "https://192.168.1.138:6443/api/v1/namespaces/kube-system/services/heapster/proxy/api/v1/model/namespaces/" -k

curl -u admin:admin "https://192.168.1.138:6443/api/v1/namespaces/kube-system/services/heapster/proxy/api/v1/model/namespaces/default/metrics" -k

[

"memory/request",

"memory/limit",

"cpu/usage_rate",

"memory/usage",

"cpu/request",

"cpu/limit"

]

[root@tensorflow1 influxdb]# curl -u admin:admin "https://192.168.1.138:6443/api/v1/namespaces/kube-system/services/heapster/proxy/api/v1/model/namespaces/default/metrics/memory/usage" -k

{

"metrics": [

...

{

"timestamp": "2018-04-09T07:45:00Z",

"value": 81121280

},

{

"timestamp": "2018-04-09T07:46:00Z",

"value": 81121280

}

...

],

"latestTimestamp": "2018-04-09T07:46:00Z"

}

api k8s restful 创建pods_k8s restful api 访问-阿里云开发者社区相关推荐

  1. mysql slave是什么_创建slave的搜索结果-阿里云开发者社区

    Rainbond部署Mysql主从集群应用说明 Mysql主从同步原理 1)在Slave 服务器上执行sart slave命令开启主从复制开关,开始进行主从复制. 2)此时,Slave服务器的IO线程 ...

  2. python刷新cdn_api 刷新是什么-和api 刷新相关的问题-阿里云开发者社区

    关于 api 刷新的搜索结果 回答 详细解答可以参考官方帮助文档 登陆CDN控制台,单击 刷新,进行刷新配置. URL刷新 原理:通过提供文件URL的方式,强制CDN节点回源拉取最新的文件. 任务生效 ...

  3. mysql注册slave_创建slave库?spm=a2c4e.11155472的搜索结果-阿里云开发者社区

    云原生必备知识: 应用储存 所属技术领域: 云原生 | 名词定义 | 由于容器本身是非持久化的,因此需要解决在容器中运行应用程序遇到的一些问题.首先,当容器崩溃时,kubelet将重新启动容器,但是写 ...

  4. api报错 javaee maven_maven test 换javaee6 无法加载spring的配置文件 ?报错-问答-阿里云开发者社区-阿里云...

    maven 构建的springmvc项目,执行mvn test 时 如果是 org.apache.openejb javaee-api 5.0-3 那么执行test可以通过 如果将version改为6 ...

  5. k8s灰度更新_k8s slb如何实现灰度发布-问答-阿里云开发者社区-阿里云

    首先需要制作此次实验的基础镜像: 1. Dockerfile的编写: mkdir dockerfile && cd dockerfile vim Dockerfile #注意: Doc ...

  6. 阿里云mysql创建用户_mysql创建用户-阿里云开发者社区

    创建用于localhost连接的用户并指定密码 mysql> create user'pcom'@'localhost'identified by'aaa7B2249'; Query OK,0r ...

  7. python场景建立_Python创建一个街道地址表-问答-阿里云开发者社区-阿里云

    首先,你应该转换givenNumber成int()因为input()总是返回字符串.此外,您可以将整体strAddress转换为自身并反转自身版本,以便更轻松地访问它.splitAddress这里不需 ...

  8. bapi sap 创建物料_SAP使用BAPI创建物料主数据的最小输入-阿里云开发者社区

    BASIC_VIEW 基本数据视图 标志 MATNR 物料编码 MAKTX 物料描述 MEINS 单位 MTART 物料类型 MBRSH 行业领域 调用BAPI CALL FUNCTION 'BAPI ...

  9. mysql 接口访问_MySQL的数据库访问接口-阿里云开发者社区

    大部分流行的关系数据库产品采用的都是 C/S 架构.因此,应用程序要访问数据库的数据就必须和各种数据库客户端(也称为数据库访问接口)打交道.可以这么认为,每一种流行的编程语言都需要一个对应的数据库访问 ...

最新文章

  1. java时间操作方法Calendar
  2. 如何衡量RFID技术在仓库中的价值?
  3. 微信公众号开发之准备工作
  4. linux sftp没有读写权限,sftp服务器上的Linux权限问题
  5. SQL Server安装问题 mof 编译器无法连接到wmi服务器 不能在控件上调用Invoke或 BeginInvoke...
  6. CSS设置无需表格的菜单
  7. 学习笔记-------Seate解决分布式事务
  8. linux加入微软,微软正式加入Linux基金会
  9. python-知识回顾-16
  10. Spring源码之ApplicationContext(十)过程刷新
  11. Windows 之间用rsync同步数据(cwRsyncServer配置)
  12. OneNET麒麟座应用开发之五:获取加速度传感器ADXL345数据
  13. IntelliJ IDEA安装lombok
  14. 从零学习AI安全监控项目【附详细代码】
  15. 办理北京市工作居住证攻略
  16. spring框架之IoC理解
  17. 名帖111 董其昌 小楷《千字文》
  18. c语言单链表的创建(头插法和尾插法)
  19. 戴尔服务器T30不读硬盘,【戴尔 POWEREDGE T30服务器开箱展示】硬盘|散热|机箱|内存_摘要频道_什么值得买...
  20. sim卡没坏但苹果手机无服务_手机突然显示无SIM卡?这样做就能恢复~

热门文章

  1. 怎样自制干果核桃仁蛋糕
  2. ASCII码完整版对照表,收藏起来以备不时之需
  3. Linux编程基础:第4章Shell编程 课后习题
  4. 【学习笔记】Kubernetes 问题诊断
  5. 给你喜欢却不能在一起的人
  6. 微信小程序——签到系统(入门级)
  7. 百度一下,什么都不知道
  8. Mosquitto安装和测试
  9. 40个免费在线杀毒网站集锦
  10. Batch_Normalization 、Layer_Normalization 、Group_Normalization你分的清楚吗