Добавить k8s.yaml
This commit is contained in:
parent
917f554767
commit
2ba26bbc9d
58
k8s.yaml
Normal file
58
k8s.yaml
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
---
|
||||||
|
- name: Deploy Kubernetes manifests from Gitea repository
|
||||||
|
hosts: localhost
|
||||||
|
connection: local
|
||||||
|
vars:
|
||||||
|
kube_config: "~/.kube/config"
|
||||||
|
repo_url: "git@192.168.0.105:jeekkaaaa/testroom.git"
|
||||||
|
repo_version: "main" # Можно изменить на нужную ветку/тег
|
||||||
|
repo_dest: "/tmp/k8s-deploy"
|
||||||
|
namespace: "default" # Можно изменить на нужный namespace
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
- name: Ensure required packages are installed
|
||||||
|
become: yes
|
||||||
|
apt:
|
||||||
|
name:
|
||||||
|
- git
|
||||||
|
- kubectl
|
||||||
|
state: present
|
||||||
|
when: ansible_os_family == 'Debian'
|
||||||
|
|
||||||
|
- name: Clone repository from Gitea
|
||||||
|
git:
|
||||||
|
repo: "{{ repo_url }}"
|
||||||
|
dest: "{{ repo_dest }}"
|
||||||
|
version: "{{ repo_version }}"
|
||||||
|
force: yes
|
||||||
|
register: clone_result
|
||||||
|
retries: 3
|
||||||
|
delay: 10
|
||||||
|
until: clone_result is succeeded
|
||||||
|
|
||||||
|
- name: Validate Kubernetes manifests
|
||||||
|
command: "kubectl apply --dry-run=client -f {{ repo_dest }}/{{ item }}"
|
||||||
|
with_items:
|
||||||
|
- ngpod.yaml
|
||||||
|
- ngserv.yaml
|
||||||
|
register: validate_result
|
||||||
|
changed_when: false
|
||||||
|
|
||||||
|
- name: Deploy ngserv.yaml (Service)
|
||||||
|
k8s:
|
||||||
|
state: present
|
||||||
|
src: "{{ repo_dest }}/ngserv.yaml"
|
||||||
|
namespace: "{{ namespace }}"
|
||||||
|
|
||||||
|
- name: Deploy ngpod.yaml (Pod/Deployment)
|
||||||
|
k8s:
|
||||||
|
state: present
|
||||||
|
src: "{{ repo_dest }}/ngpod.yaml"
|
||||||
|
namespace: "{{ namespace }}"
|
||||||
|
|
||||||
|
- name: Verify deployment status
|
||||||
|
command: "kubectl get -f {{ repo_dest }}/ngpod.yaml -o jsonpath='{.status.phase}'"
|
||||||
|
register: deploy_status
|
||||||
|
until: deploy_status.stdout == "Running" or deploy_status.stdout == "Succeeded"
|
||||||
|
retries: 10
|
||||||
|
delay: 10
|
Loading…
x
Reference in New Issue
Block a user