added initial changes

pull/390/head
= 2025-02-13 15:34:43 +01:00
parent 53ef03ed97
commit 82b3573f1c
11 changed files with 277 additions and 5 deletions

View File

@ -3,17 +3,17 @@ k3s_cluster:
children:
server:
hosts:
10.92.1.84:
10.92.1.139:
ansible_python_interpreter: /usr/bin/python3
agent:
hosts:
10.92.1.195:
10.92.1.244:
ansible_python_interpreter: /usr/bin/python3
10.92.1.44:
10.92.1.142:
ansible_python_interpreter: /usr/bin/python3
10.92.1.146:
10.92.1.155:
ansible_python_interpreter: /usr/bin/python3
10.92.1.22:
10.92.1.166:
ansible_python_interpreter: /usr/bin/python3
# Required Vars
@ -29,6 +29,15 @@ k3s_cluster:
# Or you can omit it if not using Vagrant and let the first server automatically generate one.
token: "bGB6nfxtODef8Y0J4hrLF1XbGoQZA89B1LYVwta+pcIA2FxzGJgzRJWVvrjGnubk"
api_endpoint: "{{ hostvars[groups['server'][0]]['ansible_host'] | default(groups['server'][0]) }}"
yaml:
- autoscaler-deployment.yml
- autoscaler-service.yml
- mysql-pv.yml
- mysql-pvc.yml
- mysql-deployment.yml
- mysql-service.yml
- stregsystemet-deployment.yml
- stregsystemet-service.yml
# Optional vars
# extra_server_args: ""

View File

@ -0,0 +1,29 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: autoscaler-deployment
spec:
selector:
matchLabels:
app: autoscaler
template:
metadata:
labels:
app: autoscaler
spec:
containers:
- name: autoscaler
image: ghcr.io/aau-p9s/autoscaler-frontend:latest
command: ["dotnet"]
args: ["Autoscaler.dll", "--kube-api", "https://kubernetes", "--prometheus-addr", "http://prometheus-server", "--scaler", "./predict.py", "--re-trainer", "./train.py"]
ports:
- containerPort: 8080
resources:
requests:
memory: "2048Mi"
cpu: "500m"
limits:
memory: "32Gi"
cpu: "2000m"

View File

@ -0,0 +1,46 @@
apiVersion: v1
kind: Service
metadata:
creationTimestamp: "2024-09-26T09:36:07Z"
finalizers:
- service.kubernetes.io/load-balancer-cleanup
name: autoscaler
namespace: default
resourceVersion: "809655"
uid: 1f5485f0-a839-472e-9cc6-278c9cdf785c
spec:
allocateLoadBalancerNodePorts: true
clusterIP: 10.43.51.124
clusterIPs:
- 10.43.51.124
externalTrafficPolicy: Cluster
internalTrafficPolicy: Cluster
ipFamilies:
- IPv4
ipFamilyPolicy: SingleStack
ports:
- nodePort: 32422
port: 8080
protocol: TCP
targetPort: 8080
selector:
app: autoscaler
sessionAffinity: None
type: LoadBalancer
status:
loadBalancer:
ingress:
- ip: 10.0.0.100
ipMode: VIP
- ip: 10.0.0.101
ipMode: VIP
- ip: 10.0.0.102
ipMode: VIP
- ip: 10.0.0.103
ipMode: VIP
- ip: 10.0.0.104
ipMode: VIP
- ip: 10.0.0.105
ipMode: VIP
- ip: 10.0.0.200
ipMode: VIP

View File

@ -0,0 +1,32 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: mysql
spec:
selector:
matchLabels:
app: mysql
strategy:
type: Recreate
template:
metadata:
labels:
app: mysql
spec:
containers:
- image: mysql:8.0
name: mysql
env:
- name: MYSQL_ROOT_PASSWORD
value: "1234"
ports:
- containerPort: 3306
name: mysql
volumeMounts:
- name: mysql-persistent-storage
mountPath: /var/lib/mysql
volumes:
- name: mysql-persistent-storage
persistentVolumeClaim:
claimName: mysql-pv-claim

