zoukankan      html  css  js  c++  java
  • k8s useraccout账号创建及RDBA授权

    # 证书存放位置。
    cd /etc/kubernetes/pki/
    # 做一个私钥,生成hel.key
    (umask 077; openssl genrsa -out hel.key 2048)
    # 基于私钥生成一个证书,生成hel.csr,CN就是用户账号名
    openssl req -new -key hel.key -out hel.csr -subj "/CN=hel"
    # 签发证书,生成hel.crt,-days:表示证书的过期时间,x509:生成x509格式证书,yogacfssl安装的ca证书为ca.pem,私钥为ca-key.pem    
    openssl  x509 -req -in hel.csr -CA ca.crt  -CAkey ca.key  -CAcreateserial -out hel.crt -days 365
    # 查看证书内容
    openssl x509 -in helg.crt -text -noout
    # 把用户账户信息添加到当前集群中,embed-certs=true隐藏证书信息
    kubectl config set-credentials hel --client-certificate=hel.crt --client-key=hel.key --embed-certs=true
    # 设置该用户可以访问kubernetes集群
    kubectl config set-context hel@kubernetes --cluster=kubernetes --user=hel
    # 切换到hel用户,登录k8s,可以看到hel用户没有管理器权限
    kubectl config use-context hel@kubernetes
    # 切回k8s管理员
    kubectl config use-context kubernetes-admin@kubernetes
    # 创建一个新的k8s集群,--kubeconfig:指定集群配置文件存放位置
    kubectl config set-cluster mycluster --kubeconfig=/tmp/test.conf --server="https://127.0.0.1:6443" 
    --certificate-authority=/etc/kubernetes/pki/ca.crt --embed-certs=true
    kubectl config view --kubeconfig=/tmp/test.conf
    

      

    RBAC授权:

    kubectl create role pods-reader --verb=get,list,watch --resource=pods # 想要授予所有权限可以用*来表示
    kubectl get role
    kubectl create rolebinding hel-read-pods --role=pods-reader --user=hel
    kubectl get rolebinding
    kubectl get rolebinding hel-read-pods
    kubectl describe rolebinding hel-read-pods
    kubectl describe role pods-reader
    kubectl config use-context hel@k8s  # 切换账号确认权限
    

      

  • 相关阅读:
    流行的开源分布式文件系统比较
    Linux iostat监测IO状态
    M0n0wall软件防火墙教程
    networkscripts/ifcfg配置详解
    LVM 逻辑卷管理器
    Discuz 6.0数据库结构 四(详)
    Discuz 6.0数据库结构 二(详)
    手动配置linux(centos)的IP地址
    Discuz 6.0数据库结构 五(详)
    lnk快捷方式无法打开解决方法
  • 原文地址:https://www.cnblogs.com/hel7512/p/13175984.html
Copyright © 2011-2022 走看看