kubectl技巧之查看资源列表,资源版本和资源schema配置
系列目录
在kubernetes里,pod,service,rs,rc,deploy,resource等对象都需要使用yaml文件来创建,很多时候我们都是参照照官方示例或者一些第三方示例来编写yaml文件以创建对象.虽然这些示例很有典型性和代表性,能够满足我们大部分时候的需求,然而这往往还是不够的,根据项目不同,实际配置可能远比官方提供的demo配置复杂的多,这就要求我们除了掌握常用的配置外,还需要对其它配置有所了解.如果有一个文档能够速查某一对象的所有配置,不但方便我们学习不同的配置,也可以做为一个小手册以便我们记不起来某些配置时可以速查.
下面我们介绍一些小技巧来快速查看kubernetes api
查看所有api资源
可以通过命令kubectl api-resources
来查看所有api资源
[centos@k8s-master ~]$ kubectl api-resources
NAME SHORTNAMES APIGROUP NAMESPACED KIND
bindings true Binding
componentstatuses cs false ComponentStatus
configmaps cm true ConfigMap
endpoints ep true Endpoints
events ev true Event
limitranges limits true LimitRange
namespaces ns false Namespace
nodes no false Node
persistentvolumeclaims pvc true PersistentVolumeClaim
persistentvolumes pv false PersistentVolume
pods po true Pod
podtemplates true PodTemplate
replicationcontrollers rc true ReplicationController
resourcequotas quota true ResourceQuota
secrets true Secret
serviceaccounts sa true ServiceAccount
services svc true Service
mutatingwebhookconfigurations admissionregistration.k8s.io false MutatingWebhookConfiguration
validatingwebhookconfigurations admissionregistration.k8s.io false ValidatingWebhookConfiguration
customresourcedefinitions crd,crds apiextensions.k8s.io false CustomResourceDefinition
apiservices apiregistration.k8s.io false APIService
controllerrevisions apps true ControllerRevision
daemonsets ds apps true DaemonSet
deployments deploy apps true Deployment
replicasets rs apps true ReplicaSet
statefulsets sts apps true StatefulSet
tokenreviews authentication.k8s.io false TokenReview
localsubjectaccessreviews authorization.k8s.io true LocalSubjectAccessReview
selfsubjectaccessreviews authorization.k8s.io false SelfSubjectAccessReview
selfsubjectrulesreviews authorization.k8s.io false SelfSubjectRulesReview
subjectaccessreviews authorization.k8s.io false SubjectAccessReview
horizontalpodautoscalers hpa autoscaling true HorizontalPodAutoscaler
cronjobs cj batch true CronJob
jobs batch true Job
certificatesigningrequests csr certificates.k8s.io false CertificateSigningRequest
leases coordination.k8s.io true Lease
events ev events.k8s.io true Event
daemonsets ds extensions true DaemonSet
deployments deploy extensions true Deployment
ingresses ing extensions true Ingress
networkpolicies netpol extensions true NetworkPolicy
podsecuritypolicies psp extensions false PodSecurityPolicy
replicasets rs extensions true ReplicaSet
networkpolicies netpol networking.k8s.io true NetworkPolicy
poddisruptionbudgets pdb policy true PodDisruptionBudget
podsecuritypolicies psp policy false PodSecurityPolicy
clusterrolebindings rbac.authorization.k8s.io false ClusterRoleBinding
clusterroles rbac.authorization.k8s.io false ClusterRole
rolebindings rbac.authorization.k8s.io true RoleBinding
roles rbac.authorization.k8s.io true Role
priorityclasses pc scheduling.k8s.io false PriorityClass
storageclasses sc storage.k8s.io false StorageClass
volumeattachments storage.k8s.io false VolumeAttachment
除了可以看到资源的对象名称外,还可以看到对象的别名,这时候我们再看到别人的命令如kubectl get no
这样费解的命令时就可以知道它实际上代表的是kubectl get nodes
命令
查看api的版本,很多yaml配置里都需要指定配置的资源版本,我们经常看到v1,beta1,beta2这样的配置,到底某个资源的最新版本是什么呢?
其实,可以通过kubectl api-versions
来查看api的版本
[centos@k8s-master ~]$ kubectl api-versions
admissionregistration.k8s.io/v1beta1
apiextensions.k8s.io/v1beta1
apiregistration.k8s.io/v1
apiregistration.k8s.io/v1beta1
apps/v1
apps/v1beta1
apps/v1beta2
authentication.k8s.io/v1
authentication.k8s.io/v1beta1
authorization.k8s.io/v1
authorization.k8s.io/v1beta1
autoscaling/v1
autoscaling/v2beta1
autoscaling/v2beta2
batch/v1
batch/v1beta1
certificates.k8s.io/v1beta1
coordination.k8s.io/v1beta1
events.k8s.io/v1beta1
extensions/v1beta1
networking.k8s.io/v1
policy/v1beta1
rbac.authorization.k8s.io/v1
rbac.authorization.k8s.io/v1beta1
scheduling.k8s.io/v1beta1
storage.k8s.io/v1
storage.k8s.io/v1beta1
v1
以上只是整体概况,很多时候我们还想要看到某个api下面都有哪些配置,某一荐配置的含义等,下面罗列一些常用的api范例和一些查看api的技巧
常见范例
Replica Sets
Replication Controller
Deployment
Service
通过kubectl explain查看api字段
1) 通过kubectl explain <资源名对象名>
查看资源对象拥有的字段
前面说过,可以通过kubectl api-resources
来查看资源名称,如果想要查看某个资源的字段,可以通过kubectl explain <资源名对象名>
来查点它都有哪些字段
[centos@k8s-master ~]$ kubectl explain pod
KIND: Pod
VERSION: v1DESCRIPTION:Pod is a collection of containers that can run on a host. This resource iscreated by clients and scheduled onto hosts.FIELDS:apiVersion <string>APIVersion defines the versioned schema of this representation of anobject. Servers should convert recognized schemas to the latest internalvalue, and may reject unrecognized values. More info:https://git.k8s.io/community/contributors/devel/api-conventions.md#resourceskind <string>Kind is a string value representing the REST resource this objectrepresents. Servers may infer this from the endpoint the client submitsrequests to. Cannot be updated. In CamelCase. More info:https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kindsmetadata <Object>Standard object's metadata. More info:https://git.k8s.io/community/contributors/devel/api-conventions.md#metadataspec <Object>Specification of the desired behavior of the pod. More info:https://git.k8s.io/community/contributors/devel/api-conventions.md#spec-and-statusstatus <Object>Most recently observed status of the pod. This data may not be up to date.Populated by the system. Read-only. More info:https://git.k8s.io/community/contributors/devel/api-conventions.md#spec-and-status[centos@k8s-master ~]$
以上Description是对资源对象的简要描述,Fields
则是对所有字段的描述
2) 列出所有api字段
通过以上我们能感觉到,以上好像并没有罗列出所有的api字段,实际上以上列出的仅是一级字段,一级字段可能还包含二级的,三级的字段,想要罗列出所有的字段,可以加上
--recursive
来列出所有可能的字段
[centos@k8s-master ~]$ kubectl explain svc --recursive
KIND: Service
VERSION: v1DESCRIPTION:Service is a named abstraction of software service (for example, mysql)consisting of local port (for example 3306) that the proxy listens on, andthe selector that determines which pods will answer requests sent throughthe proxy.FIELDS:apiVersion <string>kind <string>metadata <Object>annotations <map[string]string>clusterName <string>creationTimestamp <string>deletionGracePeriodSeconds <integer>deletionTimestamp <string>finalizers <[]string>generateName <string>generation <integer>initializers <Object>pending <[]Object>name <string>result <Object>apiVersion <string>code <integer>details <Object>causes <[]Object>field <string>message <string>reason <string>group <string>kind <string>name <string>retryAfterSeconds <integer>uid <string>kind <string>message <string>metadata <Object>continue <string>resourceVersion <string>selfLink <string>reason <string>status <string>labels <map[string]string>name <string>namespace <string>ownerReferences <[]Object>apiVersion <string>blockOwnerDeletion <boolean>controller <boolean>kind <string>name <string>uid <string>resourceVersion <string>selfLink <string>uid <string>spec <Object>clusterIP <string>externalIPs <[]string>externalName <string>externalTrafficPolicy <string>healthCheckNodePort <integer>loadBalancerIP <string>loadBalancerSourceRanges <[]string>ports <[]Object>name <string>nodePort <integer>port <integer>protocol <string>targetPort <string>publishNotReadyAddresses <boolean>selector <map[string]string>sessionAffinity <string>sessionAffinityConfig <Object>clientIP <Object>timeoutSeconds <integer>type <string>status <Object>loadBalancer <Object>ingress <[]Object>hostname <string>ip <string>
[centos@k8s-master ~]$
以上输出的内容是经过格式化了的,我们可以根据缩进很容易看到某一个字段从属于关系
查看具体字段
通过上面kubectl explain service --recursive
可以看到所有的api名称,但是以上仅仅是罗列了所有的api名称,如果想要知道某一个api名称的详细信息,则可以通过kubectl explain <资源对象名称.api名称>
的方式来查看,比如以下示例可以查看到service
下的spec
下的ports
字段的信息
[centos@k8s-master ~]$ kubectl explain svc.spec.ports
KIND: Service
VERSION: v1RESOURCE: ports <[]Object>DESCRIPTION:The list of ports that are exposed by this service. More info:https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxiesServicePort contains information on service's port.FIELDS:name <string>The name of this port within the service. This must be a DNS_LABEL. Allports within a ServiceSpec must have unique names. This maps to the 'Name'field in EndpointPort objects. Optional if only one ServicePort is definedon this service.nodePort <integer>The port on each node on which this service is exposed when type=NodePortor LoadBalancer. Usually assigned by the system. If specified, it will beallocated to the service if unused or else creation of the service willfail. Default is to auto-allocate a port if the ServiceType of this Servicerequires one. More info:https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeportport <integer> -required-The port that will be exposed by this service.protocol <string>The IP protocol for this port. Supports "TCP", "UDP", and "SCTP". Defaultis TCP.targetPort <string>Number or name of the port to access on the pods targeted by the service.Number must be in the range 1 to 65535. Name must be an IANA_SVC_NAME. Ifthis is a string, it will be looked up as a named port in the target Pod'scontainer ports. If this is not specified, the value of the 'port' field isused (an identity map). This field is ignored for services withclusterIP=None, and should be omitted or set equal to the 'port' field.More info:https://kubernetes.io/docs/concepts/services-networking/service/#defining-a-service
转载于:https://www.cnblogs.com/tylerzhou/p/11043285.html
kubectl技巧之查看资源列表,资源版本和资源schema配置相关推荐
- 整理Silverlight资源列表(四)——Silverlight案例补充
在过去整理资料中,发现其中有一部分案例偏小 实用 适合于初学者开发.完全可以做参考,其中包含一些难的源码项目案例,今天整理出其中一部分发上来.因为过去资料时间有点长,可能其中有些连接的资源失效或无法访 ...
- PyTorch超级资源列表(Github 2.4K星)包罗万象
PyTorch超级资源列表,包罗万象 PyTorch超级资源列表(Github 2.4K星)包罗万象 -v7.x 1 Pytorch官方工程 2 自然语言处理和语音处理(NLP & Speec ...
- 懒人必备 |通过爬虫 筛选以及查看CSDN 满足相应积分的资源列表 简单好用
为了方便查看自己上传资源情况. 不想一次一次的翻阅自己上传资源列表进行查看. 写个简单的爬虫,就可以解决这些问题啦. 视频演示:https://www.bilibili.com/video/BV1qa ...
- PHP资源列表(转)
一个PHP资源列表,内容包括:库.框架.模板.安全.代码分析.日志.第三方库.配置工具.Web 工具.书籍.电子书.经典博文等等. 初始翻译信息来自:<推荐!国外程序员整理的 PHP 资源大全& ...
- 人工智能和ChatGPT深度学习相关资源列表
作者:Derrick Harris,Matt Bornstein,Guido Appenzeller Research in artificial intelligence is increasing ...
- Asp.Net 学习资源列表 [转]
转:http://blog.csdn.net/liujien/archive/2005/11/23/535225.aspx Asp.Net 学习资源列表 名称:快速入门 地址:http://chs. ...
- 20款非常实用的Web工具和资源列表
转载:CSDN首页-软件研发 原文地址:http://www.csdn.net/article/2013-04-22/2814991-20-useful-tools-and-resources-for ...
- 如何学习深度学习——我的高质量学习资源列表
深度学习是当下计算机界火得不能再火的研究课题.作为一名计算机人,应当有不断学习当下最前沿技术的觉悟.但问题来了,深度学习领域的入门资料让人看花了眼,我实在不知道该从何学起.刚好在网上看到了Arthur ...
- 一个不错的学习资源列表
一个不错的学习资源列表 发信站: 逸仙时空 Yat-sen Channel (Sun Nov 12 11:34:48 2006), 转信 转贴)这份材料是我在帮美国MIT的William Stalli ...
最新文章
- lock_sga and pre_page_sga设置
- 树莓派html5播放器,树莓派|5 个很适合在课堂上演示的树莓派项目
- 有效的形成传感器(执行器)的控制方式
- Python小数据池
- java项目 js报错红叉,解决js红叉,java Resources红叉
- 阿里第二代微服务强势崛起,你还敢往简历上写“精通”吗?
- JRebel for idea 有时候不生效
- php修改学生信息代码_PHP程序员从入门到佛系第二十八弹:PHP $_POST 变量
- Python+django网页设计入门(17):模板语法及应用
- 2021年已经过去了4天,创业者、负债累累而希望通过再创业实现东山再起者,你们准备的怎么样了?
- docker配置 nacos_Docker下Nacos配置应用开发
- android第一个项目HelloWorld的搭建
- Linux ALSA声卡驱动
- 【项目源码】JavaWeb网上购书系统
- Vs2010中文版 使用 .net 3.5 时,智能提示英文变中文
- react-native实现支付宝支付
- WIN7下安装WIN2003系统
- 吴裕雄--天生自然 诗经:望海潮·东南形胜
- 常见的生物识别技术有哪些
- SpringBoot(六)打包方式
热门文章
- BZOJ 4720: [Noip2016]换教室
- Flask之threading.loacl方法
- Spring 属性配置
- python日记----2017.8.1
- 如何测试一个网页登陆界面
- iReport工具的使用(三)
- 31 | 套路篇:磁盘 I/O 性能优化的几个思路
- Tomcat服务部署和优化
- sudo命令_如何在非 sudo 用户下运行 docker 命令?
- 使用mvc模式读取服务器上的文件,关于C#:如何使用asp.net MVC应用程序从服务器上的网络路径读取...