mirror of
https://gitea.fenix-dev.com/fenix-gitea-admin/iac-ansible-private.git
synced 2025-10-27 16:53:04 +00:00
68 lines
1.7 KiB
YAML
68 lines
1.7 KiB
YAML
- name: Inicializar o cluster com kubeadm
|
|
command:
|
|
argv:
|
|
- kubeadm
|
|
- init
|
|
- --pod-network-cidr=192.168.3.0/16
|
|
- --apiserver-advertise-address=192.168.1.150
|
|
- --cri-socket=unix:///run/containerd/containerd.sock
|
|
creates: /etc/kubernetes/admin.conf
|
|
- name: Verificar se o diretório .kube já existe
|
|
stat:
|
|
path: /home/fenix/.kube
|
|
register: kube_dir
|
|
|
|
|
|
- name: Criar diretório .kube para o usuário ubuntu
|
|
ansible.builtin.file:
|
|
path: /home/fenix/.kube
|
|
state: directory
|
|
owner: fenix
|
|
group: ubuntu
|
|
mode: 0755
|
|
when: not kube_dir.stat.exists
|
|
|
|
- name: Set up kubeconfig for user
|
|
copy:
|
|
src: /etc/kubernetes/admin.conf
|
|
dest: /home/fenix/.kube/config
|
|
remote_src: yes
|
|
owner: fenix
|
|
group: ubuntu
|
|
mode: 0644
|
|
when: not kube_dir.stat.exists
|
|
|
|
- name: 33 Wait for Kubernetes API to be ready
|
|
shell: |
|
|
kubectl get --raw='/healthz'
|
|
environment:
|
|
KUBECONFIG: /home/fenix/.kube/config
|
|
register: api_health
|
|
until: api_health.rc == 0
|
|
retries: 10
|
|
delay: 6
|
|
become: yes
|
|
|
|
- name: Install Calico CNI
|
|
become: yes
|
|
become_user: fenix
|
|
shell: |
|
|
kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.30.3/manifests/tigera-operator.yaml
|
|
environment:
|
|
KUBECONFIG: /home/fenix/.kube/config
|
|
|
|
- name: Install Calico CNI
|
|
become: yes
|
|
become_user: fenix
|
|
shell: |
|
|
kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml
|
|
environment:
|
|
KUBECONFIG: /home/fenix/.kube/config
|
|
|
|
- name: Get kubeadm join command
|
|
shell: kubeadm token create --print-join-command
|
|
register: join_cmd
|
|
|
|
- name: Set join command as fact
|
|
set_fact:
|
|
kubeadm_join_command: "{{ join_cmd.stdout }}" |