2021-01-17 23:59:40 +08:00
|
|
|
- name: 准备kubectl使用的admin证书签名请求
|
|
|
|
template: src=admin-csr.json.j2 dest={{ cluster_dir }}/ssl/admin-csr.json
|
2020-01-29 10:40:27 +08:00
|
|
|
|
2021-01-17 23:59:40 +08:00
|
|
|
- name: 创建admin证书与私钥
|
2020-12-25 11:53:00 +08:00
|
|
|
shell: "cd {{ cluster_dir }}/ssl && {{ base_dir }}/bin/cfssl gencert \
|
2020-01-29 10:40:27 +08:00
|
|
|
-ca=ca.pem \
|
|
|
|
-ca-key=ca-key.pem \
|
|
|
|
-config=ca-config.json \
|
2021-01-17 23:59:40 +08:00
|
|
|
-profile=kubernetes admin-csr.json | {{ base_dir }}/bin/cfssljson -bare admin"
|
2020-01-29 10:40:27 +08:00
|
|
|
|
|
|
|
- name: 设置集群参数
|
|
|
|
shell: "{{ base_dir }}/bin/kubectl config set-cluster {{ CLUSTER_NAME }} \
|
2020-12-25 11:53:00 +08:00
|
|
|
--certificate-authority={{ cluster_dir }}/ssl/ca.pem \
|
2020-01-29 10:40:27 +08:00
|
|
|
--embed-certs=true \
|
2021-01-07 09:30:50 +08:00
|
|
|
--server={{ KUBE_APISERVER }} \
|
|
|
|
--kubeconfig={{ cluster_dir }}/kubectl.kubeconfig"
|
2020-01-29 10:40:27 +08:00
|
|
|
|
|
|
|
- name: 设置客户端认证参数
|
2021-01-17 23:59:40 +08:00
|
|
|
shell: "{{ base_dir }}/bin/kubectl config set-credentials admin \
|
|
|
|
--client-certificate={{ cluster_dir }}/ssl/admin.pem \
|
2020-01-29 10:40:27 +08:00
|
|
|
--embed-certs=true \
|
2021-01-17 23:59:40 +08:00
|
|
|
--client-key={{ cluster_dir }}/ssl/admin-key.pem \
|
2021-01-07 09:30:50 +08:00
|
|
|
--kubeconfig={{ cluster_dir }}/kubectl.kubeconfig"
|
2020-01-29 10:40:27 +08:00
|
|
|
|
|
|
|
- name: 设置上下文参数
|
2020-03-29 10:52:46 +08:00
|
|
|
shell: "{{ base_dir }}/bin/kubectl config set-context {{ CONTEXT_NAME }} \
|
2021-01-17 23:59:40 +08:00
|
|
|
--cluster={{ CLUSTER_NAME }} --user=admin \
|
2021-01-07 09:30:50 +08:00
|
|
|
--kubeconfig={{ cluster_dir }}/kubectl.kubeconfig"
|
2020-01-29 10:40:27 +08:00
|
|
|
|
|
|
|
- name: 选择默认上下文
|
2021-01-07 09:30:50 +08:00
|
|
|
shell: "{{ base_dir }}/bin/kubectl config use-context {{ CONTEXT_NAME }} \
|
|
|
|
--kubeconfig={{ cluster_dir }}/kubectl.kubeconfig"
|
|
|
|
|
|
|
|
- name: 安装kubeconfig
|
|
|
|
copy: src={{ cluster_dir }}/kubectl.kubeconfig dest=~/.kube/config
|