首页 > 其他分享 >K8S 的API

K8S 的API

时间:2022-08-16 22:45:21浏览次数:74  
标签:K8S apis readyz v1 poststarthook API io k8s

一、K8S的api概览:

在Kubernetes集群中,一个API对象在Etcd里完整资源路径,是由:Group(API组)、Version(API版本)和Resource(API资源类型)三个部分组成的。通过这样的结构,整个

Kubernetes里的所有API对象,实际上就可以用如下的树形结构表示出来

我们也可以用命令来查看API组织形式

~  kubectl get --raw /
{
  "paths": [
    "/api",
    "/api/v1",
    "/apis",
    "/apis/",
    "/apis/admissionregistration.k8s.io",
    "/apis/admissionregistration.k8s.io/v1",
    "/apis/admissionregistration.k8s.io/v1beta1",
    "/apis/apiextensions.k8s.io",
    "/apis/apiextensions.k8s.io/v1",
    "/apis/apiextensions.k8s.io/v1beta1",
    "/apis/apiregistration.k8s.io",
    "/apis/apiregistration.k8s.io/v1",
    "/apis/apiregistration.k8s.io/v1beta1",
    "/apis/apps",
    "/apis/apps/v1",
    "/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/autoscaling/v2beta2",
    "/apis/batch",
    "/apis/batch/v1",
    "/apis/batch/v1beta1",
    "/apis/certificates.k8s.io",
    "/apis/certificates.k8s.io/v1",
    "/apis/certificates.k8s.io/v1beta1",
    "/apis/coordination.k8s.io",
    "/apis/coordination.k8s.io/v1",
    "/apis/coordination.k8s.io/v1beta1",
    "/apis/crd.projectcalico.org",
    "/apis/crd.projectcalico.org/v1",
    "/apis/discovery.k8s.io",
    "/apis/discovery.k8s.io/v1beta1",
    "/apis/events.k8s.io",
    "/apis/events.k8s.io/v1",
    "/apis/events.k8s.io/v1beta1",
    "/apis/extensions",
    "/apis/extensions/v1beta1",
    "/apis/networking.k8s.io",
    "/apis/networking.k8s.io/v1",
    "/apis/networking.k8s.io/v1beta1",
    "/apis/node.k8s.io",
    "/apis/node.k8s.io/v1beta1",
    "/apis/policy",
    "/apis/policy/v1beta1",
    "/apis/rbac.authorization.k8s.io",
    "/apis/rbac.authorization.k8s.io/v1",
    "/apis/rbac.authorization.k8s.io/v1beta1",
    "/apis/scheduling.k8s.io",
    "/apis/scheduling.k8s.io/v1",
    "/apis/scheduling.k8s.io/v1beta1",
    "/apis/storage.k8s.io",
    "/apis/storage.k8s.io/v1",
    "/apis/storage.k8s.io/v1beta1",
    "/healthz",
    "/healthz/autoregister-completion",
    "/healthz/etcd",
    "/healthz/log",
    "/healthz/ping",
    "/healthz/poststarthook/aggregator-reload-proxy-client-cert",
    "/healthz/poststarthook/apiservice-openapi-controller",
    "/healthz/poststarthook/apiservice-registration-controller",
    "/healthz/poststarthook/apiservice-status-available-controller",
    "/healthz/poststarthook/bootstrap-controller",
    "/healthz/poststarthook/crd-informer-synced",
    "/healthz/poststarthook/generic-apiserver-start-informers",
    "/healthz/poststarthook/kube-apiserver-autoregistration",
    "/healthz/poststarthook/rbac/bootstrap-roles",
    "/healthz/poststarthook/scheduling/bootstrap-system-priority-classes",
    "/healthz/poststarthook/start-apiextensions-controllers",
    "/healthz/poststarthook/start-apiextensions-informers",
    "/healthz/poststarthook/start-cluster-authentication-info-controller",
    "/healthz/poststarthook/start-kube-aggregator-informers",
    "/healthz/poststarthook/start-kube-apiserver-admission-initializer",
    "/livez",
    "/livez/autoregister-completion",
    "/livez/etcd",
    "/livez/log",
    "/livez/ping",
    "/livez/poststarthook/aggregator-reload-proxy-client-cert",
    "/livez/poststarthook/apiservice-openapi-controller",
    "/livez/poststarthook/apiservice-registration-controller",
    "/livez/poststarthook/apiservice-status-available-controller",
    "/livez/poststarthook/bootstrap-controller",
    "/livez/poststarthook/crd-informer-synced",
    "/livez/poststarthook/generic-apiserver-start-informers",
    "/livez/poststarthook/kube-apiserver-autoregistration",
    "/livez/poststarthook/rbac/bootstrap-roles",
    "/livez/poststarthook/scheduling/bootstrap-system-priority-classes",
    "/livez/poststarthook/start-apiextensions-controllers",
    "/livez/poststarthook/start-apiextensions-informers",
    "/livez/poststarthook/start-cluster-authentication-info-controller",
    "/livez/poststarthook/start-kube-aggregator-informers",
    "/livez/poststarthook/start-kube-apiserver-admission-initializer",
    "/logs",
    "/metrics",
    "/openapi/v2",
    "/readyz",
    "/readyz/autoregister-completion",
    "/readyz/etcd",
    "/readyz/informer-sync",
    "/readyz/log",
    "/readyz/ping",
    "/readyz/poststarthook/aggregator-reload-proxy-client-cert",
    "/readyz/poststarthook/apiservice-openapi-controller",
    "/readyz/poststarthook/apiservice-registration-controller",
    "/readyz/poststarthook/apiservice-status-available-controller",
    "/readyz/poststarthook/bootstrap-controller",
    "/readyz/poststarthook/crd-informer-synced",
    "/readyz/poststarthook/generic-apiserver-start-informers",
    "/readyz/poststarthook/kube-apiserver-autoregistration",
    "/readyz/poststarthook/rbac/bootstrap-roles",
    "/readyz/poststarthook/scheduling/bootstrap-system-priority-classes",
    "/readyz/poststarthook/start-apiextensions-controllers",
    "/readyz/poststarthook/start-apiextensions-informers",
    "/readyz/poststarthook/start-cluster-authentication-info-controller",
    "/readyz/poststarthook/start-kube-aggregator-informers",
    "/readyz/poststarthook/start-kube-apiserver-admission-initializer",
    "/readyz/shutdown",
    "/version"
  ]
}%

