kubectl apply yield forbidden,检索当前配置时出错

Ant*_*ope 5 kubernetes

按照步骤创建单个主集群,我能够成功初始化主集群,但是在应用时出现禁止错误,有人遇到过同样的情况吗?谢谢!

我做了以下

1. disable selinux in /etc/selinux/config, and reboot
2. comment out KUBELET_NETWORK_ARGS in 
         /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
3. export no_proxy=$no_proxy,<master-ip> 
4. export KUBECONFIG=/etc/kubernetes/kubelet.conf in .bash_profile
Run Code Online (Sandbox Code Playgroud)

初始化成功后,尝试申请时

kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/v0.10.0/Documentation/kube-flannel.yml
Run Code Online (Sandbox Code Playgroud)

我收到以下错误消息

Error from server (Forbidden): error when retrieving current configuration of:
&{0xc42048ab40 0xc421a83730  
flannel https://raw.githubusercontent.com/coreos/flannel/v0.10.0/Documentation/kube-flannel.yml 0xc42109cc20  false}
from server for: "https://raw.githubusercontent.com/coreos/flannel/v0.10.0/Documentation/kube-flannel.yml": 
clusterroles.rbac.authorization.k8s.io "flannel" is forbidden: 
User "system:node:<master-server-name>" 
cannot get clusterroles.rbac.authorization.k8s.io at the cluster scope
Run Code Online (Sandbox Code Playgroud)

VAS*_*VAS 3

一旦您的集群尚未完全发挥作用,将其拆除并从头开始重新创建会更容易:

\n\n

拆掉一切:

\n\n
$> sudo su\n#> kubeadm reset\n#> rm -rf $HOME/.kube /etc/kubernetes\n
Run Code Online (Sandbox Code Playgroud)\n\n

准备你的主机(以防万一你还没有\xe2\x80\x99t已经完成):

\n\n
#> swapoff -a\n## Don't forget to comment swap partition line in /etc/fstab\n\n## I assume that you have these packages already installed: docker, kubeadm, kubectl\n\n## tune sysctl to pass bridged IPv4 traffic to iptables\xe2\x80\x99 chains. \n## This is a requirement for some CNI plugins to work, for more information please see\n## https://kubernetes.io/docs/concepts/cluster-administration/network-plugins/#network-plugin-requirements\n\n#> cat <<EOF >>/etc/ufw/sysctl.conf\nnet/bridge/bridge-nf-call-ip6tables = 1\nnet/bridge/bridge-nf-call-iptables = 1\nnet/bridge/bridge-nf-call-arptables = 1\nEOF\n#> sudo sysctl --system\n
Run Code Online (Sandbox Code Playgroud)\n\n

初始化集群:

\n\n
## Do not try to set less than /16 subnet for `--pod-network-cidr`\n\n#> kubeadm init --pod-network-cidr=10.244.0.0/16\n\n## Prepare the kubectl config\n\n#> mkdir -p $HOME/.kube\n#> cp -i /etc/kubernetes/admin.conf $HOME/.kube/config\n#> chown $(id -u):$(id -g) $HOME/.kube/config\n
Run Code Online (Sandbox Code Playgroud)\n\n

安装法兰绒

\n\n
#> kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/v0.10.0/Documentation/kube-flannel.yml\n
Run Code Online (Sandbox Code Playgroud)\n\n

允许在主节点上调度 pod。

\n\n

(以防万一您没有任何工作节点。)

\n\n
#> kubectl taint nodes --all node-role.kubernetes.io/master-\n
Run Code Online (Sandbox Code Playgroud)\n\n

此时您应该已经有了可以使用的 Kubernetes 集群:

\n\n
#> kubectl get nodes\n#> kubectl get pods --all-namespaces\n
Run Code Online (Sandbox Code Playgroud)\n