15
kubernetes/mysql-pv.yml Normal file
View File

@ -0,0 +1,15 @@
apiVersion: v1
kind: PersistentVolume
metadata:
name: mysql-pv
labels:
type: local
spec:
storageClassName: manual
capacity:
storage: 5Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/mnt/data"

12
kubernetes/mysql-pvc.yml Normal file
View File

@ -0,0 +1,12 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mysql-pv-claim
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi

View File

@ -0,0 +1,11 @@
apiVersion: v1
kind: Service
metadata:
name: mysql
spec:
ports:
- port: 3306
selector:
app: mysql
clusterIP: 10.43.0.100

View File

@ -0,0 +1,27 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: stregsystemet-deployment
spec:
selector:
matchLabels:
app: stregsystemet
template:
metadata:
labels:
app: stregsystemet
spec:
containers:
- name: stregsystemet
image: ghcr.io/aau-p9s/stregsystemet:latest
ports:
- containerPort: 8000
resources:
requests:
memory: "512Mi"
cpu: "500m"
limits:
memory: "1024Mi"
cpu: "2000m"

View File

@ -0,0 +1,46 @@
apiVersion: v1
kind: Service
metadata:
creationTimestamp: "2024-09-26T09:36:07Z"
finalizers:
- service.kubernetes.io/load-balancer-cleanup
name: stregsystemet
namespace: default
resourceVersion: "809655"
uid: 1f5485f0-a839-472e-9cc6-278c9cdf785c
spec:
allocateLoadBalancerNodePorts: true
clusterIP: 10.43.51.123
clusterIPs:
- 10.43.51.123
externalTrafficPolicy: Cluster
internalTrafficPolicy: Cluster
ipFamilies:
- IPv4
ipFamilyPolicy: SingleStack
ports:
- nodePort: 32421
port: 8000
protocol: TCP
targetPort: 8000
selector:
app: stregsystemet
sessionAffinity: None
type: LoadBalancer
status:
loadBalancer:
ingress:
- ip: 10.0.0.100
ipMode: VIP
- ip: 10.0.0.101
ipMode: VIP
- ip: 10.0.0.102
ipMode: VIP
- ip: 10.0.0.103
ipMode: VIP
- ip: 10.0.0.104
ipMode: VIP
- ip: 10.0.0.105
ipMode: VIP
- ip: 10.0.0.200
ipMode: VIP

View File

@ -19,3 +19,4 @@
become: true
roles:
- role: k3s_agent

View File

@ -303,3 +303,47 @@
path: ~{{ ansible_user }}/.bashrc
regexp: '\.\s+<\(kubectl completion bash\)'
line: ". <(kubectl completion bash) # Added by k3s-ansible"
- name: Copy kubernetes yaml
ansible.builtin.copy:
src: ../../../kubernetes
dest: "/home/{{ ansible_user }}"
- name: Deploy kubernetes yaml
shell: kubectl apply -f /home/{{ ansible_user }}/kubernetes/{{ item }}
ignore_errors: true
loop: "{{ yaml }}"
- name: Install Helm
shell: sudo pacman -S helm --noconfirm
- name: Add helm prometheus repo
shell:
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
- name: Add helm grafana repo
shell:
helm repo add grafana https://grafana.github.io/helm-charts
- name: Update helm repos
shell: helm repo update
- name: Install prometheus Helm Chart
shell:
helm install prometheus prometheus-community/prometheus
ignore_errors: true
- name: Install grafana Helm Chart
shell:
helm install grafana grafana/grafana
ignore_errors: true
- name: expose prometheus service
shell:
kubectl expose service prometheus-server --type=NodePort --target-port=9090 --name=prometheus-server-ext
ignore_errors: true
- name: expose grafana service
shell:
kubectl expose service grafana --type=NodePort --target-port=3000 --name=grafana-ext
ignore_errors: true