Skip to content

Commit

Permalink
feat: add and update playbooks
Browse files Browse the repository at this point in the history
  • Loading branch information
dbbDylan committed Sep 29, 2024
1 parent fc6c8b5 commit d5157f8
Show file tree
Hide file tree
Showing 13 changed files with 501 additions and 11 deletions.
19 changes: 19 additions & 0 deletions builtin/playbooks/capkk_binary_install.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
- name: Binary Install
hosts:
- k8s_cluster
- nfs
- image_registry
gather_facts: true
tasks:
- name: NFS Install
hosts:
- nfs
roles:
- install/nfs

- name: Image Registry Install
hosts:
- image_registry
roles:
- install/image-registry
33 changes: 33 additions & 0 deletions builtin/playbooks/capkk_bootstrap_ready.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
- name: BootStrap Ready
hosts:
- kube_control_plane
- kube_worker
tasks:
- name: Kubernetes Install
hosts:
- k8s_cluster
vars_files:
- vars/registry_configuration.yaml
gather_facts: true
roles:
- install/cri
- install/kubernetes

- name: Certs Distribution
hosts:
- kube_control_plane
roles:
- role: install/certs
when: .renew_certs.enabled

- name: Install CNI
hosts:
- kube_control_plane|random
roles:
- addons/cni
- addons/kata
- addons/nfd
- addons/sc

- import_playbook: hook/post_install.yaml
11 changes: 11 additions & 0 deletions builtin/playbooks/capkk_check_connect.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
- name: Check Connect
hosts: all
ignore_errors: true
tasks:
- name: Check Connect for Hosts
when: .inventory_name | ne "localhost"
command: echo 1
# post_tasks:
# - name: Compute Respond Time for Hosts
# command: ping -c 1 -W 1 k8s-master-node | grep time= | awk '{print $8}' | cut -d'=' -f2
108 changes: 108 additions & 0 deletions builtin/playbooks/capkk_delete_cluster.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
---
- name: Uninstall Kubernetes Cluster
hosts: all
become: yes
gather_facts: no
tasks:
- name: Check if node is a control plane
stat:
path: /etc/kubernetes/manifests/kube-apiserver.yaml
register: is_control_plane

- name: Stop and disable kubelet service
systemd:
name: kubelet
state: stopped
enabled: no

- name: Reset kubeadm (if installed)
shell: kubeadm reset -f
ignore_errors: true

- name: Remove Kubernetes directories
file:
path: "{{ item }}"
state: absent
with_items:
- /etc/kubernetes/
- /var/lib/kubelet/
- /var/lib/etcd/
- /etc/cni/net.d/
- /var/lib/cni/

- name: Flush iptables rules
command: iptables -F

- name: Delete iptables chains
command: iptables -X

- name: Flush iptables NAT table
command: iptables -t nat -F

- name: Delete iptables NAT table chains
command: iptables -t nat -X

- name: Flush iptables mangle table
command: iptables -t mangle -F

- name: Delete iptables mangle table chains
command: iptables -t mangle -X

- name: Flush iptables raw table
command: iptables -t raw -F

- name: Delete iptables raw table chains
command: iptables -t raw -X

- name: Clear IPVS rules
command: ipvsadm -C
ignore_errors: true

- name: Set ip_forward to 1
sysctl:
name: net.ipv4.ip_forward
value: 1
state: present

- name: Enable bridge-nf-call-iptables
sysctl:
name: net.bridge.bridge-nf-call-iptables
value: 1
state: present

- name: Enable bridge-nf-call-ip6tables
sysctl:
name: net.bridge.bridge-nf-call-ip6tables
value: 1
state: present

- name: Remove CNI plugins
file:
path: /opt/cni/bin
state: absent

- name: Purge Kubernetes packages
apt:
name: "{{ item }}"
state: absent
purge: yes
with_items:
- kubelet
- kubectl
- kubeadm

- name: Autoremove unused packages
apt:
name: "*"
state: latest
autoremove: yes

- name: Autoclean package cache
apt:
autoclean: yes

- name: Remove etcd data (for control plane nodes only)
file:
path: /var/lib/etcd
state: absent
when: is_control_plane.stat.exists
24 changes: 24 additions & 0 deletions builtin/playbooks/capkk_etcd_binary_install.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
- name: ETCD Binary Install
hosts:
- etcd
gather_facts: true
var_files:
- vars/cluster_requirements.yaml
tasks:
- name: Stop if arch supported
assert:
that: or (.cluster_require.supported_architectures.amd64 | has .os.architecture) (.cluster_require.supported_architectures.arm64 | has .os.architecture)
success_msg: |
{{- if .cluster_require.supported_architectures.amd64 | has .os.architecture }}
amd64
{{- else }}
arm64
{{- end }}
fail_msg: "{{ .os.architecture }} is not a known arch"
register: binary_type

- name: ETCD Binary Install
gather_facts: true
roles:
- install/etcd
28 changes: 28 additions & 0 deletions builtin/playbooks/capkk_preparation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
- import_playbook: hook/pre_install.yaml

- name: Environment PreCheck
gather_facts: true
hosts:
- k8s_cluster
- etcd
- image_registry
- nfs
tags: [ "always" ]
roles:
- precheck/env_check

- name: Initialize OS
gather_facts: true
hosts:
- k8s_cluster
- etcd
- image_registry
roles:
- init/init-os

- name: Download Artifacts
hosts:
- localhost
roles:
- init/init-artifact
10 changes: 5 additions & 5 deletions builtin/playbooks/create_cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
roles:
- install/etcd

- hosts:
- image_registry
gather_facts: true
roles:
- install/image-registry
#- hosts:
# - image_registry
# gather_facts: true
# roles:
# - install/image-registry

- hosts:
- k8s_cluster
Expand Down
3 changes: 3 additions & 0 deletions builtin/playbooks/hook/post_install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
dest: |
/etc/kubekey/scripts/post_install_{{ .inventory_name }}.sh
mode: 0755
register: execute_result

- name: Execute post install scripts
when: .execute_result.stderr | eq ""
command: |
for file in /etc/kubekey/scripts/post_install_*.sh; do
if [ -f $file ]; then
Expand Down
3 changes: 3 additions & 0 deletions builtin/playbooks/hook/pre_install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
dest: |
/etc/kubekey/scripts/pre_install_{{ .inventory_name }}.sh
mode: 0755
register: execute_result

- name: Execute pre install scripts
when: .execute_result.stderr | eq ""
command: |
for file in /etc/kubekey/scripts/pre_install_*.sh; do
if [ -f $file ]; then
Expand Down
8 changes: 8 additions & 0 deletions builtin/playbooks/vars/cluster_requirements.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cluster_require:
supported_architectures:
amd64:
- amd64
- x86_64
arm64:
- arm64
- aarch64
Loading

0 comments on commit d5157f8

Please sign in to comment.