kubeasz/roles/deploy/tasks/create-kubectl-kubeconfig.yml

36 lines
1.5 KiB
YAML
Raw Normal View History

- name: 准备kubectl使用的admin证书签名请求
template: src=admin-csr.json.j2 dest={{ cluster_dir }}/ssl/admin-csr.json
- name: 创建admin证书与私钥
2020-12-25 11:53:00 +08:00
shell: "cd {{ cluster_dir }}/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 }} \
2020-12-25 11:53:00 +08:00
--certificate-authority={{ cluster_dir }}/ssl/ca.pem \
--embed-certs=true \
2021-01-07 09:30:50 +08:00
--server={{ KUBE_APISERVER }} \
--kubeconfig={{ cluster_dir }}/kubectl.kubeconfig"
- name: 设置客户端认证参数
shell: "{{ base_dir }}/bin/kubectl config set-credentials admin \
--client-certificate={{ cluster_dir }}/ssl/admin.pem \
--embed-certs=true \
--client-key={{ cluster_dir }}/ssl/admin-key.pem \
2021-01-07 09:30:50 +08:00
--kubeconfig={{ cluster_dir }}/kubectl.kubeconfig"
- name: 设置上下文参数
shell: "{{ base_dir }}/bin/kubectl config set-context {{ CONTEXT_NAME }} \
--cluster={{ CLUSTER_NAME }} --user=admin \
2021-01-07 09:30:50 +08:00
--kubeconfig={{ cluster_dir }}/kubectl.kubeconfig"
- 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