首页 > 其他分享 >dash-board的kube-config文件怎么设置 就是比kube-proxy类似多了一个token选项

dash-board的kube-config文件怎么设置 就是比kube-proxy类似多了一个token选项

时间:2023-04-04 16:23:39浏览次数:46  
标签:kubectl kubernetes -- magedu dash token role kube

https://kubernetes.io/zh/docs/reference/access-authn-authz/rbac/ #使用RBAC鉴权
  RBAC是基于角色的访问控制(Role-Based Access Control)
https://kubernetes.io/zh/docs/reference/access-authn-authz/authorization/ #鉴权概述

1.1:在指定namespace创建账户:
# kubectl create serviceaccount magedu -n  magedu
serviceaccount/magedu created

1.2:创建role规则:
# kubectl apply  -f magedu-role.yaml 
role.rbac.authorization.k8s.io/magedu-role created

# cat magedu-role.yaml 
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  namespace: magedu
  name: magedu-role
rules:
- apiGroups: ["*"]
  resources: ["pods","pods/exec"]
  verbs: ["*"]
  ##RO-Role
  #verbs: ["get", "watch", "list"]
- apiGroups: ["extensions", "apps/v1"]
  resources: ["deployments"]
  verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]
  ##RO-Role
  #verbs: ["get", "watch", "list"]
  
  

1.3:将规则与账户进行绑定:
# kubectl apply  -f magedu-role-bind.yaml 
rolebinding.rbac.authorization.k8s.io/role-bind-magedu created

# cat magedu-role-bind.yaml 
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: role-bind-magedu
  namespace: magedu
subjects:
- kind: ServiceAccount
  name: magedu
  namespace: magedu
roleRef:
  kind: Role
  name: magedu-role
  apiGroup: rbac.authorization.k8s.io



1.4:获取token名称:
#  kubectl get secret -n  magedu | grep magedu
magedu-token-8d897    kubernetes.io/service-account-token   3      5m45s


1.5:使用base加密:
# kubectl get secret magedu-token-8d897 -o jsonpath={.data.token} -n magedu |base64 -d
eyJhbGciOiJSUzI1NiIsImtpZCI6IlYwMDNHdWJwTmtoaTJUMFRPTVlwV3RiVWFWczJYRHJCNkFkMGRtQWFqRTgifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJtYWdlZHUiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlY3JldC5uYW1lIjoibWFnZWR1LXRva2VuLThkODk3Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQubmFtZSI6Im1hZ2VkdSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50LnVpZCI6IjBlZmNiNGI0LWM3YTUtNGJkZS1iZjk4LTFiNTkwNThjOTFjNiIsInN1YiI6InN5c3RlbTpzZXJ2aWNlYWNjb3VudDptYWdlZHU6bWFnZWR1In0.SJHLgshKcGtIf-ycivn_4SWVRdWw4SuWymBVaA8YJXHPd5PYnwERVNtfUPX88nv-wXkCuZY7fIjGYkoYj6AJEhSPoG15fcmUPaojYeyjkQYghan3CBsZR8C12buSB6t5zCCt22GdG_ScZymxLU7n3Z0PhOzTLzgpXRs1Poqz4DOYylqZyLmW_BPgoNhtQYKlBH6OFzDe8v3JytnaaJUObVZCRxtI6x4iKLt2Evhs8XKfczqqesgoo61qTqtbU4jzlXuHeW7cUMhWoipUc-BkEdV6OtKWOetecxu5uB-44eTRHa1FBjnRMv9SEGj0hxTJCQ08ZNlP0Kc01JZlKXBGdQroot@k8s-master1:~/role/magedu-RBAC#


1.6:登录dashboard测试:

pods "magedu-tomcat-app1-deployment-798fc69b75-rc7l5" is forbidden: User "system:serviceaccount:magedu:magedu" cannot create resource "pods/exec" in API group "" in the namespace "magedu"

