Kubernetes“服务器没有资源类型部署”

Ali*_*hin 7 kubernetes kubernetes-deployment

我是 kubernetes 的新手。

我无法使用 kubectl 进行部署,但我可以在 kubernetes 仪表板上看到所有部署。我该如何解决这个问题?

user@master:~$ kubectl get deployments
error: the server doesn't have a resource type "deployments"
Run Code Online (Sandbox Code Playgroud)

Kubernetes 版本: 1.12

kubectl 版本: 1.13

kubectl api 版本:

apiregistration.k8s.io/v1

apiregistration.k8s.io/v1beta1

v1

api资源:

user@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
apiservices                           apiregistration.k8s.io   false        
APIService
Run Code Online (Sandbox Code Playgroud)

感谢您的帮助。

-----------编辑1-----------

您好@EduardoBaitello,感谢您的快速回复。问题与权限无关。

user@master:~$ kubectl auth can-i get deployments Warning: the server doesn't have a resource type 'deployments' yes user@master:~$ kubectl auth can-i get deployment Warning: the server doesn't have a resource type 'deployment' yes user@master:~$ kubectl auth can-i get namespaces yes user@master:~$ kubectl auth can-i get pods yes

所以我认为这不是一个重复的问题。

user@master:~$ kubectl get po --namespace=kube-system NAME READY STATUS RESTARTS AGE calico-kube-controllers-7c6b876df8-nk7nm 1/1 Running 2 118d calico-node-8lt9f 1/1 Running 3 118d calico-node-d9r9l 1/1 Running 2 118d calico-node-ffqlj 1/1 Running 2 118d dns-autoscaler-57ff59dd4c-c9tjv 1/1 Running 2 118d kube-apiserver-node1 1/1 Running 3 118d kube-controller-manager-node1 1/1 Running 6 118d kube-dns-84467597f5-hf2fn 3/3 Running 6 118d kube-dns-84467597f5-sttgx 3/3 Running 9 118d kube-proxy-node1 1/1 Running 3 118d kube-proxy-node2 1/1 Running 2 118d kube-proxy-node3 1/1 Running 2 118d kube-scheduler-node1 1/1 Running 6 118d kubernetes-dashboard-5db4d9f45f-gkl6w 1/1 Running 3 118d nginx-proxy-node2 1/1 Running 2 118d nginx-proxy-node3 1/1 Running 2 118d tiller-deploy-6f6fd74b68-27fqc 1/1 Running 0 16d

user@master:~$ kubectl get componentstatus NAME STATUS MESSAGE scheduler Healthy ok controller-manager Healthy ok etcd-2 Healthy {"health": "true"} etcd-1 Healthy {"health": "true"} etcd-0 Healthy {"health": "true"}

Ale*_*lex 9

第一步是提高详细程度以帮助找出根本原因:

Kubectl 获取部署 --v=99

总的来说,可能导致它的原因很少:

  1. 您可能以 root 用户身份运行以下命令,而不是常规用户。所以以普通用户身份运行

cp -i /etc/kubernetes/admin.conf $HOME/.kube/config

chown $(id -u):$(id -g) $HOME/.kube/config

正如这里所建议的https://github.com/kubernetes/kubernetes/issues/52636

  1. kubectl 配置文件中的证书已过期,或者如果集群位于“AWS EKS”中,则 IAM 访问密钥可能处于非活动状态。

在我的例子中,除了“服务器没有资源类型部署”之外,当运行“kubectl get deployments --v=99”时,它表明:

Response Body: {"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"Unauthorized","reason":"Unauthorized","code":401
Run Code Online (Sandbox Code Playgroud)

如果是这种情况,请检查您的证书 kubectl 配置文件(它们可能不存在、已过期、必须创建新证书等),或者如果在 EKS 上,则 IAM 密钥已发布/激活。

  1. 缺乏 RBAC 权限,因此不允许为其颁发/签署证书/密钥的用户/组查看特定资源。


小智 0

@阿里坎

我怀疑这是因为 Kubectl 二进制版本。我注意到您的 kubectl 版本(1.13)高于 Kubernetes 版本(1.12)。

您可以尝试将 kubectl 版本降级到 1.12 或更低版本吗?