zoukankan      html  css  js  c++  java
  • kubernetes版本apiversion简单说明

    在使用yaml文件部署Deployment项目时,出现过

    error: error validating "xx-Deployment.yaml": error validating data: found invalid field Ports for v1.Container; if you choose to ignore these errors, turn validation off with --validate=false

    的错误,对于kubernetes中的apiversion做一个简单的说明:

    1.extensions/v1beta1是用于kubernetes版本在1.6之前,资源申明

    2.apps/v1beta1是用于1.6-1.9版本之间

    3.apps/v1是1.9版本以后使用
    目前使用的是1.16.3版本可以正常使用apps/v1

    apps是指应用的场景,例如可以使用deployment,service,namespace等,几乎涵盖了申明资源,不过也可以不写,进行通用匹配资源,但也有些资源需要特殊申明,具体可以通过命令查看。

    [root@test kubernetes]# 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-resources

    可以通过查看api-resources来查看受支持的资源。

    这里的资源包括Kubernetes自带的,和用户自建的CRD

    第三列和第五列就可以看到title为APIVERSIONKIND,其实到此就已经可以明确如何对应使用资源了。

    [root@test ~]# kubectl api-resources 
    NAME                              SHORTNAMES   APIVERSION                             NAMESPACED   KIND
    bindings                                       v1                                     true         Binding
    componentstatuses                 cs           v1                                     false        ComponentStatus
    configmaps                        cm           v1                                     true         ConfigMap
    endpoints                         ep           v1                                     true         Endpoints
    events                            ev           v1                                     true         Event
    limitranges                       limits       v1                                     true         LimitRange
    namespaces                        ns           v1                                     false        Namespace
    nodes                             no           v1                                     false        Node
    persistentvolumeclaims            pvc          v1                                     true         PersistentVolumeClaim
    persistentvolumes                 pv           v1                                     false        PersistentVolume
    pods                              po           v1                                     true         Pod
    podtemplates                                   v1                                     true         PodTemplate
    replicationcontrollers            rc           v1                                     true         ReplicationController
    resourcequotas                    quota        v1                                     true         ResourceQuota
    secrets                                        v1                                     true         Secret
    serviceaccounts                   sa           v1                                     true         ServiceAccount
    services                          svc          v1                                     true         Service
    mutatingwebhookconfigurations                  admissionregistration.k8s.io/v1        false        MutatingWebhookConfiguration
    validatingwebhookconfigurations                admissionregistration.k8s.io/v1        false        ValidatingWebhookConfiguration
    customresourcedefinitions         crd,crds     apiextensions.k8s.io/v1                false        CustomResourceDefinition
    apiservices                                    apiregistration.k8s.io/v1              false        APIService
    controllerrevisions                            apps/v1                                true         ControllerRevision
    daemonsets                        ds           apps/v1                                true         DaemonSet
    deployments                       deploy       apps/v1                                true         Deployment
    replicasets                       rs           apps/v1                                true         ReplicaSet
    statefulsets                      sts          apps/v1                                true         StatefulSet
    tokenreviews                                   authentication.k8s.io/v1               false        TokenReview
    localsubjectaccessreviews                      authorization.k8s.io/v1                true         LocalSubjectAccessReview
    selfsubjectaccessreviews                       authorization.k8s.io/v1                false        SelfSubjectAccessReview
    selfsubjectrulesreviews                        authorization.k8s.io/v1                false        SelfSubjectRulesReview
    subjectaccessreviews                           authorization.k8s.io/v1                false        SubjectAccessReview
    horizontalpodautoscalers          hpa          autoscaling/v1                         true         HorizontalPodAutoscaler
    cronjobs                          cj           batch/v1beta1                          true         CronJob
    jobs                                           batch/v1                               true         Job
    certificatesigningrequests        csr          certificates.k8s.io/v1                 false        CertificateSigningRequest
    leases                                         coordination.k8s.io/v1                 true         Lease
    endpointslices                                 discovery.k8s.io/v1beta1               true         EndpointSlice
    events                            ev           events.k8s.io/v1                       true         Event
    ingresses                         ing          extensions/v1beta1                     true         Ingress
    flowschemas                                    flowcontrol.apiserver.k8s.io/v1beta1   false        FlowSchema
    prioritylevelconfigurations                    flowcontrol.apiserver.k8s.io/v1beta1   false        PriorityLevelConfiguration
    ingressclasses                                 networking.k8s.io/v1                   false        IngressClass
    ingresses                         ing          networking.k8s.io/v1                   true         Ingress
    networkpolicies                   netpol       networking.k8s.io/v1                   true         NetworkPolicy
    runtimeclasses                                 node.k8s.io/v1                         false        RuntimeClass
    poddisruptionbudgets              pdb          policy/v1beta1                         true         PodDisruptionBudget
    podsecuritypolicies               psp          policy/v1beta1                         false        PodSecurityPolicy
    clusterrolebindings                            rbac.authorization.k8s.io/v1           false        ClusterRoleBinding
    clusterroles                                   rbac.authorization.k8s.io/v1           false        ClusterRole
    rolebindings                                   rbac.authorization.k8s.io/v1           true         RoleBinding
    roles                                          rbac.authorization.k8s.io/v1           true         Role
    priorityclasses                   pc           scheduling.k8s.io/v1                   false        PriorityClass
    csidrivers                                     storage.k8s.io/v1                      false        CSIDriver
    csinodes                                       storage.k8s.io/v1                      false        CSINode
    storageclasses                    sc           storage.k8s.io/v1                      false        StorageClass
    volumeattachments                              storage.k8s.io/v1                      false        VolumeAttachment

    kubectl explain

    通过kubectl explain {kind_name}可以参考到某个kind资源拥有的字段以及对应的apiVersion

    $ kubectl explain deployment
    KIND:     Deployment
    VERSION:  apps/v1
    
    DESCRIPTION:
         Deployment enables declarative updates for Pods and ReplicaSets.
    
    FIELDS:
       apiVersion    <string>
         APIVersion defines the versioned schema of this representation of an
         object. Servers should convert recognized schemas to the latest internal
         value, and may reject unrecognized values. More info:
         https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
    
       kind    <string>
         Kind is a string value representing the REST resource this object
         represents. Servers may infer this from the endpoint the client submits
         requests to. Cannot be updated. In CamelCase. More info:
         https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
    
       metadata    <Object>
         Standard object metadata.
    
       spec    <Object>
         Specification of the desired behavior of the Deployment.
    
       status    <Object>
         Most recently observed status of the Deployment.

    查看资源支持所有字段

    kubectl explain { kind_name } --recursive

    如:kubectl explain { kind_name } --recursive

    因为太长这里就不列出来了。

    查看具体字段里的子字段

    kubectl explain { kind_name }.字段名1.字段名2

    其中从左往右是父子关系,如:deployment.spec.selector

    当在自己写yaml文件时,没有参考示例,可以使用这些命令来摸索

  • 相关阅读:
    构造和析构
    const修饰的成员函数
    class和struct权限
    封装加强
    函数重载实现原理
    Unity2019破解hub
    Lua模拟stack
    函数重载
    LeanTween
    占位参数和默认参数
  • 原文地址:https://www.cnblogs.com/fat-girl-spring/p/14046941.html
Copyright © 2011-2022 走看看