mirror of
https://github.com/kubesphere/kubekey.git
synced 2025-12-25 17:12:50 +00:00
97 lines
3.1 KiB
YAML
97 lines
3.1 KiB
YAML
---
|
|
# load defaults vars
|
|
- hosts:
|
|
- all
|
|
vars_files:
|
|
- vars/create_cluster.yaml
|
|
- vars/create_cluster_kubernetes.yaml
|
|
|
|
- import_playbook: hook/pre_install.yaml
|
|
|
|
# precheck
|
|
- hosts:
|
|
- localhost
|
|
roles:
|
|
- role: precheck/artifact_check
|
|
when: and .artifact.artifact_file (ne .artifact.artifact_file "")
|
|
- hosts:
|
|
- k8s_cluster
|
|
- etcd
|
|
- image_registry
|
|
- nfs
|
|
gather_facts: true
|
|
roles:
|
|
- precheck/env_check
|
|
|
|
- hosts:
|
|
- localhost
|
|
gather_facts: true
|
|
roles:
|
|
- init/init-artifact
|
|
|
|
# init os
|
|
- hosts:
|
|
- etcd
|
|
- k8s_cluster
|
|
- registry
|
|
- nfs
|
|
roles:
|
|
- init/init-os
|
|
|
|
- hosts:
|
|
- kube_control_plane
|
|
tasks:
|
|
- name: select init node
|
|
run_once: true
|
|
set_fact:
|
|
init_kubernetes_node: |
|
|
{{- $initNodes := list -}}
|
|
{{- range .groups.kube_control_plane -}}
|
|
{{- if index $.hostvars . "kubernetes_install_service" "stdout" | eq "active" -}}
|
|
{{- $initNodes = append $initNodes . -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
{{- if $initNodes | len | eq 1 -}}
|
|
{{ $initNodes | first }}
|
|
{{- else if $initNodes | len | lt 1 -}}
|
|
{{ index $initNodes (randInt 0 ((sub ($initNodes | len) 1) | int)) }}
|
|
{{- end -}}
|
|
- name: init node
|
|
when: eq .inventory_hostname .init_kubernetes_node
|
|
block:
|
|
- name: Generate certificate key by kubeadm
|
|
command: |
|
|
if [ ! -f /etc/kubernetes/kubeadm-config.yaml ]; then
|
|
kubectl get cm kubeadm-config -n kube-system -o=jsonpath='{.data.ClusterConfiguration}' > /etc/kubernetes/kubeadm-config.yaml
|
|
fi
|
|
/usr/local/bin/kubeadm init phase upload-certs --upload-certs --config /etc/kubernetes/kubeadm-config.yaml 2>&1 \
|
|
| awk '/Using certificate key:/{getline; print}'
|
|
register: kubeadm_cert_result
|
|
- name: Set_Fact certificate key to all hosts
|
|
set_fact:
|
|
kubeadm_cert: |
|
|
{{ .kubeadm_cert_result.stdout }}
|
|
- name: Generate token by kubeadm
|
|
command: /usr/local/bin/kubeadm token create
|
|
register: kubeadm_token_result
|
|
- name: Set_Fact token to all hosts
|
|
set_fact:
|
|
kubeadm_token: |
|
|
{{ .kubeadm_token_result.stdout }}
|
|
|
|
- hosts:
|
|
- k8s_cluster
|
|
roles:
|
|
- role: install/cri
|
|
when: or (.add_nodes | default list | len | eq 0) (.add_nodes | default list | has .inventory_hostname)
|
|
- role: kubernetes/pre-kubernetes
|
|
when: or (.add_nodes | default list | len | eq 0) (.add_nodes | default list | has .inventory_hostname)
|
|
- role: kubernetes/join-kubernetes
|
|
when: or (.add_nodes | default list | len | eq 0) (.add_nodes | default list | has .inventory_hostname)
|
|
- role: kubernetes/certs
|
|
when:
|
|
- or (.add_nodes | default list | len | eq 0) (.add_nodes | default list | has .inventory_hostname)
|
|
- .groups.kube_control_plane | default list | has .inventory_hostname
|
|
- .kubernetes.renew_certs.enabled
|
|
|
|
- import_playbook: hook/post_install.yaml |