【k8s错误处理】——unable to retrieve the complete list of server APIs

东门翰
2023-12-01

一、前言

        打算开一个专栏,写一些k8s中遇到的问题,不定时更新。

报错信息:

Error: could not get apiVersions from Kubernetes: unable to retrieve the complete list of server APIs: custom.metrics.k8s.io/v1beta1: the server is currently unable to handle the request

二、排查问题

$ 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
meshpolicies                                      authentication.istio.io            false        MeshPolicy
policies                                          authentication.istio.io            true         Policy
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
metrics                                           autoscaling.internal.knative.dev   true         Metric
podautoscalers                    kpa,pa          autoscaling.internal.knative.dev   true         PodAutoscaler
cronjobs                          cj              batch                              true         CronJob
jobs                                              batch                              true         Job
images                            img             caching.internal.knative.dev       true         Image
certificatesigningrequests        csr             certificates.k8s.io                false        CertificateSigningRequest
certificates                      cert,certs      certmanager.k8s.io                 true         Certificate
challenges                                        certmanager.k8s.io                 true         Challenge
clusterissuers                                    certmanager.k8s.io                 false        ClusterIssuer
issuers                                           certmanager.k8s.io                 true         Issuer
orders                                            certmanager.k8s.io                 true         Order
adapters                                          config.istio.io                    true         adapter
attributemanifests                                config.istio.io                    true         attributemanifest
handlers                                          config.istio.io                    true         handler
httpapispecbindings                               config.istio.io                    true         HTTPAPISpecBinding
httpapispecs                                      config.istio.io                    true         HTTPAPISpec
instances                                         config.istio.io                    true         instance
quotaspecbindings                                 config.istio.io                    true         QuotaSpecBinding
quotaspecs                                        config.istio.io                    true         QuotaSpec
rules                                             config.istio.io                    true         rule
templates                                         config.istio.io                    true         template
leases                                            coordination.k8s.io                true         Lease
brokers                                           eventing.knative.dev               true         Broker
channels                          chan            eventing.knative.dev               true         Channel
clusterchannelprovisioners        ccp             eventing.knative.dev               false        ClusterChannelProvisioner
eventtypes                                        eventing.knative.dev               true         EventType
subscriptions                     sub             eventing.knative.dev               true         Subscription
triggers                                          eventing.knative.dev               true         Trigger
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
channels                          ch              messaging.knative.dev              true         Channel
choices                                           messaging.knative.dev              true         Choice
inmemorychannels                  imc             messaging.knative.dev              true         InMemoryChannel
sequences                                         messaging.knative.dev              true         Sequence
nodes                                             metrics.k8s.io                     false        NodeMetrics
pods                                              metrics.k8s.io                     true         PodMetrics
certificates                      kcert           networking.internal.knative.dev    true         Certificate
clusteringresses                                  networking.internal.knative.dev    false        ClusterIngress
ingresses                         ing             networking.internal.knative.dev    true         Ingress
serverlessservices                sks             networking.internal.knative.dev    true         ServerlessService
destinationrules                  dr              networking.istio.io                true         DestinationRule
envoyfilters                                      networking.istio.io                true         EnvoyFilter
gateways                          gw              networking.istio.io                true         Gateway
serviceentries                    se              networking.istio.io                true         ServiceEntry
sidecars                                          networking.istio.io                true         Sidecar
virtualservices                   vs              networking.istio.io                true         VirtualService
ingresses                         ing             networking.k8s.io                  true         Ingress
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
authorizationpolicies                             rbac.istio.io                      true         AuthorizationPolicy
clusterrbacconfigs                                rbac.istio.io                      false        ClusterRbacConfig
rbacconfigs                                       rbac.istio.io                      true         RbacConfig
servicerolebindings                               rbac.istio.io                      true         ServiceRoleBinding
serviceroles                                      rbac.istio.io                      true         ServiceRole
priorityclasses                   pc              scheduling.k8s.io                  false        PriorityClass
configurations                    config,cfg      serving.knative.dev                true         Configuration
revisions                         rev             serving.knative.dev                true         Revision
routes                            rt              serving.knative.dev                true         Route
services                          kservice,ksvc   serving.knative.dev                true         Service
apiserversources                                  sources.eventing.knative.dev       true         ApiServerSource
awssqssources                                     sources.eventing.knative.dev       true         AwsSqsSource
containersources                                  sources.eventing.knative.dev       true         ContainerSource
cronjobsources                                    sources.eventing.knative.dev       true         CronJobSource
githubsources                                     sources.eventing.knative.dev       true         GitHubSource
kafkasources                                      sources.eventing.knative.dev       true         KafkaSource
csidrivers                                        storage.k8s.io                     false        CSIDriver
csinodes                                          storage.k8s.io                     false        CSINode
storageclasses                    sc              storage.k8s.io                     false        StorageClass
volumeattachments                                 storage.k8s.io                     false        VolumeAttachment
clustertasks                                      tekton.dev                         false        ClusterTask
pipelineresources                                 tekton.dev                         true         PipelineResource
pipelineruns                      pr,prs          tekton.dev                         true         PipelineRun
pipelines                                         tekton.dev                         true         Pipeline
taskruns                          tr,trs          tekton.dev                         true         TaskRun
tasks                                             tekton.dev                         true         Task
error: unable to retrieve the complete list of server APIs: custom.metrics.k8s.io/v1beta1: the server is currently unable to handle the request
➜  charts git:(h2update2)

三、解决办法

1、查找到出问题的apiservice

kubectl get apiservice

可以看到其中有出现false状态的apiservice,删除出问题的apiservice故障即可解决。

2、删除出问题的apiservice

kubectl delete apiservce <service-name>

四、参考资料

1、issue 

 类似资料: