mirror of
https://gitea.fenix-dev.com/fenix-gitea-admin/iac-ansible-private.git
synced 2025-10-27 00:33:16 +00:00
v0
This commit is contained in:
23
.gitea/workflows/deploy-k8s.yml
Normal file
23
.gitea/workflows/deploy-k8s.yml
Normal file
@ -0,0 +1,23 @@
|
||||
name: IAC
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ main ]
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
hello:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Cloning ansible repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
path: ansible/iac
|
||||
|
||||
- name: Install Ansible
|
||||
run: sudo apt-get install -y ansible
|
||||
|
||||
- name: Run Ansible Playbook
|
||||
working-directory: ansible/
|
||||
run: |
|
||||
ansible-playbook -i inventory.ini playbook.yml
|
||||
9
inventory.ini
Normal file
9
inventory.ini
Normal file
@ -0,0 +1,9 @@
|
||||
[kube-master]
|
||||
master1 ansible_host=192.168.1.10 ansible_user=ubuntu
|
||||
|
||||
[kube-node]
|
||||
node1 ansible_host=192.168.1.11 ansible_user=ubuntu
|
||||
node2 ansible_host=192.168.1.12 ansible_user=ubuntu
|
||||
|
||||
[all:vars]
|
||||
ansible_python_interpreter=/usr/bin/python3
|
||||
15
playbook.yml
Normal file
15
playbook.yml
Normal file
@ -0,0 +1,15 @@
|
||||
- name: Configure Kubernetes Master
|
||||
hosts: kube-master
|
||||
become: yes
|
||||
roles:
|
||||
- common
|
||||
- kubernetes
|
||||
- kube-master
|
||||
|
||||
- name: Configure Kubernetes Nodes
|
||||
hosts: kube-node
|
||||
become: yes
|
||||
roles:
|
||||
- common
|
||||
- kubernetes
|
||||
- kube-node
|
||||
12
roles/common/tasks/main.yml
Normal file
12
roles/common/tasks/main.yml
Normal file
@ -0,0 +1,12 @@
|
||||
- name: Update apt cache
|
||||
apt:
|
||||
update_cache: yes
|
||||
|
||||
- name: Install basic packages
|
||||
apt:
|
||||
name:
|
||||
- curl
|
||||
- vim
|
||||
- net-tools
|
||||
- gnupg
|
||||
state: present
|
||||
21
roles/kube-master/tasks/main.yml
Normal file
21
roles/kube-master/tasks/main.yml
Normal file
@ -0,0 +1,21 @@
|
||||
- name: Initialize Kubernetes master
|
||||
command: kubeadm init --pod-network-cidr=192.168.1.3/16
|
||||
args:
|
||||
creates: /etc/kubernetes/admin.conf
|
||||
|
||||
- name: Set up kubeconfig for user
|
||||
copy:
|
||||
src: /etc/kubernetes/admin.conf
|
||||
dest: /home/ubuntu/.kube/config
|
||||
remote_src: yes
|
||||
owner: ubuntu
|
||||
group: ubuntu
|
||||
mode: 0644
|
||||
|
||||
- name: Install Calico CNI
|
||||
become: yes
|
||||
become_user: ubuntu
|
||||
shell: |
|
||||
kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml
|
||||
environment:
|
||||
KUBECONFIG: /home/ubuntu/.kube/config
|
||||
3
roles/kube-node/tasks/main.yml
Normal file
3
roles/kube-node/tasks/main.yml
Normal file
@ -0,0 +1,3 @@
|
||||
- name: Join Kubernetes cluster
|
||||
shell: "{{ hostvars['master1']['kubeadm_join_command'] }}"
|
||||
when: hostvars['master1']['kubeadm_join_command'] is defined
|
||||
31
roles/kubernetes/tasks/main.yml
Normal file
31
roles/kubernetes/tasks/main.yml
Normal file
@ -0,0 +1,31 @@
|
||||
- name: Install containerd
|
||||
apt:
|
||||
name: containerd
|
||||
state: present
|
||||
|
||||
- name: Add Kubernetes APT key
|
||||
apt_key:
|
||||
url: https://packages.cloud.google.com/apt/doc/apt-key.gpg
|
||||
state: present
|
||||
|
||||
- name: Add Kubernetes repo
|
||||
apt_repository:
|
||||
repo: deb http://apt.kubernetes.io/ kubernetes-xenial main
|
||||
state: present
|
||||
|
||||
- name: Install Kubernetes components
|
||||
apt:
|
||||
name:
|
||||
- kubelet
|
||||
- kubeadm
|
||||
- kubectl
|
||||
state: present
|
||||
update_cache: yes
|
||||
|
||||
- name: Hold Kubernetes packages
|
||||
apt:
|
||||
name:
|
||||
- kubelet
|
||||
- kubeadm
|
||||
- kubectl
|
||||
state: hold
|
||||
Reference in New Issue
Block a user