kubectl从服务器获取cs提示错误(禁止)

时间:2018-07-05 21:29:10

标签: centos kubernetes

在centos 7上运行kubectl get cs时,出现以下错误消息。

No resources found.
Error from server (Forbidden): componentstatuses is forbidden: 
User "system:node:<server-name>" cannot list componentstatuses at the cluster scope

我可以确认api服务器正在运行kubectl cluster-info

Kubernetes master is running at https://<server-IP>:6443
KubeDNS is running at https://<server-IP>:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

我也有下面的~/.bash_profile

export http_proxy=http://<proxy-server-IP>:3128
export https_proxy=http://<proxy-server-IP>:3128
export no_proxy=$no_proxy,127.0.0.1,localhost,<server-IP>,<server-name>
export KUBECONFIG=/etc/kubernetes/kubelet.conf

不仅kubectl get cs产生错误消息,kubectl apply -f kubernetes-dashboard.yaml产生类似错误消息

Error from server (Forbidden): error when retrieving current configuration of:
Resource: "/v1, Resource=secrets", GroupVersionKind: "/v1, Kind=Secret"
Name: "kubernetes-dashboard-certs", Namespace: "kube-system"
Object: &{map["kind":"Secret" "metadata":map["labels":map["k8s-app":"kubernetes-dashboard"] "name":"kubernetes-dashboard-certs" "namespace":"kube-system" "annotations":map["kubectl.kubernetes.io/last-applied-configuration":""]] "type":"Opaque" "apiVersion":"v1"]}
from server for: "https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml": 
secrets "kubernetes-dashboard-certs" is forbidden: 
User "system:node:<server-name>" cannot get secrets in the namespace "kube-system": 
no path found to object

3 个答案:

答案 0 :(得分:1)

  

export KUBECONFIG=/etc/kubernetes/kubelet.conf

完全不正确;您正在执行此操作,因为错误消息正试图通知您,因此尝试以Node而不是Users或ServiceAccount之一的身份执行集群操作。 RBAC几乎明确地旨在阻止您完全执行当前的操作。您永远不会希望Node能够读取敏感凭据,也不会在集群范围内创建任意Pod

如果您想对此一窍不通,请使用SSH进入主节点,并使用通常在cluster-admin(或类似文件)中找到的/etc/kubernetes/admin.conf凭据(取决于配置群集的方式) )。如果您还没有拥有 cluster-admin凭据,则创建一个X.509证书,该证书由apiserver信任与组织(在X中为{O= .509的说法,cluster-admin,然后用ServiceAccount的{​​{1}}创建一个ClusterRoleBinding(或其他任何东西),然后从那里开始。

答案 1 :(得分:1)

尝试以下代码段

1)sudo su

2)kubectl get cs

答案 2 :(得分:0)

重新安装centos 7后并按照以下步骤操作,我可以正常启动主机

  1. 安装docker-ce并添加proxy
  2. 安装kubeadm,kubectl,kubelet
  3. 禁用防火墙并关闭交换
  4. 在.bash_profile中导出no_proxy

    export no_proxy=$no_proxy,127.0.0.1,localhost,<master-server-name>,<master-server-ip>,10.96.0.0/12,10.244.0.0/16

  5. kubeadm初始化

    kubeadm init --apiserver-advertise-address=<master-server-ip> --pod-network-cidr=10.244.0.0/16 mkdir -p $HOME/.kube \cp -f /etc/kubernetes/admin.conf $HOME/.kube/config chown $(id -u):$(id -g) $HOME/.kube/config

  6. 使用kubectl get cs

    进行测试

    NAME STATUS MESSAGE ERROR scheduler Healthy ok controller-manager Healthy ok etcd-0 Healthy {"health": "true"}

无需手动安装etcd或导出KUBECONFIG。