1.1使用的软件及版本
软件
版本号
Rancher
1.6stable
Kubernetes
1.8.3
Docker
1.12.6
1.2 Rancher与K8S的RESTAPI差异
因为目前使用Rancher作为K8S的部署工具,Rancher封装了K8S的REST API(仅仅是做了一层代办代理),,且K8S apiserver是作为内部处事(没有开放对外端口),因此无法直接访谒K8S的api。不过可以通过Rancher开放的端口访谒,其他内容还是没有变革的。
原K8S的REST API访谒链接
https://k8s_apiserver_ip:6443/api/v1/namespaces/default/
现Rancher供给的RESTAPI链接
:8080/r/projects/1a7/kubernetes:6443/v1/namespaces/default/
2 REST API授权要访谒K8S的RESTAPI需要供给认证信息API Key。
API Key使用Bearer认证,包罗集群所有者的两部分内容:Access Key和Secret Key。这两个信息都可以通过在RancherUI中获得。
具体获取方法如下:
①使用该集群所有者信息登录RancherUI,点击【API】> 【密钥】
②点击【添加账号API Key】
这里Api Key的名称和描述仅仅作为帮助感化,点创建会弹出真正需要记录的内容。
③点击【创建】
图片中的警告信息说明的已经很清晰了,不再解释。
④按照Access Key和Secret Key计算认证信息。
先获取 <AccessKey>:<SecretKey> 的Base64编码,长度84,记做KeyCode84
再获取 Basic <KeyCode84> 的Base64编码,长度120,记做KeyCode120
⑤使用
倡议REST API请求的时候,在请求头里加上以下认证信息即可:
Authorization:Bearer <KeyCode120>
例如:
Authorization:Bearer
QmFzaWMgTXpjNVFVSkRRalJCT1RRMFJUQTFPRVF5UlVZNldXbFJNbmM1UVcxUVIzaEZlbHBrTlc1NU56VnZRbmhCY1RreFIxRjBObU55ZVRsRVFuVnRhdz09
QmFzaWMgTUVNME0wWXpPVU0wTmtNek5USXhNRVV4TWpRNmVHMDFhRlY2WkRnelMxazBjM2xTT0ZKa2MyTnJTRFJUYm1seGFXTktOelI2Tm5ONmFYUkJXQT09
3 REST API使用3.1 api成果分类
访谒:8080/r/projects/1a7/kubernetes:6443可以获取到所有撑持的接口:
{
"paths": [
"/api",
"/api/v1", //蓝色部分是核心API Group
"/apis",
"/apis/",
"/apis/apiextensions.k8s.io",
"/apis/apiextensions.k8s.io/v1beta1",
"/apis/apiregistration.k8s.io",
"/apis/apiregistration.k8s.io/v1beta1",
"/apis/apps",
"/apis/apps/v1beta1",
"/apis/apps/v1beta2",
"/apis/authentication.k8s.io",
"/apis/authentication.k8s.io/v1",
"/apis/authentication.k8s.io/v1beta1",
"/apis/authorization.k8s.io",
"/apis/authorization.k8s.io/v1",
"/apis/authorization.k8s.io/v1beta1",
"/apis/autoscaling",
"/apis/autoscaling/v1",
"/apis/autoscaling/v2beta1",
"/apis/batch",
"/apis/batch/v1",
"/apis/batch/v1beta1",
"/apis/batch/v2alpha1",
"/apis/certificates.k8s.io",
"/apis/certificates.k8s.io/v1beta1",
"/apis/extensions",
"/apis/extensions/v1beta1", //扩展组
"/apis/networking.k8s.io",
"/apis/networking.k8s.io/v1",
"/apis/policy",
"/apis/policy/v1beta1",
"/apis/rbac.authorization.k8s.io",
"/apis/rbac.authorization.k8s.io/v1",
"/apis/rbac.authorization.k8s.io/v1beta1",
"/apis/storage.k8s.io",
"/apis/storage.k8s.io/v1",
"/apis/storage.k8s.io/v1beta1",//其他APIGroup
"/healthz",
"/healthz/autoregister-completion",
"/healthz/etcd",
"/healthz/ping",
"/healthz/poststarthook/apiservice-openapi-controller",
"/healthz/poststarthook/apiservice-registration-controller",
"/healthz/poststarthook/apiservice-status-available-controller",
"/healthz/poststarthook/bootstrap-controller",
"/healthz/poststarthook/ca-registration",
"/healthz/poststarthook/generic-apiserver-start-informers",
"/healthz/poststarthook/kube-apiserver-autoregistration",
"/healthz/poststarthook/start-apiextensions-controllers",
"/healthz/poststarthook/start-apiextensions-informers",
"/healthz/poststarthook/start-kube-aggregator-informers",
"/healthz/poststarthook/start-kube-apiserver-informers",
"/logs",
"/metrics",
"/swagger-2.0.0.json",
"/swagger-2.0.0.pb-v1",
"/swagger-2.0.0.pb-v1.gz",
"/swagger.json",
"/swaggerapi",
"/ui",
"/ui/",
"/version"
]
}
Kubernetes主要打点三种资源:Pod,replicationController,service
这里有一篇针对这三个资源的RESTAPI文档: