Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
孤思冥想
beach
提交
4b5b20be
B
beach
项目概览
孤思冥想
/
beach
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
B
beach
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
4b5b20be
编写于
12月 19, 2022
作者:
孤思冥想
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
kubernetes 集群创建查询用户
上级
d6897d88
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
79 addition
and
0 deletion
+79
-0
k8s/create_view_user.sh
k8s/create_view_user.sh
+79
-0
未找到文件。
k8s/create_view_user.sh
0 → 100644
浏览文件 @
4b5b20be
#!/bin/bash
if
[
$#
-lt
5
]
;
then
echo
"Usage:
$0
{userName clusterName apiServerAddress caKeyPath caCrtPath}"
exit
1
fi
if
[
!
-f
$4
]
;
then
echo
"the ca key file doesn't exist"
exit
1
fi
if
[
!
-f
$5
]
;
then
echo
"the ca key file doesn't exist"
exit
1
fi
userName
=
$1
clusterName
=
$2
apiServer
=
$3
caKeyPath
=
$4
caCrtPath
=
$5
cat
<<
EOF
> clusterRole.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name:
${
userName
}
-cluster-reader
rules:
- apiGroups:
- ""
resources:
- "*"
verbs:
- get
- list
- watch
EOF
cat
<<
EOF
> userRoleBinding.yaml
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
name:
${
userName
}
-read-all
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name:
${
userName
}
-cluster-reader
subjects:
- apiGroup: rbac.authorization.k8s.io
kind: User
name:
${
userName
}
EOF
kubectl apply
-f
clusterRole.yaml
kubectl apply
-f
userRoleBinding.yaml
openssl genrsa
-out
${
userName
}
.key 2048
openssl req
-new
-key
${
userName
}
.key
-out
${
userName
}
.csr
-subj
"/O=K8s/CN=
${
userName
}
"
openssl x509
-req
-in
${
userName
}
.csr
-CA
${
caCrtPath
}
-CAkey
${
caKeyPath
}
-CAcreateserial
-out
${
userName
}
.crt
-days
365
kubectl config set-cluster
${
clusterName
}
--server
=
${
apiServer
}
--certificate-authority
=
${
caCrtPath
}
--embed-certs
=
true
--kubeconfig
=
./
${
userName
}
.conf
kubectl config set-credentials
${
userName
}
--client-certificate
=
${
userName
}
.crt
--client-key
=
${
userName
}
.key
--embed-certs
=
true
--kubeconfig
=
./
${
userName
}
.conf
kubectl config set-context
${
userName
}
@
${
clusterName
}
--cluster
=
${
clusterName
}
--user
=
${
userName
}
--kubeconfig
=
./
${
userName
}
.conf
kubectl config use-context
${
userName
}
@
${
clusterName
}
--kubeconfig
=
./
${
userName
}
.conf
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录