二:基于kube-config文件登录:
2.1:创建csr文件:
# cat magedu-csr.json 
{
  "CN": "China",
  "hosts": [],
  "key": {
    "algo": "rsa",
    "size": 2048
  },
  "names": [
    {
      "C": "CN",
      "ST": "BeiJing",
      "L": "BeiJing",
      "O": "k8s",
      "OU": "System"
    }
  ]
}


2.2:签发证书:

# ln -sv /etc/kubeasz/bin/cfssl* /usr/bin/
# cfssl gencert -ca=/etc/kubernetes/ssl/ca.pem  -ca-key=/etc/kubernetes/ssl/ca-key.pem -config=/etc/kubeasz/clusters/k8s-01/ssl/ca-config.json -profile=kubernetes user1-csr.json | cfssljson -bare  user1



# ls magedu*
magedu-csr.json  magedu-key.pem  magedu-role-bind.yaml  magedu-role.yaml  magedu.csr  magedu.pem

2.3:生成普通用户kubeconfig文件:
# kubectl config set-cluster cluster1 --certificate-authority=/etc/kubernetes/ssl/ca.pem --embed-certs=true --server=https://172.31.7.188:6443 --kubeconfig=user1.kubeconfig #--embed-certs=true为嵌入证书信息

2.4:设置客户端认证参数:
# cp *.pem /etc/kubernetes/ssl/
# kubectl config set-credentials user1 \
--client-certificate=/etc/kubernetes/ssl/user1.pem \
--client-key=/etc/kubernetes/ssl/user1-key.pem \
--embed-certs=true \
--kubeconfig=user1.kubeconfig


2.5:设置上下文参数(多集群使用上下文区分)
https://kubernetes.io/zh/docs/concepts/configuration/organize-cluster-access-kubeconfig/

# kubectl config set-context cluster1 \
--cluster=cluster1 \
--user=user1 \
--namespace=magedu \
--kubeconfig=user1.kubeconfig


2.5: 设置默认上下文
# kubectl config use-context cluster1 --kubeconfig=user1.kubeconfig

2.7:获取token:
# kubectl  get secrets  -n magedu | grep magedu
# kubectl  describe   secrets magedu-token-8d897  -n  magedu
token:      eyJhbGciOiJSUzI1NiIsImtpZCI6IlYwMDNHdWJwTmtoaTJUMFRPTVlwV3RiVWFWczJYRHJCNkFkMGRtQWFqRTgifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJtYWdlZHUiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlY3JldC5uYW1lIjoibWFnZWR1LXRva2VuLThkODk3Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQubmFtZSI6Im1hZ2VkdSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50LnVpZCI6IjBlZmNiNGI0LWM3YTUtNGJkZS1iZjk4LTFiNTkwNThjOTFjNiIsInN1YiI6InN5c3RlbTpzZXJ2aWNlYWNjb3VudDptYWdlZHU6bWFnZWR1In0.SJHLgshKcGtIf-ycivn_4SWVRdWw4SuWymBVaA8YJXHPd5PYnwERVNtfUPX88nv-wXkCuZY7fIjGYkoYj6AJEhSPoG15fcmUPaojYeyjkQYghan3CBsZR8C12buSB6t5zCCt22GdG_ScZymxLU7n3Z0PhOzTLzgpXRs1Poqz4DOYylqZyLmW_BPgoNhtQYKlBH6OFzDe8v3JytnaaJUObVZCRxtI6x4iKLt2Evhs8XKfczqqesgoo61qTqtbU4jzlXuHeW7cUMhWoipUc-BkEdV6OtKWOetecxu5uB-44eTRHa1FBjnRMv9SEGj0hxTJCQ08ZNlP0Kc01JZlKXBGdQ


2.8:将token写入用户kube-config文件:


3.9:dashboard登录测试:
https://xxxxx:30002/#/login

 

标签:kubectl,kubernetes,--,magedu,dash,token,role,kube
From: https://www.cnblogs.com/gaoyuechen/p/17286813.html

