首页 > 其他分享 >k8s API account基本操作

k8s API account基本操作

时间:2023-02-23 21:57:44浏览次数:45  
标签:account master01 devops cert API ubuntu 基本操作 k8s vbear

创建cert key

#创建key密钥
openssl genrsa -out vbear.key 2048

#创建证书
openssl req -new -key vbear.key -out vbear.csr -subj "/CN=vbear/O=it"

#申请签名
udo openssl x509 -req -in vbear.csr -CA /etc/kubernetes/pki/ca.crt -CAkey /etc/kubernetes/pki/ca.key  -CAcreateserial -out vbear.crt -days 365
Certificate request self-signature ok
subject=CN = vbear, O = it

#查看contexts
ubuntu@master01:/k8s/cert$ kubectl config get-contexts
CURRENT   NAME                          CLUSTER                       AUTHINFO           NAMESPACE
*         devops-context                kubernetes                    vbear              

#指定证书为用户vbear
 
ubuntu@master01:/k8s/cert$ kubectl config set-credentials vbear --client-certificate=/k8s/cert/vbear.crt --client-key=vbear.key
User "vbear" set.

#查看当前的context
ubuntu@master01:/k8s/cert$ kubectl config current-context
devops-context
ubuntu@master01:/k8s/cert$ kubectl get pods -n devops
NAME    READY   STATUS    RESTARTS   AGE
nginx   1/1     Running   0          10m
ubuntu@master01:/k8s/cert$ 



在devops namespace里面创建账号api-access

#创建namespace
ubuntu@master01:/k8s/cert$ kubectl create namespace devops
namespace/devops created

#创建服务账号api-access
ubuntu@master01:/k8s/cert$ kubectl create serviceaccount api-access -n devops
serviceaccount/api-access created
ubuntu@master01:/k8s/cert$ 

创建角色,并绑定资源

ubuntu@master01:/k8s/cert$ kubectl create role api-clusterrole --verb=watch,list,get  --resource=pods,deployments,services -n devops
role.rbac.authorization.k8s.io/api-clusterrole created
ubuntu@master01:/k8s/cert$ 

ubuntu@master01:/k8s/cert$ kubectl create rolebinding api-clusterrolebinding --role=api-clusterrole --user=vbear -n devops
rolebinding.rbac.authorization.k8s.io/api-clusterrolebinding created

验证结果

ubuntu@master01:/k8s/cert$ curl --cert ./vbear.crt --key ./vbear.key --cacert /etc/kubernetes/pki/ca.crt -s https://192.168.64.84:6443/api/v1/namespaces/devops/pods
{
  "kind": "PodList",
  "apiVersion": "v1",
  "metadata": {
    "resourceVersion": "125896"
  },
  "items": [
    {
      "metadata": {
        "name": "nginx",
        "namespace": "devops",
        "uid": "c666e438-6d4f-4103-ac8b-ca057ffe3f2b",
        "resourceVersion": "125837",
        "creationTimestamp": "2023-02-23T13:32:57Z",
        "labels": {
          "run": "nginx"
        },

标签:account,master01,devops,cert,API,ubuntu,基本操作,k8s,vbear
From: https://www.cnblogs.com/vbear/p/17149588.html

相关文章

  • OpenAI API 参数说明
    OpenAIAPIhttps://platform.openai.com/docs/api-reference/completions/create#completions/create-model  max_tokensintegerOptionalDefaultsto16Themaxi......
  • RESETful API接口设计规范
    开发工作中,我们有时需要提供API接口给客户端或者第三方使用,那么如何构建一个能让使用者快速理解的API是一项重要的工作。如何我们在设计API时就严格遵守一些规范,那么在后面......
  • Centos下KONG API网关实践
    上篇已经安装好了kong​​Centos安装KONG​​一、命令操作kong网关-添加服务和路由services:创建名为service.api的服务,并通过host绑定相应的后端服务upstream.api。cur......
  • 数据服务api加密方式
    md5+签名认证packagecom.alibaba.dt.dataphin;importorg.apache.commons.codec.binary.Base64;importorg.apache.http.Header;importorg.apache.http.HttpRespo......
  • asp.net core webapi之创建项目后切换http/https
    在项目调试过程中如果选择了https则会出现下面问题这时的解决方案为:项目-右键-属性-调试,把原先的https后的s删除即可  ......
  • asp.net core webapi初识
    1.建立webapi项目  2.把启用SSL取消勾选(取消https)  3.选择项目-右键-发布,进行发布信息设置,选择文件夹发布   4.打开IIS管理器,新建网站,物理路径选择刚刚......
  • A Tandem Learning Rule for Effective Training and Rapid Inference of Deep Spikin
    郑重声明:原文参见标题,如有侵权,请联系作者,将会撤销发布!IEEETRANSACTIONSONNEURALNETWORKSANDLEARNINGSYSTEMS,VOL.34,NO.1,JANUARY2023 Abstract脉......
  • docker基本操作
     【1】常见操作本地镜像:dockerimages容器列表:dockerps-a从镜像创建容器:dockerrun...启动所有容器:dockerstart$(dockerps-a|awk'{print$1}'|tail......
  • ABAP 委外采购收货调用过账bapi
    相关的表:ekko:采购凭证抬头表用于判断是否委外ekpo:采购凭证行项目表用于判断是否委外以及委外采购的数量resb:获取委外采购单中bom的相应预留mseg:获取已经委外原材......
  • C# 调用Web Api通用方法
    1.通用方法publicclassGetDataByWebApi{///<summary>///通过webapi获取数据的方法///</summary>///<paramname="url">api的url</param>......