如:查看批处理操作

[root@master1 ~]# kubectl get --raw /apis/batch/v1 | python -m json.tool
{
    "apiVersion": "v1",
    "groupVersion": "batch/v1",
    "kind": "APIResourceList",
    "resources": [
        {
            "categories": [
                "all"
            ],
            "kind": "CronJob",
            "name": "cronjobs",
            "namespaced": true,
            "shortNames": [
                "cj"
            ],
            "singularName": "",
            "storageVersionHash": "h/JlFAZkyyY=",
            "verbs": [
                "create",
                "delete",
                "deletecollection",
                "get",
                "list",
                "patch",
                "update",
                "watch"
            ]
        },
        {
            "kind": "CronJob",
            "name": "cronjobs/status",
            "namespaced": true,
            "singularName": "",
            "verbs": [
                "get",
                "patch",
                "update"
            ]
        },
        {
            "categories": [
                "all"
            ],
            "kind": "Job",
            "name": "jobs",
            "namespaced": true,
            "singularName": "",
            "storageVersionHash": "mudhfqk/qZY=",
            "verbs": [
                "create",
                "delete",
                "deletecollection",
                "get",
                "list",
                "patch",

二、YAML书写

通常,kubernetes API支持函通过标准HTTP POST、PUT、DELETE和GET在指定PATH路径上创建、更新 、删除和检索操作,并使用JSON作为默认的数据交互格式。
比如现在我们要创建一个Job对象,那么我们的YAML文件的声明就需要怎么写

apiVersion: batch/v1
kind: Job
metadata:
  name: demo
  namespace: default

其中Job就是这个API对象的资源类型Kind,而资源类型Resource通常为Kind的小写复数词,比如这里就是jobs,batch就是它的组(Group),v1就是它的版本(Version),APIGroup、Version和资源就唯一定义了一个HTTP路径,

然后kube-apiserver端对这个URL进行了监听,然后把对应的请求传递给了对应的控制器进行处理而已

 

Resources和Kind的区别是什么?需要注意的是Resources指的是HTTP Restful API请求路径中的资源(理解Restful API的资源),而kind对应的是系统中真正的实体,这两个是有本质区别的。

每个kind都存在于一个Group和Version中,并通过GroupVersionKind(GVK)来标识,GVR和GVK是相关联的,GVK通过GVR标识的HTTP路径来提供服务,将GVK映射到GVR的过程就叫做Rest mapping

三、api请求流程

1、HTTP请求先由DefaultBuildHandlerChain()注册的一系列过滤器处理,这个函数位于k8s.io/apiserver/pkg/server/config.go文件中,它对请求进行一系列过滤操作,经过验证的就返回相应的HTTP返回码

2、接下来根据请求的路径,通过handler路由到各种处理程序中k8s.io/apiserver/pkg/server/handler.go

3、每个API Group都注册了一个handler,详情参见k8s.io/apiserver/pkg/endpoints/groupversion.go和k8s.io/apiserver/pkg/endpoints/installer.go它接受HTTP请求和上下文,并从e处链接及本声明。

原文链接:https://blog.csdn.net/qq_21127151/article/details/124854845

标签:K8S,apis,readyz,v1,poststarthook,API,io,k8s
From: https://www.cnblogs.com/wuchangblog/p/16593137.html

相关文章

  • K8S 四种client简单介绍
    K8S四种client简单介绍client-go支持RESTClient、ClientSet、DynamicClient、DiscoveryClient四种客户端与KubernetesApiServer进行交互RESTClient客户端restclient客......
  • system desing 系统设计(四):网站API和短网址short url的生成
    1、(1)逆向APP时,第一个干的事就是抓包了,抓包的结果类似下面:GEThttps://aweme.snssdk.com/aweme/v1/commit/item/digg/?aweme_id=6956180208793718055&type=1&channel_......
  • 了解使用Java语言操作数据库的API之JDBC
    一、简单了解JDBC是官方定义的一套使用Java语言操作数据库的API,各数据库厂商按照此标准定义各自的实现类,因此在使用JDBC操作不同的数据库时,需导入对应的驱动jar包。二......
  • Jenkins pipeline 发布k8s应用
    1.容器镜像仓库harbor2.应用的基础镜像3.Jenkinspipeline 首先制作好应用的基础镜像,上传到容器仓库中然后设置Jenkins,用Jenkins发布k8s需要安装一个插件,在插件......
  • 在IIS中部署.NET Core WebApi程序(转载)
    环境说明部署NETCore编写WebApi并部署为IIS站点,演示环境如下:VisualStudio2019(v16.8).NetCore3.1一台安装了IIS的设备Note:.NETCore3.0项目开发需要vs2019(......
  • 将WebAPI(core 3.1)部署在IIS上(转)
    使用的是VS2019社区版,WebAPI的版本是.netcore3.1,其他版本可能略有不同,请根据情况适当更改。1.打开微软.net官网,点击HostingBundle下载安装,安装好后重启电脑2.打开IIS,双......
  • k8s集群不可用:The connection to the server 192.168.117.161:6443 was refused - did
    虚拟机非正常关机后,k8s集群不可用获取节点,报如下错,kubectlgetnode 查看env:env|grep-ikubernetes 查看docker状态:systemctlstatusdocker 查看kubelet......
  • 前端好用API之MutationObserver
    前情一直以来都没有好的方式可以监听元素变化,Mutationevents虽然可以监听DOM树结构变化,但是因性能问题和差的兼容问题(Webkit内核不支持)并不推荐使用。MutationObserver......
  • JS学习-Web Workers API接口
    WebWorkersAPI接口通过使用WebWorkers,Web应用程序可以在独立于主线程的后台线程中,运行一个脚本操作。这样做的好处是可以在独立线程中执行费时的处理任务,从而允许主线......
  • APISpace 发现好物节 优惠多多
    叮叮叮!!APISpace即将迎来818发现好物节,又是一波满满的优惠福利。发现好物,当然是给大家带来了超多超热门超好用超实惠的API啦~除此之外,注册APISpace即可得到一份160元A......