add kubernetes

This commit is contained in:
Bartal Læarsson
2025-02-27 23:01:21 +00:00
parent ccdc52070b
commit d8813b2428
17 changed files with 774 additions and 1 deletions
+36
View File
@@ -0,0 +1,36 @@
---
# ansible/playbooks/kubernetes.yml
- name: Common configuration for all nodes
hosts: k8s_cluster
become: yes
tags:
- common
tasks:
- include_tasks: ../tasks/kubernetes/setup-hosts.yml
- include_tasks: ../tasks/kubernetes/update-dns.yml
- include_tasks: ../tasks/kubernetes/ssh.yml
- include_tasks: ../tasks/kubernetes/setup-kernel.yml
- name: Kubernetes setup for all nodes
hosts: k8s_cluster
become: yes
tags:
- k8s-setup
tasks:
- include_tasks: ../tasks/kubernetes/node-setup.yml
- name: Initialize Kubernetes control plane
hosts: control_plane
become: yes
tags:
- control-plane
tasks:
- include_tasks: ../tasks/kubernetes/control-plane-init.yml
- name: Join worker nodes to cluster
hosts: workers
become: yes
tags:
- workers
tasks:
- include_tasks: ../tasks/kubernetes/worker-join.yml
+96
View File
@@ -0,0 +1,96 @@
---
- name: Configure PostgreSQL Primary
hosts: postgres_primary
become: true
tasks:
- name: Install PostgreSQL
apt:
name: postgresql
state: present
update_cache: yes
- name: Ensure PostgreSQL is running
service:
name: postgresql
state: started
enabled: yes
- name: Create test database
become: true
# Replace the direct become_user with a shell command that uses sudo
shell: |
sudo -u postgres psql -c "CREATE DATABASE testdb WITH OWNER = postgres ENCODING = 'UTF8' LC_COLLATE = 'en_US.UTF-8' LC_CTYPE = 'en_US.UTF-8' TEMPLATE = template0;"
# Only run this if the database doesn't already exist
register: db_creation
changed_when: db_creation.rc == 0
failed_when: db_creation.rc != 0 and "already exists" not in db_creation.stderr
# The following approach handles error gracefully if DB already exists
args:
executable: /bin/bash
# Rest of the playbook remains the same
- name: Configure PostgreSQL Replicas
hosts: postgres_replicas
become: true
tasks:
- name: Install PostgreSQL
apt:
name: postgresql
state: present
update_cache: yes
- name: Ensure PostgreSQL is running
service:
name: postgresql
state: started
enabled: yes
- name: Configure Load Balancer
hosts: postgres_lb
become: true
tasks:
- name: Install HAProxy
apt:
name: haproxy
state: present
update_cache: yes
- name: Create simple HAProxy configuration
copy:
dest: /etc/haproxy/haproxy.cfg
content: |
global
log /dev/log local0
log /dev/log local1 notice
chroot /var/lib/haproxy
stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners
stats timeout 30s
user haproxy
group haproxy
daemon
defaults
log global
mode tcp
option tcplog
option dontlognull
timeout connect 5000
timeout client 50000
timeout server 50000
frontend postgresql
bind *:5432
mode tcp
default_backend postgresql_backends
backend postgresql_backends
mode tcp
balance roundrobin
server primary {{ hostvars[groups['postgres_primary'][0]]['ansible_host'] }}:5432 check
backup: yes
- name: Restart HAProxy
service:
name: haproxy
state: restarted
enabled: yes