Skip to content

Commit

Permalink
add k8s practice materials
Browse files Browse the repository at this point in the history
  • Loading branch information
balazsfodor committed Nov 6, 2024
1 parent c83ab18 commit 02a5260
Show file tree
Hide file tree
Showing 16 changed files with 593 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
hidden_*
hidden_*
node_modules
4 changes: 4 additions & 0 deletions k8s-autoscaling/deployments/fortio/gen_load.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#kubectl create -f https://raw.githubusercontent.com/verfio/fortio-operator/master/deploy/fortio.yaml

echo "start sending requests"
kubectl run -i --tty load-generator --rm --image=docker.io/fortio/fortio --restart=Never -- load -allow-initial-errors -qps $1 -t 0 -connection-reuse 0:0 -c 32 - http://demo-webserver:8080
3 changes: 3 additions & 0 deletions k8s-autoscaling/deployments/grafana/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
service:
type: NodePort
nodePort: 30002
5 changes: 5 additions & 0 deletions k8s-autoscaling/deployments/grafana/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
helm repo add grafana https://grafana.github.io/helm-charts
helm install grafana grafana/grafana -n monitoring --values config.yaml
echo "Login data:"
kubectl get secret --namespace monitoring grafana -o jsonpath="{.data.admin-password}" | base64 --decode ; echo
336 changes: 336 additions & 0 deletions k8s-autoscaling/deployments/grafana/service-dashboard.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,336 @@
{
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": {
"type": "grafana",
"uid": "-- Grafana --"
},
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
"type": "dashboard"
}
]
},
"editable": true,
"fiscalYearStartMonth": 0,
"graphTooltip": 0,
"id": 5,
"links": [],
"liveNow": false,
"panels": [
{
"datasource": {
"type": "prometheus",
"uid": "d5414744-c248-426b-b9d7-e66f3bd8de8c"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"drawStyle": "line",
"fillOpacity": 0,
"gradientMode": "none",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"insertNulls": false,
"lineInterpolation": "linear",
"lineWidth": 1,
"pointSize": 5,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "auto",
"spanNulls": false,
"stacking": {
"group": "A",
"mode": "none"
},
"thresholdsStyle": {
"mode": "off"
}
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 7,
"w": 24,
"x": 0,
"y": 0
},
"id": 5,
"options": {
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "single",
"sort": "none"
}
},
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "d5414744-c248-426b-b9d7-e66f3bd8de8c"
},
"editorMode": "code",
"expr": "sum(rate(seminar_http_requests_total{kubernetes_pod_name=~\"demo-webserver.*\"}[2m])) by (kubernetes_pod_name)",
"instant": false,
"legendFormat": "__auto",
"range": true,
"refId": "A"
}
],
"title": "AVG HTTP Requests/s",
"type": "timeseries"
},
{
"datasource": {
"type": "prometheus",
"uid": "d5414744-c248-426b-b9d7-e66f3bd8de8c"
},
"fieldConfig": {
"defaults": {
"color": {
"fixedColor": "orange",
"mode": "palette-classic"
},
"custom": {
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"drawStyle": "line",
"fillOpacity": 0,
"gradientMode": "none",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"insertNulls": false,
"lineInterpolation": "smooth",
"lineStyle": {
"fill": "solid"
},
"lineWidth": 1,
"pointSize": 5,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "auto",
"spanNulls": false,
"stacking": {
"group": "A",
"mode": "none"
},
"thresholdsStyle": {
"mode": "off"
}
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "red",
"value": 80
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 24,
"x": 0,
"y": 7
},
"id": 2,
"maxDataPoints": 100,
"options": {
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "single",
"sort": "none"
}
},
"pluginVersion": "10.1.5",
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "d5414744-c248-426b-b9d7-e66f3bd8de8c"
},
"disableTextWrap": false,
"editorMode": "code",
"expr": "sum by(pod) (rate(container_cpu_usage_seconds_total{pod=~\"demo-webserver.*\"}[2m])) *1000",
"format": "time_series",
"fullMetaSearch": false,
"includeNullMetadata": true,
"intervalFactor": 1,
"legendFormat": "",
"range": true,
"refId": "A",
"useBackend": false
}
],
"title": "CPU Usage",
"transformations": [],
"type": "timeseries"
},
{
"datasource": {
"type": "prometheus",
"uid": "d5414744-c248-426b-b9d7-e66f3bd8de8c"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"drawStyle": "line",
"fillOpacity": 0,
"gradientMode": "none",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"insertNulls": false,
"lineInterpolation": "linear",
"lineWidth": 1,
"pointSize": 5,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "auto",
"spanNulls": false,
"stacking": {
"group": "A",
"mode": "none"
},
"thresholdsStyle": {
"mode": "off"
}
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "red",
"value": 80
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 24,
"x": 0,
"y": 15
},
"id": 4,
"maxDataPoints": 100,
"options": {
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "single",
"sort": "none"
}
},
"pluginVersion": "10.1.5",
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "d5414744-c248-426b-b9d7-e66f3bd8de8c"
},
"editorMode": "code",
"expr": "sum by (pod) (rate(container_memory_usage_bytes{pod=~\"demo-webserver.*\"}[2m])) / 1024",
"format": "time_series",
"intervalFactor": 1,
"legendFormat": "",
"range": true,
"refId": "A"
}
],
"title": "Memory Usage",
"type": "timeseries"
}
],
"refresh": "5s",
"schemaVersion": 38,
"style": "dark",
"tags": [],
"templating": {
"list": []
},
"time": {
"from": "now-5m",
"to": "now"
},
"timepicker": {},
"timezone": "",
"title": "Demo Webserver",
"uid": "c19c0e7e-18c9-424f-95e9-66abcaeb62e4",
"version": 10,
"weekStart": ""
}
31 changes: 31 additions & 0 deletions k8s-autoscaling/deployments/prometheus/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
global:
scrape_interval: 15s
evaluation_interval: 15s
alertmanager:
enabled: false
kube-state-metrics:
enabled: true
prometheus-node-exporter:
enabled: true
prometheus-pushgateway:
enabled: false
server:
service:
type: NodePort
nodePort: 30001
extraScrapeConfigs: >
- job_name: demo-webserver
kubernetes_sd_configs:
- role: pod
relabel_configs:
- source_labels: [__meta_kubernetes_pod_label_app]
action: keep
regex: demo-webserver
- source_labels: [__meta_kubernetes_namespace]
action: replace
target_label: kubernetes_namespace
- source_labels: [__meta_kubernetes_pod_name]
action: replace
target_label: kubernetes_pod_name
static_configs:
- targets: ['localhost:8080']
3 changes: 3 additions & 0 deletions k8s-autoscaling/deployments/prometheus/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
helm install prometheus prometheus-community/prometheus --values config.yaml -n monitoring
2 changes: 2 additions & 0 deletions k8s-autoscaling/deployments/prometheus/forward.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sudo ufw allow 30001
kubectl port-forward svc/prometheus-server -n monitoring --address 0.0.0.0 30001:80
Loading

0 comments on commit 02a5260

Please sign in to comment.