mirror of
https://gitea.fenix-dev.com/fenix-gitea-admin/iac-ansible-private.git
synced 2025-10-27 08:43:05 +00:00
102 lines
2.4 KiB
YAML
102 lines
2.4 KiB
YAML
#- name: Initialize Kubernetes master
|
|
# command: kubeadm init --pod-network-cidr=192.168.3.0/16 --apiserver-advertise-address=192.168.2.50
|
|
# creates: /etc/kubernetes/admin.conf
|
|
- name: Inicializar o cluster com kubeadm
|
|
command:
|
|
argv:
|
|
- kubeadm
|
|
- init
|
|
- --pod-network-cidr=192.168.3.0/16
|
|
- --apiserver-advertise-address=192.168.2.50
|
|
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: 3 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: Fazer download do manifest oficial do Flannel
|
|
get_url:
|
|
url: https://raw.githubusercontent.com/flannel-io/flannel/master/Documentation/kube-flannel.yml
|
|
dest: /tmp/kube-flannel.yml
|
|
|
|
- name: Substituir o CIDR da rede no manifest
|
|
replace:
|
|
path: /tmp/kube-flannel.yml
|
|
regexp: '10\.244\.0\.0/16'
|
|
replace: '192.168.3.0/16'
|
|
|
|
- name: cat flannel
|
|
shell: |
|
|
cat /tmp/kube-flannel.yml
|
|
|
|
- name: Forçar uso da interface correta
|
|
replace:
|
|
path: /tmp/kube-flannel.yml
|
|
regexp: 'command:
|
|
|
|
\[.*?flanneld.*?\]
|
|
|
|
'
|
|
replace: |
|
|
command:
|
|
- /opt/bin/flanneld
|
|
- --ip-masq
|
|
- --kube-subnet-mgr
|
|
- --iface=eth1
|
|
|
|
- name: cat flannel
|
|
shell: |
|
|
cat /tmp/kube-flannel.yml
|
|
|
|
|
|
- name: Aplicar o manifest do Flannel
|
|
shell: |
|
|
kubectl apply -f /tmp/kube-flannel.yml
|
|
environment:
|
|
KUBECONFIG: /etc/kubernetes/admin.conf
|
|
|
|
#- 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 }}" |