相关文章

  • npm报错 npm ERR! Unexpected token '.'
    报错如下图:  报错原因:node版本太高解决办法:卸载node重新安装,或者使用nvm切换版本 mvm安装使用教程:https://www.cnblogs.com/tianxinya/p/17286467.html......
  • KubeSphere——使用deployment文件部署实战(3)
    摘要如果没有KubeSphere可视化界面,同样也能保持部署的能力。因此使用deployment文件来部署的相关应用。Deployment对象,顾名思义,是用于部署应用的对象。它使Kubernetes中最常用的一个对象,它为ReplicaSet和Pod的创建提供了一种声明式的定义方法,从而无需像前两篇文章中那样手动创建Rep......
  • Kubernetes——问题与解决方案一、k8s重启报错 :The connection to the server 192.168
    摘要Kubernetes运行过程中出现的各种问题,因此本人整理出本人遇到的有关于的k8s的相关问题和解决方案一、k8s重启报错:Theconnectiontotheserver192.168.102.149:6443wasrefused1.1现象k8s重启报错#kubectlgetpodsTheconnectiontotheserverxxx:6443wasrefused......
  • Angular 应用里 server.ts 文件的 APP_BASE_HREF token 的用法?
    Angular应用里server.ts文件,下面这段代码的含义?server.get('*',(req,res)=>{res.render(indexHtml,{req,providers:[{provide:APP_BASE_HREF,useValue:req.baseUrl}],});});在Angular应用中,server.ts文件是用于构建服务器端渲染(S......
  • 3、kubernetes各种port
    K8s中nodePort、port、targetPort、hostPort介绍1、nodeport外部流量访问k8s集群中service入口的一个方式(还有一种是loadbalancer)nodeIP:nodePort提供给外部流量访问k8s集群中service一个入口比如外部用户要访问k8s集群中的一个Web应用,那么我们可以配置对应service的type=Nod......
  • 2、kubernetes资源管理
    四、资源管理介绍k8s本质上是一个集群系统,用户可以在集群中部署各种服务,部署服务(其实就是在k8s集群中运行一个个容器,并将指定的程序跑在容器中)k8s的最小管理单元是pod不是容器,所以只能将容器放在pod中,而k8s一般不会直接管理pod,而是通过pod控制器来管理的pod的pod可以提供服务之......
  • 1h玩转kubernetes
    学习k8s就跟学习office三件套上,95%的人只会5%,而5%的知识可以干95%的事情,所以不要觉的k8s难1kubernetes1什么是kubernetesKubernetes是一个可移植、可扩展的开源平台,一个分布式资源调度进行容器编排云原生的操作系统,用于管理容器化的工作负载和服务,可促进声明式配置和自动化......
  • PHP实现JWT lcobucci/jwt生成jwt token
    github:https://github.com/lcobucci/jwt/tree/3.21.安装PHP5.5+(v3.2)andPHP7.1(v4.x)OpenSSLExtension"lcobucci/jwt":"^3.3"composerrequirelcobucci/jwt2.一些参数说明iss【issuer】发布者的url地址sub【subject】该JWT所面向的用户,用于处理特定应用,不是常......
  • k8s work节点重新获取token
    在master节点重新生成token命令,然后在node子节点中执行kubuadmjoin命令kubeadmtokencreate--print-join-command如果网忘了证书的秘钥,可以在master节点执行以下命令opensslx509-pubkey-in/etc/kubernetes/pki/ca.crt|opensslrsa-pubin-outformder2>/dev/null......
  • 让应用交付和管理统一:KubeVela 亮点功能及核心技术回顾
    作者: 殷达(晖树)自2020 年OAM(OpenApplicationModel) 开放应用模型发布以来,KubeVela经历了数十个版本的更新和演变,朝着现代化应用交付的高级功能不断发展。今天,我们将回顾KubeVela项目发展至今的亮点功能和核心技术。什么是KubeVela?KubeVela是一个面向现代化应用的交......