zoukankan      html  css  js  c++  java
  • Jenkins集成k8s报错:Error testing connection https://kubernetes.default.svc.cluster.local: Failure

    背景:jenkins部署在k8s中的命名空间infra中

     Jenkins集成k8s报错  连接测试报错:

    Error testing connection https://kubernetes.default.svc.cluster.local: Failure executing: GET at: https://kubernetes.default.svc.cluster.local/api/v1/namespaces/defualt/pods. Message: Forbidden!Configured service account doesn't have access. Service account may have been revoked. pods is forbidden: User "system:serviceaccount:infra:default" cannot list resource "pods" in API group "" in the namespace "defualt".

    意思:serviceaccount中 infra:default 没有权限“GET”这个命名空间的 "pods"。权限是“get”对象是“pods”。

    出处:https://www.cnblogs.com/liucx/

    解决办法是:需要给infra:default赋权get去访问pods。

    出处:

    1.新建一个service-reader-cluster-role.yaml
    vi service-reader-cluster-role.yaml

    kind: ClusterRole
    apiVersion: rbac.authorization.k8s.io/v1
    metadata:
      namespace: infra
      name: service-reader
    rules:
      - apiGroups: [""]
        resources: ["services"]
        verbs: ["get", "watch", "list"]
      - apiGroups: [""]
        resources: ["pods"]
        verbs: ["get","list","patch","watch"]

    2.添加serviceacount的binding
    kubectl create clusterrolebinding service-reader-pod --clusterrole=service-reader --serviceaccount=infra:default

    验证:kubectl -n infra get clusterrolebinding|grep service-reader-pod

    然后就可以了。

  • 相关阅读:
    js下拉框二级关联菜单效果代码具体实现
    js实现拉伸拖动iframe的具体代码
    mysql--Ubuntu下设置MySQL字符集为utf8
    python--使用MySQL数据库
    python--笨方法学python 习题52
    python--web.py使用
    python--flask使用
    python--类方法、对象方法、静态方法
    Python--类定义
    堆 在游戏中的运用
  • 原文地址:https://www.cnblogs.com/liucx/p/13214411.html
Copyright © 2011-2022 走看看