【问题标题】:Failed to create ClusterRole for kube-lego为 kube-lego 创建 ClusterRole 失败
【发布时间】:2018-01-31 05:43:35
【问题描述】:

我做了这个例子 https://github.com/jetstack/kube-lego/tree/master/examples/gce ,然后创建 ClusterRole kube-lego 失败。

错误是:

Error from server (Forbidden): error when creating "k8s/kube-lego/hoge.yaml": clusterroles.rbac.authorization.k8s.io "kube-lego" is forbidden: attempt to grant extra privileges: [PolicyRule{Resources:["pods"], APIGroups:[""], Verbs:["get"]} PolicyRule{Resources:["pods"], APIGroups:[""], Verbs:["list"]} PolicyRule{Resources:["services"], APIGroups:[""], Verbs:["create"]} PolicyRule{Resources:["services"], APIGroups:[""], Verbs:["get"]} PolicyRule{Resources:["services"], APIGroups:[""], Verbs:["delete"]} PolicyRule{Resources:["services"], APIGroups:[""], Verbs:["update"]} PolicyRule{Resources:["endpoints"], APIGroups:[""], Verbs:["create"]} PolicyRule{Resources:["endpoints"], APIGroups:[""], Verbs:["get"]} PolicyRule{Resources:["endpoints"], APIGroups:[""], Verbs:["delete"]} PolicyRule{Resources:["endpoints"], APIGroups:[""], Verbs:["update"]} PolicyRule{Resources:["ingresses"], APIGroups:["extensions"], Verbs:["get"]} PolicyRule{Resources:["ingresses"], APIGroups:["extensions"], Verbs:["update"]} PolicyRule{Resources:["ingresses"], APIGroups:["extensions"], Verbs:["create"]} PolicyRule{Resources:["ingresses"], APIGroups:["extensions"], Verbs:["list"]} PolicyRule{Resources:["ingresses"], APIGroups:["extensions"], Verbs:["patch"]} PolicyRule{Resources:["ingresses"], APIGroups:["extensions"], Verbs:["delete"]} PolicyRule{Resources:["ingresses"], APIGroups:["extensions"], Verbs:["watch"]} PolicyRule{Resources:["endpoints"], APIGroups:[""], Verbs:["get"]} PolicyRule{Resources:["endpoints"], APIGroups:[""], Verbs:["create"]} PolicyRule{Resources:["endpoints"], APIGroups:[""], Verbs:["update"]} PolicyRule{Resources:["secrets"], APIGroups:[""], Verbs:["get"]} PolicyRule{Resources:["secrets"], APIGroups:[""], Verbs:["create"]} PolicyRule{Resources:["secrets"], APIGroups:[""], Verbs:["update"]}] user=&{myemail@gmail.com  [system:authenticated] map[]} ownerrules=[PolicyRule{Resources:["selfsubjectaccessreviews" "selfsubjectrulesreviews"], APIGroups:["authorization.k8s.io"], Verbs:["create"]} PolicyRule{NonResourceURLs:["/api" "/api/*" "/apis" "/apis/*" "/healthz" "/swagger-2.0.0.pb-v1" "/swagger.json" "/swaggerapi" "/swaggerapi/*" "/version"], Verbs:["get"]}] ruleResolutionErrors=[]

我尝试了 1.8.6-gke.0、1.8.7-gke.0 和 1.9.2-gke.0。

谢谢。

【问题讨论】:

    标签: kubernetes google-kubernetes-engine


    【解决方案1】:

    正如kube-lego issue 225中评论的那样:

    原来是我在 GKE 1.6 的一个已知问题中收到的错误。我按照这篇文章解决了:

    获取当前的谷歌身份

    $ gcloud info | grep Account
    Account: [myname@example.org]
    

    将 cluster-admin 授予您当前的身份

    $ kubectl create clusterrolebinding myname-cluster-admin-binding --clusterrole=cluster-admin --user=myname@example.org
    Clusterrolebinding "myname-cluster-admin-binding" created
    

    要定义的实际 RBAC,请参阅issue 99

    它指的是Adds official RBAC rules,它应用了正确的设置:

    # RBAC objects
    kubectl apply -f lego/service-account.yaml
    kubectl apply -f lego/cluster-role.yaml
    kubectl apply -f lego/cluster-role-binding.yaml
    

    【讨论】:

    • 这适用于用户帐户(如 myuser@gmail.com),但它不适用于使用默认服务帐户(如 k8s-deployment@xxxxx.iam.gserviceaccount.com)的 GCE VM - clusterrolebinding 创建得很好,但使用它不允许我创建新角色。
    • @Bosh Strange:你能针对这个案例提出一个新问题吗?
    【解决方案2】:

    您来自gcloud info | grep Account 的 Google 帐户电子邮件可能无法正常工作,但我已经解决了这个问题。

    转到Stackdriver Logging,选择合适的kubernetes集群和错误日志级别。

    应用下一个高级过滤器(更改适当的字段):

    resource.type="k8s_cluster"
    resource.labels.location="europe-west1-b"
    resource.labels.cluster_name="your-cluster-name"
    severity>=ERROR
    protoPayload.resourceName="rbac.authorization.k8s.io/v1beta1/clusterroles/prometheus-operator"
    

    你会发现如下错误:

    k8s.io create prometheus-operator 20456435270447878856446 {"@type":"type.googleapis.com/google.cloud.audit.AuditLog","status":{"code": ...
    

    接下来,您需要复制那个长编号的principalEmail。将其粘贴到clusterrolebinding 命令中,作为用户密钥:

    kubectl create clusterrolebinding 20456435270447878856446-cluster-admin-binding --clusterrole=cluster-admin --user=20456435270447878856446
    

    您将能够创建 prometheus-operator 集群角色。

    【讨论】:

    • 老兄,你是我的英雄。谢谢!
    猜你喜欢
    • 2018-10-27
    • 2018-03-28
    • 2016-07-11
    • 1970-01-01
    • 2019-07-13
    • 1970-01-01
    • 2022-09-30
    • 2017-05-07
    • 2018-06-14
    相关资源
    最近更新 更多