kubeasz/roles/kube-node/tasks/create-kubelet-kubeconfig.yml

48 lines
2.1 KiB
YAML
Raw Normal View History

- block:
- name: 准备kubelet 证书签名请求
2023-01-15 21:41:45 +08:00
template: src=kubelet-csr.json.j2 dest={{ cluster_dir }}/ssl/{{ K8S_NODENAME }}-kubelet-csr.json
- name: 创建 kubelet 证书与私钥
shell: "cd {{ cluster_dir }}/ssl && {{ base_dir }}/bin/cfssl gencert \
-ca=ca.pem \
-ca-key=ca-key.pem \
-config=ca-config.json \
2023-01-15 21:41:45 +08:00
-profile=kubernetes {{ K8S_NODENAME }}-kubelet-csr.json | {{ base_dir }}/bin/cfssljson -bare {{ K8S_NODENAME }}-kubelet"
- name: 设置集群参数
shell: "{{ base_dir }}/bin/kubectl config set-cluster kubernetes \
--certificate-authority={{ cluster_dir }}/ssl/ca.pem \
--embed-certs=true \
--server={{ KUBE_APISERVER }} \
2023-01-15 21:41:45 +08:00
--kubeconfig={{ cluster_dir }}/{{ K8S_NODENAME }}-kubelet.kubeconfig"
- name: 设置客户端认证参数
2023-01-15 21:41:45 +08:00
shell: "{{ base_dir }}/bin/kubectl config set-credentials system:node:{{ K8S_NODENAME }} \
--client-certificate={{ cluster_dir }}/ssl/{{ K8S_NODENAME }}-kubelet.pem \
--embed-certs=true \
2023-01-15 21:41:45 +08:00
--client-key={{ cluster_dir }}/ssl/{{ K8S_NODENAME }}-kubelet-key.pem \
--kubeconfig={{ cluster_dir }}/{{ K8S_NODENAME }}-kubelet.kubeconfig"
- name: 设置上下文参数
shell: "{{ base_dir }}/bin/kubectl config set-context default \
--cluster=kubernetes \
2023-01-15 21:41:45 +08:00
--user=system:node:{{ K8S_NODENAME }} \
--kubeconfig={{ cluster_dir }}/{{ K8S_NODENAME }}-kubelet.kubeconfig"
2021-01-12 11:01:19 +08:00
- name: 选择默认上下文
shell: "{{ base_dir }}/bin/kubectl config use-context default \
2023-01-15 21:41:45 +08:00
--kubeconfig={{ cluster_dir }}/{{ K8S_NODENAME }}-kubelet.kubeconfig"
2021-01-12 11:32:48 +08:00
connection: local
- name: 分发ca 证书
copy: src={{ cluster_dir }}/ssl/ca.pem dest={{ ca_dir }}/ca.pem
- name: 分发kubelet 证书
2023-01-15 21:41:45 +08:00
copy: src={{ cluster_dir }}/ssl/{{ K8S_NODENAME }}-{{ item }} dest={{ ca_dir }}/{{ item }}
2021-01-12 11:32:48 +08:00
with_items:
- kubelet.pem
- kubelet-key.pem
- name: 分发kubeconfig
2023-01-15 21:41:45 +08:00
copy: src={{ cluster_dir }}/{{ K8S_NODENAME }}-kubelet.kubeconfig dest=/etc/kubernetes/kubelet.kubeconfig