mirror of https://github.com/easzlab/kubeasz.git
30 lines
1.2 KiB
YAML
30 lines
1.2 KiB
YAML
|
- name: 下载kubectl二进制
|
||
|
copy: src={{ base_dir }}/bin/kubectl dest={{ bin_dir }}/kubectl mode=0755
|
||
|
|
||
|
- 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"
|
||
|
|
||
|
# 创建kubectl kubeconfig 文件
|
||
|
- name: 设置集群参数
|
||
|
shell: "{{ bin_dir }}/kubectl config set-cluster kubernetes \
|
||
|
--certificate-authority={{ ca_dir }}/ca.pem \
|
||
|
--embed-certs=true \
|
||
|
--server={{ KUBE_APISERVER }}"
|
||
|
- 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"
|
||
|
- name: 设置上下文参数
|
||
|
shell: "{{ bin_dir }}/kubectl config set-context kubernetes \
|
||
|
--cluster=kubernetes --user=admin"
|
||
|
- name: 选择默认上下文
|
||
|
shell: "{{ bin_dir }}/kubectl config use-context kubernetes"
|