Create and stated write role for deploy k8s cluster

This commit is contained in:
2025-08-24 21:12:59 +03:00
parent 69638a9a69
commit d32a39b1f1
11 changed files with 188 additions and 0 deletions

View File

@ -0,0 +1,44 @@
---
- name: Check if Kubernetes has already been initialized.
stat:
path: /etc/kubernetes/admin.conf
register: k8s_init_stat
- block:
- block:
- name: Create kubeadm-config.yaml
template:
src: kubeadm-config.yaml.j2
dest: "/etc/kubernetes/kubeadm-kubelet-config.yaml"
owner: root
group: root
mode: '0644'
- name: Initialize Kubernetes control plane with kubeadm init
command: >
kubeadm init
--config /etc/kubernetes/kubeadm-kubelet-config.yaml
--upload-certs
register: k8s_init
when: hostvars[inventory_hostname].role_node == "control-first"
- name: Ensure .kube directory exists.
file:
path: ~/.kube
state: directory
mode: 0755
- name: Symlink the kubectl admin.conf to ~/.kube/conf.
file:
src: /etc/kubernetes/admin.conf
dest: ~/.kube/config
state: link
mode: 0644
when: not k8s_init_stat.stat.exists