mirror of https://github.com/easzlab/kubeasz.git
33 lines
1.3 KiB
YAML
33 lines
1.3 KiB
YAML
- name: 删除原有kubeconfig
|
|
file: path=/root/.kube/config state=absent
|
|
ignore_errors: true
|
|
|
|
- name: 准备kubectl使用的admin证书签名请求
|
|
template: src=admin-csr.json.j2 dest={{ base_dir }}/.cluster/ssl/admin-csr.json
|
|
|
|
- name: 创建admin证书与私钥
|
|
shell: "cd {{ base_dir }}/.cluster/ssl && {{ base_dir }}/bin/cfssl gencert \
|
|
-ca=ca.pem \
|
|
-ca-key=ca-key.pem \
|
|
-config=ca-config.json \
|
|
-profile=kubernetes admin-csr.json | {{ base_dir }}/bin/cfssljson -bare admin"
|
|
|
|
- name: 设置集群参数
|
|
shell: "{{ base_dir }}/bin/kubectl config set-cluster {{ CLUSTER_NAME }} \
|
|
--certificate-authority={{ base_dir }}/.cluster/ssl/ca.pem \
|
|
--embed-certs=true \
|
|
--server={{ KUBE_APISERVER }}"
|
|
|
|
- name: 设置客户端认证参数
|
|
shell: "{{ base_dir }}/bin/kubectl config set-credentials admin \
|
|
--client-certificate={{ base_dir }}/.cluster/ssl/admin.pem \
|
|
--embed-certs=true \
|
|
--client-key={{ base_dir }}/.cluster/ssl/admin-key.pem"
|
|
|
|
- name: 设置上下文参数
|
|
shell: "{{ base_dir }}/bin/kubectl config set-context {{ CLUSTER_NAME }} \
|
|
--cluster={{ CLUSTER_NAME }} --user=admin"
|
|
|
|
- name: 选择默认上下文
|
|
shell: "{{ base_dir }}/bin/kubectl config use-context {{ CLUSTER_NAME }}"
|