forked from easzlab/kubeasz
-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathmain.yml
29 lines (26 loc) · 1.16 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
- 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"