mirror of https://github.com/easzlab/kubeasz.git
更新生成kubeconfig脚本与文档
parent
b542542163
commit
43de866aa5
|
@ -59,6 +59,11 @@ kubeconfig 为与apiserver交互使用的认证配置文件,如脚本步骤需
|
|||
|
||||
创建完成后生成默认配置文件为 `~/.kube/config`
|
||||
|
||||
## 恢复 admin 权限
|
||||
|
||||
- 可以恢复之前备份的`~/.kubeadmin`文件:`mv ~/.kube ~/.kuberead && mv ~/.kubeadmin ~/.kube`
|
||||
- 或者直接执行 `ansible-playbook /etc/ansible/roles/deploy/create-admin-kubeconfig.yml`
|
||||
|
||||
## 参考
|
||||
|
||||
- [Using RBAC Authorization](https://kubernetes.io/docs/reference/access-authn-authz/rbac/)
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
- hosts: deploy
|
||||
tasks:
|
||||
- name: 删除原有kubeconfig
|
||||
file: path=/root/.kube state=absent
|
||||
|
||||
- name: 准备kubectl使用的admin 证书签名请求
|
||||
template: src=admin-csr.json.j2 dest={{ ca_dir }}/admin-csr.json
|
||||
|
||||
- name: 创建 admin证书与私钥
|
||||
shell: "cd {{ ca_dir }} && {{ bin_dir }}/cfssl gencert \
|
||||
-ca={{ ca_dir }}/ca.pem \
|
||||
-ca-key={{ ca_dir }}/ca-key.pem \
|
||||
-config={{ ca_dir }}/ca-config.json \
|
||||
-profile=kubernetes admin-csr.json | {{ bin_dir }}/cfssljson -bare admin"
|
||||
# 设置集群参数,指定CA证书和apiserver地址
|
||||
- name: 设置集群参数
|
||||
shell: "{{ bin_dir }}/kubectl config set-cluster kubernetes \
|
||||
--certificate-authority={{ ca_dir }}/ca.pem \
|
||||
--embed-certs=true \
|
||||
--server={{ KUBE_APISERVER }}"
|
||||
# 设置客户端认证参数,指定使用admin证书和私钥
|
||||
- name: 设置客户端认证参数
|
||||
shell: "{{ bin_dir }}/kubectl config set-credentials admin \
|
||||
--client-certificate={{ ca_dir }}/admin.pem \
|
||||
--embed-certs=true \
|
||||
--client-key={{ ca_dir }}/admin-key.pem"
|
||||
# 设置上下文参数,说明使用cluster集群和用户admin
|
||||
- name: 设置上下文参数
|
||||
shell: "{{ bin_dir }}/kubectl config set-context kubernetes \
|
||||
--cluster=kubernetes --user=admin"
|
||||
# 选择默认上下文
|
||||
- name: 选择默认上下文
|
||||
shell: "{{ bin_dir }}/kubectl config use-context kubernetes"
|
|
@ -9,6 +9,9 @@
|
|||
- name: 创建group:read rbac 绑定
|
||||
shell: "{{ bin_dir }}/kubectl apply -f /opt/kube/kube-system/read-group-rbac.yaml"
|
||||
|
||||
- name: 删除原有kubeconfig
|
||||
file: path=/root/.kube state=absent
|
||||
|
||||
# 创建readonly kubectl kubeconfig文件: /root/.kube/config
|
||||
- name: 准备kubectl使用的read 证书签名请求
|
||||
template: src=read-csr.json.j2 dest={{ ca_dir }}/read-csr.json
|
||||
|
|
Loading…
Reference in New Issue