這篇文章將為大家詳細(xì)講解有關(guān)kubernetes API Server原理分析是怎樣的,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個(gè)參考,希望大家閱讀完這篇文章后對(duì)相關(guān)知識(shí)有一定的了解。
創(chuàng)新互聯(lián)公司專注于企業(yè)全網(wǎng)營銷推廣、網(wǎng)站重做改版、永福網(wǎng)站定制設(shè)計(jì)、自適應(yīng)品牌網(wǎng)站建設(shè)、HTML5建站、商城建設(shè)、集團(tuán)公司官網(wǎng)建設(shè)、成都外貿(mào)網(wǎng)站建設(shè)、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁設(shè)計(jì)等建站業(yè)務(wù),價(jià)格優(yōu)惠性價(jià)比高,為永福等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。
一:簡介
k8s API Server提供了k8s各類資源對(duì)象(pod,RC,Service等)的增刪改查及watch等HTTP Rest接口,是整個(gè)系統(tǒng)的數(shù)據(jù)總線和數(shù)據(jù)中心。功能特性:
1.是集群管理的API入口
2.是資源配額控制的入口
3.提供了完善的集群安全機(jī)制
二:概述
通??梢酝ㄟ^命令行工具Kubectl來與API Server交互,它們之間的接口是REST調(diào)用,同時(shí)也可以使用curl命令行工具進(jìn)行快速驗(yàn)證。通過配置參數(shù)KUBE_MASTER="--master=http://10.116.137.196:8080" 客戶獲得API Server的訪問路徑。
1.獲取 API的版本信息
curl 10.116.137.196:8080/api
點(diǎn)擊(此處)折疊或打開
{
"kind": "APIVersions",
"versions": [
"v1"
],
"serverAddressByClientCIDRs": [
{
"clientCIDR": "0.0.0.0/0",
"serverAddress": "10.116.137.196:6443"
}
]
}
2.獲取目前所支持的資源對(duì)象的種類
curl 10.116.137.196:8080/api/v1
{
"kind": "APIResourceList",
"groupVersion": "v1",
"resources": [
{
"name": "bindings",
"singularName": "",
"namespaced": true,
"kind": "Binding",
"verbs": [
"create"
]
},
{
"name": "componentstatuses",
"singularName": "",
"namespaced": false,
"kind": "ComponentStatus",
"verbs": [
"get",
"list"
],
"shortNames": [
"cs"
]
},
{
"name": "configmaps",
"singularName": "",
"namespaced": true,
"kind": "ConfigMap",
"verbs": [
"create",
"delete",
"deletecollection",
"get",
"list",
"patch",
"update",
"watch"
],
"shortNames": [
"cm"
]
},
{
"name": "endpoints",
"singularName": "",
"namespaced": true,
"kind": "Endpoints",
"verbs": [
"create",
"delete",
"deletecollection",
"get",
"list",
"patch",
"update",
"watch"
],
"shortNames": [
"ep"
]
},
{
"name": "events",
"singularName": "",
"namespaced": true,
"kind": "Event",
"verbs": [
"create",
"delete",
"deletecollection",
"get",
"list",
"patch",
"update",
"watch"
],
"shortNames": [
"ev"
]
},
{
"name": "limitranges",
"singularName": "",
"namespaced": true,
"kind": "LimitRange",
"verbs": [
"create",
"delete",
"deletecollection",
"get",
"list",
"patch",
"update",
"watch"
],
"shortNames": [
"limits"
]
},
{
"name": "namespaces",
"singularName": "",
"namespaced": false,
"kind": "Namespace",
"verbs": [
"create",
"delete",
"get",
"list",
"patch",
"update",
"watch"
],
"shortNames": [
"ns"
]
},
{
"name": "namespaces/finalize",
"singularName": "",
"namespaced": false,
"kind": "Namespace",
"verbs": [
"update"
]
},
{
"name": "namespaces/status",
"singularName": "",
"namespaced": false,
"kind": "Namespace",
"verbs": [
"get",
"patch",
"update"
]
},
{
"name": "nodes",
"singularName": "",
"namespaced": false,
"kind": "Node",
"verbs": [
"create",
"delete",
"deletecollection",
"get",
"list",
"patch",
"proxy",
"update",
"watch"
],
"shortNames": [
"no"
]
},
{
"name": "nodes/proxy",
"singularName": "",
"namespaced": false,
"kind": "Node",
"verbs": []
},
{
"name": "nodes/status",
"singularName": "",
"namespaced": false,
"kind": "Node",
"verbs": [
"get",
"patch",
"update"
]
},
{
"name": "persistentvolumeclaims",
"singularName": "",
"namespaced": true,
"kind": "PersistentVolumeClaim",
"verbs": [
"create",
"delete",
"deletecollection",
"get",
"list",
"patch",
"update",
"watch"
],
"shortNames": [
"pvc"
]
},
{
"name": "persistentvolumeclaims/status",
"singularName": "",
"namespaced": true,
"kind": "PersistentVolumeClaim",
"verbs": [
"get",
"patch",
"update"
]
},
{
"name": "persistentvolumes",
"singularName": "",
"namespaced": false,
"kind": "PersistentVolume",
"verbs": [
"create",
"delete",
"deletecollection",
"get",
"list",
"patch",
"update",
"watch"
],
"shortNames": [
"pv"
]
},
{
"name": "persistentvolumes/status",
"singularName": "",
"namespaced": false,
"kind": "PersistentVolume",
"verbs": [
"get",
"patch",
"update"
]
},
{
"name": "pods",
"singularName": "",
"namespaced": true,
"kind": "Pod",
"verbs": [
"create",
"delete",
"deletecollection",
"get",
"list",
"patch",
"proxy",
"update",
"watch"
],
"shortNames": [
"po"
],
"categories": [
"all"
]
},
{
"name": "pods/attach",
"singularName": "",
"namespaced": true,
"kind": "Pod",
"verbs": []
},
{
"name": "pods/binding",
"singularName": "",
"namespaced": true,
"kind": "Binding",
"verbs": [
"create"
]
},
{
"name": "pods/eviction",
"singularName": "",
"namespaced": true,
"group": "policy",
"version": "v1beta1",
"kind": "Eviction",
"verbs": [
"create"
]
},
{
"name": "pods/exec",
"singularName": "",
"namespaced": true,
"kind": "Pod",
"verbs": []
},
{
"name": "pods/log",
"singularName": "",
"namespaced": true,
"kind": "Pod",
"verbs": [
"get"
]
},
{
"name": "pods/portforward",
"singularName": "",
"namespaced": true,
"kind": "Pod",
"verbs": []
},
{
"name": "pods/proxy",
"singularName": "",
"namespaced": true,
"kind": "Pod",
"verbs": []
},
{
"name": "pods/status",
"singularName": "",
"namespaced": true,
"kind": "Pod",
"verbs": [
"get",
"patch",
"update"
]
},
{
"name": "podtemplates",
"singularName": "",
"namespaced": true,
"kind": "PodTemplate",
"verbs": [
"create",
"delete",
"deletecollection",
"get",
"list",
"patch",
"update",
"watch"
]
},
{
"name": "replicationcontrollers",
"singularName": "",
"namespaced": true,
"kind": "ReplicationController",
"verbs": [
"create",
"delete",
"deletecollection",
"get",
"list",
"patch",
"update",
"watch"
],
"shortNames": [
"rc"
],
"categories": [
"all"
]
},
{
"name": "replicationcontrollers/scale",
"singularName": "",
"namespaced": true,
"group": "autoscaling",
"version": "v1",
"kind": "Scale",
"verbs": [
"get",
"patch",
"update"
]
},
{
"name": "replicationcontrollers/status",
"singularName": "",
"namespaced": true,
"kind": "ReplicationController",
"verbs": [
"get",
"patch",
"update"
]
},
{
"name": "resourcequotas",
"singularName": "",
"namespaced": true,
"kind": "ResourceQuota",
"verbs": [
"create",
"delete",
"deletecollection",
"get",
"list",
"patch",
"update",
"watch"
],
"shortNames": [
"quota"
]
},
{
"name": "resourcequotas/status",
"singularName": "",
"namespaced": true,
"kind": "ResourceQuota",
"verbs": [
"get",
"patch",
"update"
]
},
{
"name": "secrets",
"singularName": "",
"namespaced": true,
"kind": "Secret",
"verbs": [
"create",
"delete",
"deletecollection",
"get",
"list",
"patch",
"update",
"watch"
]
},
{
"name": "serviceaccounts",
"singularName": "",
"namespaced": true,
"kind": "ServiceAccount",
"verbs": [
"create",
"delete",
"deletecollection",
"get",
"list",
"patch",
"update",
"watch"
],
"shortNames": [
"sa"
]
},
{
"name": "services",
"singularName": "",
"namespaced": true,
"kind": "Service",
"verbs": [
"create",
"delete",
"get",
"list",
"patch",
"proxy",
"update",
"watch"
],
"shortNames": [
"svc"
],
"categories": [
"all"
]
},
{
"name": "services/proxy",
"singularName": "",
"namespaced": true,
"kind": "Service",
"verbs": []
},
{
"name": "services/status",
"singularName": "",
"namespaced": true,
"kind": "Service",
"verbs": [
"get",
"patch",
"update"
]
}
]
}
3.如果只想對(duì)外暴露部分REST服務(wù),則可以在Master或其他任何節(jié)點(diǎn)上通過運(yùn)行kubectl proxy進(jìn)程啟動(dòng)一個(gè)內(nèi)部代理來實(shí)現(xiàn)
kubectl proxy --port=8001
三:Kubernetes Proxy API接口
API Server最主要的REST接口是資源對(duì)象的增刪改查,另外還有一類特殊的REST接口--Kubernetes Proxy API接口,這類接口的作用是代理REST請求,即kubernetes API Server把收到的REST請求轉(zhuǎn)發(fā)到某個(gè)Node上的kubelet守護(hù)進(jìn)程的REST端口上,由該kubelet進(jìn)程負(fù)責(zé)響應(yīng)。
1.Node 相關(guān)的接口
點(diǎn)擊(此處)折疊或打開
/api/v1/proxy/nodes/{name}/pods/ #列出指定節(jié)點(diǎn)內(nèi)所有Pod的信息
/api/v1/proxy/nodes/{name}/stats/ #列出指定節(jié)點(diǎn)內(nèi)物理資源的統(tǒng)計(jì)信息
/api/v1/prxoy/nodes/{name}/spec/ #列出指定節(jié)點(diǎn)的概要信息
這里獲取的Pod信息來自Node而非etcd數(shù)據(jù)庫,兩者時(shí)間點(diǎn)可能存在偏差。
2.Pod 相關(guān)的接口
點(diǎn)擊(此處)折疊或打開
/api/v1/proxy/namespaces/{namespace}/pods/{name}/{path:*} #訪問pod的某個(gè)服務(wù)接口
/api/v1/proxy/namespaces/{namespace}/pods/{name} #訪問Pod
#以下寫法不同,功能一樣
/api/v1/namespaces/{namespace}/pods/{name}/proxy/{path:*} #訪問pod的某個(gè)服務(wù)接口
/api/v1/namespaces/{namespace}/pods/{name}/proxy #訪問Pod
Pod的proxy接口的作用:在kubernetes集群之外訪問某個(gè)pod容器的服務(wù)(HTTP服務(wù)),可以用Proxy API實(shí)現(xiàn),這種場景多用于管理目的,比如逐一排查Service的Pod副本,檢查哪些Pod的服務(wù)存在異常問題。
3.Service 相關(guān)的接口
點(diǎn)擊(此處)折疊或打開
/api/v1/proxy/namespaces/{namespace}/services/{name}
四:集群功能模塊之間的通信
kubernetes API Server作為集群的核心,負(fù)責(zé)集群各功能模塊之間的通信,集群內(nèi)各個(gè)功能模塊通過API Server將信息存入etcd,當(dāng)需要獲取和操作這些數(shù)據(jù)時(shí),通過API Server提供的REST接口(GET\LIST\WATCH方法)來實(shí)現(xiàn),從而實(shí)現(xiàn)各模塊之間的信息交互。
1. kubelet與API SERVER交互
每個(gè)Node節(jié)點(diǎn)上的kubelet定期就會(huì)調(diào)用API Server的REST接口報(bào)告自身狀態(tài),API Server接收這些信息后,將節(jié)點(diǎn)狀態(tài)信息更新到etcd中。kubelet也通過API Server的Watch接口監(jiān)聽Pod信息,從而對(duì)Node機(jī)器上的POD進(jìn)行管理。
2. kube-controller-manager與API SERVER交互
kube-controller-manager中的Node Controller模塊通過API Server提供的Watch接口,實(shí)時(shí)監(jiān)控Node的信息,并做相應(yīng)處理。
3.kube-scheduler與API SERVER交互
Scheduler通過API Server的Watch接口監(jiān)聽到新建Pod副本的信息后,它會(huì)檢索所有符合該P(yáng)od要求的Node列表,開始執(zhí)行Pod調(diào)度邏輯。調(diào)度成功后將Pod綁定到目標(biāo)節(jié)點(diǎn)上。
五: 說明
為了緩解各模塊對(duì)API Server的訪問壓力,各功能模塊都采用緩存機(jī)制來緩存數(shù)據(jù),各功能模塊定時(shí)從API Server獲取指定的資源對(duì)象信息(LIST/WATCH方法),然后將信息保存到本地緩存,功能模塊在某些情況下不直接訪問API Server,而是通過訪問緩存數(shù)據(jù)來間接訪問API Server。
關(guān)于kubernetes API Server原理分析是怎樣的就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到。