【问题标题】:kubectl apply yield forbidden, error when retrieving current configurationkubectl apply yield 禁止,检索当前配置时出错
【发布时间】:2018-11-30 05:41:11
【问题描述】:

followed steps to create single master cluster,我能够成功初始化master,但是当应用时我得到forbidden错误,有人遇到过同样的情况吗?谢谢!

我做了以下

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

初始化成功后,尝试应用时

kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/v0.10.0/Documentation/kube-flannel.yml

我收到以下错误消息

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

【问题讨论】:

    标签: kubernetes


    【解决方案1】:

    一旦您的集群尚未完全正常运行,将其拆除并从头开始重新创建会更容易:

    拆除一切:

    $> sudo su
    #> kubeadm reset
    #> rm -rf $HOME/.kube /etc/kubernetes
    

    准备你的主机(以防万一你还没有这样做):

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

    初始化集群:

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

    安装法兰绒

    #> kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/v0.10.0/Documentation/kube-flannel.yml
    

    允许在主节点上调度 Pod。

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

    #> kubectl taint nodes --all node-role.kubernetes.io/master-
    

    此时你应该已经有了现成的 Kubernetes 集群:

    #> kubectl get nodes
    #> kubectl get pods --all-namespaces
    

    【讨论】:

    • 感谢 VAS,您的步骤正是我所做的,但是我在 kubectl apply 的步骤中得到了 Forbidden ....我认为它与代理有关....因为我刚刚尝试了在 digitalocean 服务器上执行相同的步骤,并且都通过了...不太确定如何处理代理,可能需要在 squid.conf 中允许某些端口...
    • 尝试添加apiserver ip地址到代理异常:xmodulo.com/how-to-configure-http-proxy-exceptions.html
    • 实际上原因是因为我没有使用正确的法兰绒--pod-network-cidr=10.244.0.0/16,我也忘记在脚本末尾(不在.bash_profile中)export KUBECONFIG=/etc/kubernetes/admin.conf...谢谢不过正式步骤!
    【解决方案2】:

    您不知何故从使用 cluster-admin kubeconfig(具有超级用户访问权限)切换到使用主节点 kubeconfig(只能访问 kubelet/节点应该能够做的事情)

    【讨论】:

    • 如何切换回来?我试图将 /etc/kubernetes/admin.config cp 到 .kube/config...仍然得到相同的结果...谢谢
    【解决方案3】:
    cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
    

    而不是

    cp -i /etc/kubernetes/kubelet.conf ~/.kube/config
    

    【讨论】:

      猜你喜欢
      • 2019-01-19
      • 1970-01-01
      • 2018-08-22
      • 1970-01-01
      • 1970-01-01
      • 2019-11-18
      • 2019-07-25
      • 2018-05-02
      • 2020-04-22
      相关资源
      最近更新 更多