【问题标题】:kube-apiserver authentification ( Unauthorized )kube-apiserver 认证(未授权)
【发布时间】:2018-12-14 00:08:42
【问题描述】:

我创建了用户 teamcity 以便能够使用 kube-apiserver

kubectl 创建 serviceaccount teamcity

使用下面的命令我得到了秘密名称

kubectl get accourcissements teamcity -o yaml

要查找我使用的最后一个命令生成的令牌

kubectl 获取秘密 teamcity-token-lmr6z -o yaml

当我尝试通过 curl 连接时出现错误,我不明白我的错误在哪里:(

 curl -v -Sskk -H "Authorization: bearer ZXlKaGJH......wWHNIVzZ3" https://10.109.0.88:6443/api/v1/namespaces

 HTTP/1.1 401 Unauthorized
 Content-Type: application/json
 Date: Thu, 05 Jul 2018 13:14:00 GMT
 Content-Length: 165

{
  "kind": "Status",
  "apiVersion": "v1",
  "metadata": {

  },
  "status": "Failure",
  "message": "Unauthorized",
  "reason": "Unauthorized",
  "code": 401
* Connection #0 to host 10.109.0.88 left intact

我在 kubernetes 上找到了关于为什么会出现此错误的简短描述(部分:匿名请求)https://kubernetes.io/docs/reference/access-authn-authz/authentication/

但我仍然不明白我的错误在哪里,因为使用 kubectl 它可以工作

kubectl  --token=ZXlKaGJHY2lPaUpTVXpJ........swWHNIVzZ3 get svc
NAME                       TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)        AGE
hello-kubernetes           NodePort    192.2.0.159   <none>        80:17502/TCP   13d
hello-kubernetes-olivier   NodePort    192.2.0.235   <none>        80:17296/TCP   13d
kubernetes                 ClusterIP   192.2.0.1     <none>        443/TCP        14d 

【问题讨论】:

    标签: kubernetes kubectl minikube


    【解决方案1】:

    “bearer”的部分可能是你的错字,因为我记得它是“bearer”。

    部分命令示例如下,Kubernetes - Accessing Clusters

    $ APISERVER=$(kubectl config view | grep server | cut -f 2- -d ":" | tr -d " ")
    
    $ TOKEN=$(kubectl describe secret $(kubectl get secrets | grep default | cut -f1 -d ' ') | grep -E '^token' | cut -f2 -d':' | tr -d '\t')
    
    $ curl $APISERVER/api --header "Authorization: Bearer $TOKEN" --insecure
    {
      "kind": "APIVersions",
      "versions": [
        "v1"
      ],
      "serverAddressByClientCIDRs": [
        {
          "clientCIDR": "0.0.0.0/0",
          "serverAddress": "10.0.1.149:443"
        }
      ]
    }
    

    【讨论】:

    • 我试试你说的,但不幸的是我有同样的错误
    • curl $APISERVER/api/v1/namespaces/ --header "Authorization: Bearer $TOKEN" --insecure { "kind": "Status", "apiVersion": "v1", "metadata ": { }, "status": "Failure", "message": "命名空间被禁止:用户 \"system:anonymous\" 不能列出集群范围内的命名空间", "reason": "Forbidden", "details" : { "kind": "namespaces" }, "code": 403
    • 但是状态变了,401是未授权到403是禁止的,看来你的token权限不够。
    • 在将 cluster-admin 分配给 serviceaccount 之后可以测试吗? kubernetes.io/docs/reference/access-authn-authz/rbac/…
    猜你喜欢
    • 2022-01-25
    • 2018-07-26
    • 1970-01-01
    • 2019-05-08
    • 2020-12-31
    • 2017-07-15
    • 2018-10-25
    • 1970-01-01
    • 2018-12-11
    相关资源
    最近更新 更多