Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| cad7c23dac | |||
| bdd139b34a |
6
.project
6
.project
@@ -5,7 +5,13 @@
|
|||||||
<projects>
|
<projects>
|
||||||
</projects>
|
</projects>
|
||||||
<buildSpec>
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.python.pydev.PyDevBuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
</buildSpec>
|
</buildSpec>
|
||||||
<natures>
|
<natures>
|
||||||
|
<nature>org.python.pydev.pythonNature</nature>
|
||||||
</natures>
|
</natures>
|
||||||
</projectDescription>
|
</projectDescription>
|
||||||
|
|||||||
5
.pydevproject
Normal file
5
.pydevproject
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<?eclipse-pydev version="1.0"?><pydev_project>
|
||||||
|
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
|
||||||
|
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python interpreter</pydev_property>
|
||||||
|
</pydev_project>
|
||||||
73
_scripts/get_resources.py
Executable file
73
_scripts/get_resources.py
Executable file
@@ -0,0 +1,73 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
import kubernetes as k8s
|
||||||
|
|
||||||
|
from pint import UnitRegistry
|
||||||
|
from collections import defaultdict
|
||||||
|
|
||||||
|
__all__ = ["compute_allocated_resources"]
|
||||||
|
|
||||||
|
|
||||||
|
def compute_allocated_resources():
|
||||||
|
ureg = UnitRegistry()
|
||||||
|
ureg.load_definitions('kubernetes_units.txt')
|
||||||
|
|
||||||
|
Q_ = ureg.Quantity
|
||||||
|
data = {}
|
||||||
|
|
||||||
|
# doing this computation within a k8s cluster
|
||||||
|
k8s.config.load_kube_config()
|
||||||
|
core_v1 = k8s.client.CoreV1Api()
|
||||||
|
|
||||||
|
# print("Listing pods with their IPs:")
|
||||||
|
# ret = core_v1.list_pod_for_all_namespaces(watch=False)
|
||||||
|
# for i in ret.items:
|
||||||
|
# print("%s\t%s\t%s" % (i.status.pod_ip, i.metadata.namespace, i.metadata.name))
|
||||||
|
|
||||||
|
for node in core_v1.list_node().items:
|
||||||
|
|
||||||
|
stats = {}
|
||||||
|
node_name = node.metadata.name
|
||||||
|
allocatable = node.status.allocatable
|
||||||
|
max_pods = int(int(allocatable["pods"]) * 1.5)
|
||||||
|
# print("{} ALLOC: {} MAX_PODS: {}".format(node_name,allocatable,max_pods))
|
||||||
|
field_selector = ("status.phase!=Succeeded,status.phase!=Failed," +
|
||||||
|
"spec.nodeName=" + node_name)
|
||||||
|
|
||||||
|
stats["cpu_alloc"] = Q_(allocatable["cpu"])
|
||||||
|
stats["mem_alloc"] = Q_(allocatable["memory"])
|
||||||
|
|
||||||
|
pods = core_v1.list_pod_for_all_namespaces(limit=max_pods,
|
||||||
|
field_selector=field_selector).items
|
||||||
|
|
||||||
|
# compute the allocated resources
|
||||||
|
cpureqs, cpulmts, memreqs, memlmts = [], [], [], []
|
||||||
|
for pod in pods:
|
||||||
|
for container in pod.spec.containers:
|
||||||
|
res = container.resources
|
||||||
|
reqs = defaultdict(lambda: 0, res.requests or {})
|
||||||
|
lmts = defaultdict(lambda: 0, res.limits or {})
|
||||||
|
cpureqs.append(Q_(reqs["cpu"]))
|
||||||
|
memreqs.append(Q_(reqs["memory"]))
|
||||||
|
cpulmts.append(Q_(lmts["cpu"]))
|
||||||
|
memlmts.append(Q_(lmts["memory"]))
|
||||||
|
|
||||||
|
stats["cpu_req"] = sum(cpureqs)
|
||||||
|
stats["cpu_lmt"] = sum(cpulmts)
|
||||||
|
stats["cpu_req_per"] = (stats["cpu_req"] / stats["cpu_alloc"] * 100)
|
||||||
|
stats["cpu_lmt_per"] = (stats["cpu_lmt"] / stats["cpu_alloc"] * 100)
|
||||||
|
|
||||||
|
stats["mem_req"] = sum(memreqs)
|
||||||
|
stats["mem_lmt"] = sum(memlmts)
|
||||||
|
stats["mem_req_per"] = (stats["mem_req"] / stats["mem_alloc"] * 100)
|
||||||
|
stats["mem_lmt_per"] = (stats["mem_lmt"] / stats["mem_alloc"] * 100)
|
||||||
|
|
||||||
|
data[node_name] = stats
|
||||||
|
|
||||||
|
return data
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
# execute only if run as a script
|
||||||
|
print(compute_allocated_resources())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
20
_scripts/kubernetes_units.txt
Normal file
20
_scripts/kubernetes_units.txt
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
# memory units
|
||||||
|
|
||||||
|
kmemunits = 1 = [kmemunits]
|
||||||
|
Ki = 1024 * kmemunits
|
||||||
|
Mi = Ki^2
|
||||||
|
Gi = Ki^3
|
||||||
|
Ti = Ki^4
|
||||||
|
Pi = Ki^5
|
||||||
|
Ei = Ki^6
|
||||||
|
|
||||||
|
# cpu units
|
||||||
|
|
||||||
|
kcpuunits = 1 = [kcpuunits]
|
||||||
|
m = 1/1000 * kcpuunits
|
||||||
|
k = 1000 * kcpuunits
|
||||||
|
M = k^2
|
||||||
|
G = k^3
|
||||||
|
T = k^4
|
||||||
|
P = k^5
|
||||||
|
E = k^6
|
||||||
@@ -1,3 +1,7 @@
|
|||||||
|
#we use postgresql:
|
||||||
|
#create database gitea;
|
||||||
|
#create user gitea with encrypted password 'secret';
|
||||||
|
#grant all privileges on database gitea to gitea;
|
||||||
apiVersion: apps/v1
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
metadata:
|
metadata:
|
||||||
@@ -46,13 +50,13 @@ spec:
|
|||||||
httpGet:
|
httpGet:
|
||||||
path: /
|
path: /
|
||||||
port: http
|
port: http
|
||||||
# resources:
|
resources:
|
||||||
# requests:
|
requests:
|
||||||
# memory: "256Mi"
|
memory: "256Mi"
|
||||||
# cpu: "250m"
|
cpu: "250m"
|
||||||
# limits:
|
limits:
|
||||||
# memory: "1000Mi"
|
memory: "1000Mi"
|
||||||
# cpu: "500m"
|
cpu: "500m"
|
||||||
volumes:
|
volumes:
|
||||||
- name: gitea
|
- name: gitea
|
||||||
persistentVolumeClaim:
|
persistentVolumeClaim:
|
||||||
@@ -78,14 +82,14 @@ metadata:
|
|||||||
name: gitea
|
name: gitea
|
||||||
labels:
|
labels:
|
||||||
app: gitea
|
app: gitea
|
||||||
release: latest
|
|
||||||
spec:
|
spec:
|
||||||
|
type: LoadBalancer
|
||||||
ports:
|
ports:
|
||||||
- port: 3000
|
- port: 3000
|
||||||
targetPort: http
|
targetPort: http
|
||||||
protocol: TCP
|
protocol: TCP
|
||||||
name: http
|
name: http
|
||||||
- port: 2222
|
- port: 22
|
||||||
targetPort: 22
|
targetPort: 22
|
||||||
name: ssh
|
name: ssh
|
||||||
selector:
|
selector:
|
||||||
@@ -98,7 +102,7 @@ metadata:
|
|||||||
name: gitea
|
name: gitea
|
||||||
spec:
|
spec:
|
||||||
rules:
|
rules:
|
||||||
- host: git.lan
|
- host: git-ui.lan
|
||||||
http:
|
http:
|
||||||
paths:
|
paths:
|
||||||
- backend:
|
- backend:
|
||||||
|
|||||||
74
apps/postgresql/postgresql-deploy.yaml
Normal file
74
apps/postgresql/postgresql-deploy.yaml
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
apiVersion: apps/v1
|
||||||
|
kind: StatefulSet
|
||||||
|
metadata:
|
||||||
|
name: postgres
|
||||||
|
labels:
|
||||||
|
app: postgres
|
||||||
|
env: live
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: postgres
|
||||||
|
env: live
|
||||||
|
serviceName: postgres-service
|
||||||
|
replicas: 1
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: postgres
|
||||||
|
env: live
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: postgres
|
||||||
|
image: postgres
|
||||||
|
volumeMounts:
|
||||||
|
- name: postgres-disk
|
||||||
|
mountPath: /var/lib/postgresql/data
|
||||||
|
env:
|
||||||
|
- name: POSTGRES_PASSWORD
|
||||||
|
value: pg2020
|
||||||
|
- name: PGDATA
|
||||||
|
value: /var/lib/postgresql/data/pgdata
|
||||||
|
volumes:
|
||||||
|
- name: postgres-disk
|
||||||
|
persistentVolumeClaim:
|
||||||
|
claimName: postgres
|
||||||
|
# volumeClaimTemplates:
|
||||||
|
# - metadata:
|
||||||
|
# name: postgres-disk
|
||||||
|
# spec:
|
||||||
|
# accessModes:
|
||||||
|
# - ReadWriteOnce
|
||||||
|
# resources:
|
||||||
|
# requests:
|
||||||
|
# storage: 10Gi
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: PersistentVolumeClaim
|
||||||
|
metadata:
|
||||||
|
name: postgres
|
||||||
|
labels:
|
||||||
|
app: postgres
|
||||||
|
spec:
|
||||||
|
storageClassName: nfs-ssd
|
||||||
|
accessModes:
|
||||||
|
- ReadWriteOnce
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
storage: 20Mi
|
||||||
|
# service.yml
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: postgres
|
||||||
|
labels:
|
||||||
|
app: postgres
|
||||||
|
env: live
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
env: live
|
||||||
|
type: LoadBalancer
|
||||||
|
ports:
|
||||||
|
- port: 5432
|
||||||
|
targetPort: 5432
|
||||||
Submodule cluster-monitoring updated: 94678da245...f0581d44d4
Reference in New Issue
Block a user