eindelijk weer eens een push

This commit is contained in:
allard committed 2026-05-31 16:07:30 +02:00
1 parent 01cff8e165
commit ff21c258e0
2747 files changed
+302316 -131101

No files matched your search

+25
View File
@@ -0,0 +1,25 @@
step 1
======
kubectl apply -f pvcs.yaml
Deze stap moet eerst omdat anders de statefullset zelf al een of meer pvc;s met hostpath storage heeft aangemaakt.
step2:
======
kubectl apply -f crate.yaml
step3:
======
In de web-ui kun je nu sql commando's uitvoeren.
CREATE TABLE iss (timestamp TIMESTAMP GENERATED ALWAYS AS CURRENT_TIMESTAMP,position GEO_POINT);
ALTER TABLE iss SET ("blocks.read_only_allow_delete" = FALSE)
SELECT "timestamp", "position" FROM "doc"."iss" LIMIT 1000;
step 4:
=======
Met het scriptje iss.sh kun je rows opvoeren in de tabel
-1
View File
@@ -1 +0,0 @@
ALTER TABLE iss SET ("blocks.read_only_allow_delete" = FALSE)
@@ -3,6 +3,7 @@ apiVersion: "apps/v1"
metadata:
# This is the name used as a prefix for all pods in the set.
name: crate
namespace: crate
spec:
serviceName: "crate-set"
# Our cluster has three nodes.
@@ -32,7 +33,7 @@ spec:
containers:
- name: crate
# Use the CrateDB 5.1.1 Docker image.
image: crate:5.1.1
image: crate
# Pass in configuration to CrateDB via command-line options.
# We are setting the name of the node's explicitly, which is
# needed to determine the initial master nodes. These are set to
@@ -95,3 +96,95 @@ spec:
resources:
requests:
storage: 1Gi
---
kind: Service
apiVersion: v1
metadata:
name: crate-internal-service
namespace: crate
labels:
app: crate
spec:
# A static IP address is assigned to this service. This IP address is
# only reachable from within the Kubernetes cluster.
type: ClusterIP
ports:
# Port 4300 for inter-node communication.
- port: 4300
name: crate-internal
selector:
# Apply this to all nodes with the `app:crate` label.
app: crate
---
kind: Service
apiVersion: v1
metadata:
name: crate-ui
namespace: crate
labels:
app: crate
spec:
# A static IP address is assigned to this service. This IP address is
# only reachable from within the Kubernetes cluster.
type: ClusterIP
ports:
# Port 4300 for inter-node communication.
- port: 4200
name: crate-web
selector:
# Apply this to all nodes with the `app:crate` label.
app: crate
---
kind: Service
apiVersion: v1
metadata:
name: crate-external-service
namespace: crate
labels:
app: crate
spec:
# Create an externally reachable load balancer.
type: LoadBalancer
ports:
# Port 4200 for HTTP clients.
- port: 4200
name: crate-web
# Port 5432 for PostgreSQL wire protocol clients.
- port: 5432
name: postgres
selector:
# Apply this to all nodes with the `app:crate` label.
app: crate
---
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
name: cratedb-tls
namespace: crate
spec:
entryPoints:
- websecure
routes:
- match: Host(`cratedb-dev.allarddcs.nl`)
kind: Rule
services:
- name: crate-ui
port: 4200
tls:
certResolver: letsencrypt
---
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
name: cratedb-http
namespace: crate
spec:
entryPoints:
- web
routes:
- match: Host(`cratedb-dev.allarddcs.nl`)
kind: Rule
services:
- name: crate-ui
port: 4200
+1 -4
View File
@@ -1,4 +1 @@
CREATE TABLE iss (
timestamp TIMESTAMP GENERATED ALWAYS AS CURRENT_TIMESTAMP,
position GEO_POINT
);
CREATE TABLE iss (timestamp TIMESTAMP GENERATED ALWAYS AS CURRENT_TIMESTAMP,position GEO_POINT);
-19
View File
@@ -1,19 +0,0 @@
kind: Service
apiVersion: v1
metadata:
name: crate-external-service
labels:
app: crate
spec:
# Create an externally reachable load balancer.
type: LoadBalancer
ports:
# Port 4200 for HTTP clients.
- port: 4200
name: crate-web
# Port 5432 for PostgreSQL wire protocol clients.
- port: 5432
name: postgres
selector:
# Apply this to all nodes with the `app:crate` label.
app: crate
-15
View File
@@ -1,15 +0,0 @@
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: cratedb-tls
spec:
entryPoints:
- websecure
routes:
- match: Host(`cratedb.alldcs.nl`)
kind: Rule
services:
- name: crate-ui
port: 4200
tls:
certResolver: letsencrypt
-36
View File
@@ -1,36 +0,0 @@
kind: Service
apiVersion: v1
metadata:
name: crate-internal-service
labels:
app: crate
spec:
# A static IP address is assigned to this service. This IP address is
# only reachable from within the Kubernetes cluster.
type: ClusterIP
ports:
# Port 4300 for inter-node communication.
- port: 4300
name: crate-internal
selector:
# Apply this to all nodes with the `app:crate` label.
app: crate
---
kind: Service
apiVersion: v1
metadata:
name: crate-ui
labels:
app: crate
spec:
# A static IP address is assigned to this service. This IP address is
# only reachable from within the Kubernetes cluster.
type: ClusterIP
ports:
# Port 4300 for inter-node communication.
- port: 4200
name: crate-web
selector:
# Apply this to all nodes with the `app:crate` label.
app: crate
+8
View File
@@ -0,0 +1,8 @@
FROM nginx:1.25-alpine
COPY nginx/default.conf /etc/nginx/conf.d/default.conf
COPY app/ /usr/share/nginx/html/
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
+208
View File
@@ -0,0 +1,208 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>ISS Tracker — Live Position Feed</title>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
<link href="https://fonts.googleapis.com/css2?family=Share+Tech+Mono&family=Orbitron:wght@400;700&display=swap" rel="stylesheet" />
<style>
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
--bg: #050d1a;
--panel: #091628;
--border: #0d3a6e;
--accent: #00d4ff;
--accent2: #ff6b35;
--green: #39ff14;
--text: #c8e6ff;
--dim: #4a7aa0;
--font-mono: 'Share Tech Mono', monospace;
--font-disp: 'Orbitron', sans-serif;
}
html, body { height: 100%; background: var(--bg); color: var(--text); font-family: var(--font-mono); overflow: hidden; }
#app { display: grid; grid-template-rows: 56px 1fr; height: 100vh; }
header {
display: flex; align-items: center; gap: 16px;
padding: 0 20px;
background: var(--panel);
border-bottom: 1px solid var(--border);
position: relative; z-index: 1000;
}
.logo { font-family: var(--font-disp); font-size: 15px; letter-spacing: 3px; color: var(--accent); white-space: nowrap; }
.logo span { color: var(--accent2); }
.status-bar { display: flex; gap: 24px; align-items: center; font-size: 11px; color: var(--dim); flex: 1; }
.stat { display: flex; flex-direction: column; gap: 1px; }
.stat-label { font-size: 9px; letter-spacing: 2px; color: var(--dim); text-transform: uppercase; }
.stat-value { color: var(--accent); font-size: 12px; }
#ping-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--dim); margin-left: auto; transition: background .3s; }
#ping-dot.live { background: var(--green); box-shadow: 0 0 8px var(--green); animation: pulse 2s infinite; }
#ping-dot.error { background: var(--accent2); box-shadow: 0 0 8px var(--accent2); }
@keyframes pulse { 0%,100% { opacity:1 } 50% { opacity:.4 } }
#map { width: 100%; height: 100%; background: #020a14; }
.leaflet-tile { filter: brightness(.7) saturate(1.4) hue-rotate(190deg); }
.leaflet-container { background: #020a14; }
.leaflet-control-zoom a { background: var(--panel); color: var(--accent); border-color: var(--border); }
.leaflet-control-zoom a:hover { background: var(--border); }
.leaflet-control-attribution { background: rgba(5,13,26,.8) !important; color: var(--dim) !important; font-size: 9px; }
.leaflet-control-attribution a { color: var(--dim) !important; }
#toast {
position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
background: var(--panel); border: 1px solid var(--border);
color: var(--accent2); font-size: 12px; padding: 8px 20px;
border-radius: 2px; z-index: 9999; opacity: 0; transition: opacity .4s;
pointer-events: none;
}
#toast.show { opacity: 1; }
.iss-ring {
width: 24px; height: 24px; border-radius: 50%;
border: 2px solid var(--accent);
animation: sonar 1.5s ease-out infinite;
position: absolute; top: -4px; left: -4px;
}
@keyframes sonar { 0% { transform: scale(1); opacity:1 } 100% { transform: scale(2.5); opacity:0 } }
</style>
</head>
<body>
<div id="app">
<header>
<div class="logo">ISS/<span>TRACKER</span></div>
<div class="status-bar">
<div class="stat"><span class="stat-label">Points</span><span class="stat-value" id="s-count">—</span></div>
<div class="stat"><span class="stat-label">Latitude</span><span class="stat-value" id="s-lat">—</span></div>
<div class="stat"><span class="stat-label">Longitude</span><span class="stat-value" id="s-lon">—</span></div>
<div class="stat"><span class="stat-label">Last seen</span><span class="stat-value" id="s-ts">—</span></div>
<div class="stat"><span class="stat-label">Refresh</span><span class="stat-value" id="s-refresh">10s</span></div>
</div>
<div id="ping-dot" title="Connection status"></div>
</header>
<div id="map"></div>
</div>
<div id="toast"></div>
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
<script>
const CRATEDB_URL = window.CRATEDB_URL || '/cratedb';
const REFRESH_MS = parseInt(window.REFRESH_MS || '10000', 10);
const TRAIL_LIMIT = parseInt(window.TRAIL_LIMIT || '1000', 10);
const SQL = `
SELECT "timestamp", "position"
FROM "doc"."iss"
ORDER BY "timestamp" DESC
LIMIT ${TRAIL_LIMIT}
`;
const map = L.map('map', { center: [20, 0], zoom: 2 });
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap contributors', maxZoom: 18,
}).addTo(map);
const trail = L.polyline([], {
color: '#00d4ff', weight: 1.5, opacity: 0.5, dashArray: '4 6',
}).addTo(map);
const ghostLayer = L.layerGroup().addTo(map);
const issIcon = L.divIcon({
className: '',
html: `<div style="width:16px;height:16px;border-radius:50%;background:#ff6b35;border:2px solid #fff;box-shadow:0 0 12px #ff6b35, 0 0 24px #ff6b35;position:relative;z-index:2"></div><div class="iss-ring"></div>`,
iconSize: [16, 16], iconAnchor: [8, 8],
});
const issMarker = L.marker([0, 0], { icon: issIcon, zIndexOffset: 1000 }).addTo(map);
function parseWKT(position) {
if (!position) return null;
// CrateDB returns position as [lon, lat] array
if (Array.isArray(position)) {
return { lon: position[0], lat: position[1] };
}
// fallback: WKT string
const m = typeof position === 'string' && position.match(/POINT\s*\(\s*([-\d.]+)\s+([-\d.]+)\s*\)/i);
if (!m) return null;
return { lon: parseFloat(m[1]), lat: parseFloat(m[2]) };
}
const dot = document.getElementById('ping-dot');
const toast = document.getElementById('toast');
let toastTimer;
function showToast(msg, isError = false) {
toast.textContent = msg;
toast.style.borderColor = isError ? 'var(--accent2)' : 'var(--border)';
toast.classList.add('show');
clearTimeout(toastTimer);
toastTimer = setTimeout(() => toast.classList.remove('show'), 3500);
}
function updateHeader(rows) {
document.getElementById('s-count').textContent = rows.length;
if (!rows.length) return;
const pt = parseWKT(rows[0][1]);
if (pt) {
document.getElementById('s-lat').textContent = pt.lat.toFixed(4) + '°';
document.getElementById('s-lon').textContent = pt.lon.toFixed(4) + '°';
}
const ts = rows[0][0];
document.getElementById('s-ts').textContent = ts
? new Date(ts).toUTCString().replace(/.*,\s*/, '').replace(' GMT', ' UTC') : '—';
}
async function fetchPositions() {
const res = await fetch(`${CRATEDB_URL}/_sql`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ stmt: SQL }),
});
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const json = await res.json();
return json.rows || [];
}
let firstLoad = true;
async function refresh() {
try {
const rows = await fetchPositions();
dot.className = 'live';
const points = rows.map(r => parseWKT(r[1])).filter(Boolean);
ghostLayer.clearLayers();
points.slice(1).forEach((pt, i) => {
const age = i / Math.max(points.length, 1);
L.circleMarker([pt.lat, pt.lon], {
radius: 2 + (1 - age) * 2,
color: '#00d4ff', fillColor: '#00d4ff',
fillOpacity: 0.15 + (1 - age) * 0.45, weight: 0,
}).addTo(ghostLayer);
});
trail.setLatLngs([...points].reverse().map(p => [p.lat, p.lon]));
if (points.length > 0) {
const latest = points[0];
issMarker.setLatLng([latest.lat, latest.lon]);
issMarker.bindPopup(`<div style="font-family:monospace;font-size:12px;color:#ff6b35"><b>ISS — Live</b><br>Lat: ${latest.lat.toFixed(4)}°<br>Lon: ${latest.lon.toFixed(4)}°</div>`);
if (firstLoad) { map.setView([latest.lat, latest.lon], 3); firstLoad = false; }
}
updateHeader(rows);
} catch (err) {
dot.className = 'error';
showToast(`CrateDB error: ${err.message}`, true);
}
}
document.getElementById('s-refresh').textContent = (REFRESH_MS / 1000) + 's';
refresh();
setInterval(refresh, REFRESH_MS);
</script>
</body>
</html>
+23
View File
@@ -0,0 +1,23 @@
server {
listen 80;
server_name _;
root /usr/share/nginx/html;
index index.html;
location / {
try_files $uri $uri/ /index.html;
add_header Cache-Control "no-store";
}
# Proxies CrateDB to avoid CORS — browser calls /cratedb/_sql
location /cratedb/ {
proxy_pass http://crate-ui:4200/;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
add_header Access-Control-Allow-Origin "*";
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";
add_header Access-Control-Allow-Headers "Content-Type";
}
}
+13 -8
View File
@@ -1,20 +1,25 @@
# Exit immediately if a pipeline returns a non-zero status
set -e
position () {
curl -s http://api.open-notify.org/iss-now.json |
jq -r '[.iss_position.longitude, .iss_position.latitude] | @tsv';
jq -r '[.iss_position.longitude, .iss_position.latitude] | @tsv'
}
wkt_position () {
echo "POINT ($(position | expand -t 1))";
echo "POINT ($(position | expand -t 1))"
}
while true; do
crash --hosts 192.168.40.81:4200 \
--command "INSERT INTO iss (position) VALUES ('$(wkt_position)')"
echo 'Sleeping for 1 seconds...'
WKT=$(wkt_position)
if [[ -z "$WKT" || "$WKT" == "POINT ()" ]]; then
echo "Empty position, skipping..."
else
crash --hosts 192.168.2.182:4200 \
--command "INSERT INTO iss (position) VALUES ('$WKT')" \
|| echo "Insert failed, skipping..."
fi
echo 'Sleeping for 10 seconds...'
sleep 10
done
+60
View File
@@ -0,0 +1,60 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: iss-tracker
namespace: crate
labels:
app: iss-tracker
spec:
replicas: 1
selector:
matchLabels:
app: iss-tracker
template:
metadata:
labels:
app: iss-tracker
spec:
containers:
- name: iss-tracker
image: allardkrings/iss:1.0
imagePullPolicy: Always
ports:
- containerPort: 80
resources:
requests:
cpu: "50m"
memory: "32Mi"
limits:
cpu: "200m"
memory: "64Mi"
---
apiVersion: v1
kind: Service
metadata:
name: iss-tracker
namespace: crate
spec:
selector:
app: iss-tracker
ports:
- port: 80
targetPort: 80
type: ClusterIP
---
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
name: iss-tracker
namespace: crate
spec:
entryPoints:
- websecure
routes:
- match: Host(`iss-dev.allarddcs.nl`) # ← change to your hostname
kind: Rule
services:
- name: iss-tracker
port: 80
tls:
certResolver: letsencrypt
@@ -13,8 +13,8 @@ spec:
- hard
- nfsvers=4.1
nfs:
server: 192.168.40.100
path: /mnt/nfs_share/crate/crate-0
server: 192.168.2.111
path: /mnt/nfs_share/dev/crate/crate-0
readOnly: false
---
apiVersion: v1
@@ -32,8 +32,8 @@ spec:
- hard
- nfsvers=4.1
nfs:
server: 192.168.40.100
path: /mnt/nfs_share/crate/crate-1
server: 192.168.2.111
path: /mnt/nfs_share/dev/crate/crate-1
readOnly: false
---
apiVersion: v1
@@ -51,14 +51,15 @@ spec:
- hard
- nfsvers=4.1
nfs:
server: 192.168.40.100
path: /mnt/nfs_share/crate/crate-2
server: 192.168.2.111
path: /mnt/nfs_share/dev/crate/crate-2
readOnly: false
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: data-crate-0
namespace: crate
spec:
storageClassName: ""
volumeName: crate-pv-0
@@ -73,6 +74,7 @@ apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: data-crate-1
namespace: crate
spec:
storageClassName: ""
volumeName: crate-pv-1
@@ -87,6 +89,7 @@ apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: data-crate-2
namespace: crate
spec:
storageClassName: ""
volumeName: crate-pv-2
@@ -96,3 +99,4 @@ spec:
resources:
requests:
storage: 1Gi
-1
View File
@@ -1 +0,0 @@
SELECT "timestamp", "position" FROM "doc"."iss" LIMIT 1000;