-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
382 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,6 @@ mvn install && mvn spring-boot:run -pl service | |
$ npm -v | ||
6.12.1 | ||
|
||
|
||
$ node -v | ||
v12.13.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/bin/bash | ||
# nohup sh agent.sh [NODE-NAME] [YOUR-SECURITY-TOKEN] > /tmp/agent.log | ||
if [ -z "$1" ]; then | ||
echo "Node name required !" | ||
exit 1 | ||
fi | ||
|
||
if [ -z "$2" ]; then | ||
echo "Security Token required !" | ||
exit 1 | ||
fi | ||
|
||
attempts=0 | ||
server="http[s]://[YOUR-API-BACKEN-URL]/k8s/collect/$1/temperature" | ||
|
||
while true; do | ||
|
||
temperature=$(cat /sys/class/thermal/thermal_zone0/temp) | ||
|
||
if [ $? != 0 ] || [ -z "$temperature" ]; then | ||
echo "Unable to determinate CPU temperature value !" | ||
exit 1 | ||
fi | ||
|
||
url="$server?node=$2&value=$temperature" | ||
|
||
responseCode=$(curl --silent --output /dev/null --write-out "%{http_code}" $url) | ||
|
||
if [ $? != 0 ] || [ -z "$responseCode" ] || [ $responseCode -ne 200 ]; then | ||
attempts=$((attempts + 1)) | ||
echo "[ATTEMP-$attempts] Failed sending data to server : $responseCode" | ||
if [ $attempts = 20 ]; then | ||
echo "Server response error after 20 attempts !" | ||
exit 1 | ||
fi; | ||
else | ||
attempts=0 | ||
fi | ||
|
||
sleep 5 | ||
done; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
--- | ||
apiVersion: v1 | ||
kind: Namespace | ||
metadata: | ||
name: monitoring | ||
|
||
--- | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: monitoring-tls | ||
namespace: monitoring | ||
data: | ||
tls.crt: {{crt}} | ||
tls.key: {{key}} | ||
type: kubernetes.io/tls | ||
|
||
--- | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: monitoring-token | ||
namespace: monitoring | ||
type: Opaque | ||
data: | ||
security.token: {{encodedtoken}} | ||
|
||
--- | ||
apiVersion: extensions/v1beta1 | ||
kind: Ingress | ||
metadata: | ||
annotations: | ||
kubernetes.io/ingress.class: nginx | ||
name: monitoring-ingress | ||
namespace: monitoring | ||
labels: | ||
app: api | ||
spec: | ||
rules: | ||
- host: {{host}} | ||
http: | ||
paths: | ||
- backend: | ||
serviceName: monitoring-service | ||
servicePort: http | ||
path: / | ||
tls: | ||
- hosts: | ||
- {{host}} | ||
secretName: monitoring-tls | ||
|
||
--- | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: api | ||
namespace: monitoring | ||
labels: | ||
app: api | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: api | ||
template: | ||
metadata: | ||
labels: | ||
app: api | ||
commit: '{{commit}}' | ||
spec: | ||
serviceAccountName: api-access | ||
containers: | ||
- name: api | ||
image: medinvention/k8s-monitoring-api:arm | ||
imagePullPolicy: Always | ||
env: | ||
- name: COLLECTOR_TOKEN | ||
valueFrom: | ||
secretKeyRef: | ||
name: monitoring-token | ||
key: security.token | ||
- name: FAN_SERVER_URL | ||
value: 'http://192.168.1.85:5000' | ||
- name: FAN_MAXTEMP | ||
value: '70' | ||
ports: | ||
- containerPort: 8080 | ||
readinessProbe: | ||
httpGet: | ||
path: /k8s/actuator/health | ||
port: 8080 | ||
initialDelaySeconds: 60 | ||
timeoutSeconds: 2 | ||
periodSeconds: 3 | ||
failureThreshold: 1 | ||
livenessProbe: | ||
httpGet: | ||
path: /k8s/actuator/health | ||
port: 8080 | ||
initialDelaySeconds: 300 | ||
timeoutSeconds: 5 | ||
periodSeconds: 60 | ||
failureThreshold: 1 | ||
|
||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: monitoring-service | ||
namespace: monitoring | ||
spec: | ||
ports: | ||
- name: http | ||
port: 80 | ||
targetPort: 8080 | ||
selector: | ||
app: api | ||
|
||
--- | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
labels: | ||
name: api-access | ||
namespace: monitoring | ||
|
||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: api-access | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: ClusterRole | ||
name: cluster-admin | ||
subjects: | ||
- kind: ServiceAccount | ||
name: api-access | ||
namespace: monitoring | ||
|
||
--- | ||
apiVersion: apps/v1 | ||
kind: DaemonSet | ||
metadata: | ||
name: monitoring-agent | ||
namespace: monitoring | ||
labels: | ||
k8s-app: monitoring-agent | ||
spec: | ||
selector: | ||
matchLabels: | ||
name: monitoring-agent | ||
template: | ||
metadata: | ||
labels: | ||
name: monitoring-agent | ||
commit: '{{commit}}' | ||
spec: | ||
tolerations: | ||
# this toleration is to have the daemonset runnable on master nodes | ||
# remove it if your masters can't run pods | ||
- key: node-role.kubernetes.io/master | ||
effect: NoSchedule | ||
containers: | ||
- name: monitoring-agent | ||
image: busybox | ||
env: | ||
- name: NODE | ||
valueFrom: | ||
fieldRef: | ||
fieldPath: spec.nodeName | ||
- name: SERVER | ||
value: http://monitoring-service.monitoring.svc.cluster.local/k8s/collect/{{token}}/temperature | ||
command: [ "sh", "-c"] | ||
args: | ||
- while true; do | ||
TEMP=$(cat /sys/class/thermal/thermal_zone0/temp); | ||
URL="$SERVER?node=$NODE&value=$TEMP"; | ||
wget -qO- $URL; | ||
sleep 5; | ||
done; | ||
imagePullPolicy: IfNotPresent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#!/bin/sh | ||
|
||
if [ -z "$CRT" ] || [ -z "$KEY" ]; then | ||
echo "TLS CRT/KEY environment value not found !" | ||
exit 1 | ||
fi | ||
|
||
if [ -z "$TOKEN" ]; then | ||
echo "Kube Token environment value not found !" | ||
exit 1 | ||
fi | ||
|
||
if [ -z "$COLLECTORTOKEN" ]; then | ||
echo "Collector Token environment value not found !" | ||
exit 1 | ||
fi | ||
|
||
echo "Get Kubectl" | ||
curl -s -LO https://storage.googleapis.com/kubernetes-release/release/v1.17.0/bin/linux/arm/kubectl | ||
chmod +x ./kubectl | ||
|
||
commitID=$(git log -1 --pretty="%H") | ||
|
||
if [ $? != 0 ] || [ -z "$commitID" ]; then | ||
echo "Unable to determinate CommitID !" | ||
exit 1 | ||
fi | ||
|
||
echo "Deploy for CommitID : ${commitID}" | ||
|
||
ENCODEDCOLLECTORTOKEN=$(echo -n $COLLECTORTOKEN | base64) | ||
# create new deploy | ||
sed -i "s|{{crt}}|`echo $CRT`|g" api.yaml | ||
sed -i "s|{{key}}|`echo $KEY`|g" api.yaml | ||
sed -i "s|{{token}}|`echo $COLLECTORTOKEN`|g" api.yaml | ||
sed -i "s|{{encodedtoken}}|`echo $ENCODEDCOLLECTORTOKEN`|g" api.yaml | ||
sed -i "s|{{host}}|api-monitoring.medinvention.dev|g" api.yaml | ||
sed -i "s|{{commit}}|`echo $commitID`|g" api.yaml | ||
|
||
./kubectl --token=$TOKEN apply -f api.yaml | ||
if [ $? != 0 ]; then | ||
echo "Unable to deploy API !" | ||
exit 1 | ||
fi | ||
|
||
# wait for ready | ||
attempts=0 | ||
rolloutStatusCmd="./kubectl --token=$TOKEN rollout status deployment/api -n monitoring" | ||
until $rolloutStatusCmd || [ $attempts -eq 60 ]; do | ||
$rolloutStatusCmd | ||
attempts=$((attempts + 1)) | ||
sleep 10 | ||
done | ||
|
||
# create new deploy | ||
sed -i "s|{{crt}}|`echo $CRT`|g" front.yaml | ||
sed -i "s|{{key}}|`echo $KEY`|g" front.yaml | ||
sed -i "s|{{host}}|monitoring.medinvention.dev|g" front.yaml | ||
sed -i "s|{{commit}}|`echo $commitID`|g" front.yaml | ||
|
||
./kubectl --token=$TOKEN apply -f front.yaml | ||
if [ $? != 0 ]; then | ||
echo "Unable to deploy Front !" | ||
exit 1 | ||
fi | ||
|
||
# wait for ready | ||
attempts=0 | ||
rolloutStatusCmd="./kubectl --token=$TOKEN rollout status deployment/front -n monitoring" | ||
until $rolloutStatusCmd || [ $attempts -eq 60 ]; do | ||
$rolloutStatusCmd | ||
attempts=$((attempts + 1)) | ||
sleep 10 | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: front-tls | ||
namespace: monitoring | ||
type: Opaque | ||
data: | ||
tls.crt: {{crt}} | ||
tls.key: {{key}} | ||
type: kubernetes.io/tls | ||
|
||
--- | ||
apiVersion: extensions/v1beta1 | ||
kind: Ingress | ||
metadata: | ||
annotations: | ||
kubernetes.io/ingress.class: nginx | ||
name: front | ||
namespace: monitoring | ||
labels: | ||
app: front | ||
spec: | ||
rules: | ||
- host: {{host}} | ||
http: | ||
paths: | ||
- backend: | ||
serviceName: front-service | ||
servicePort: http | ||
path: / | ||
tls: | ||
- hosts: | ||
- {{host}} | ||
secretName: front-tls | ||
|
||
--- | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: front | ||
namespace: monitoring | ||
labels: | ||
app: front | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: front | ||
template: | ||
metadata: | ||
labels: | ||
app: front | ||
commit: '{{commit}}' | ||
spec: | ||
containers: | ||
- name: front | ||
image: medinvention/k8s-monitoring-front:arm | ||
imagePullPolicy: Always | ||
ports: | ||
- containerPort: 80 | ||
|
||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: front-service | ||
namespace: monitoring | ||
spec: | ||
ports: | ||
- name: http | ||
port: 80 | ||
targetPort: 80 | ||
selector: | ||
app: front |
Oops, something went wrong.