added initial istio BLAHAJ code

This commit is contained in:
2025-08-27 19:32:09 -04:00
parent 44de4f6345
commit ba11630d56
22 changed files with 438 additions and 0 deletions
+2
View File
@@ -0,0 +1,2 @@
*.txt
*.xml
+31
View File
@@ -0,0 +1,31 @@
// bun, es modules, minimal deps; one file serves all three services
import http from 'http';
const serviceName = process.env.SERVICE_NAME || 'blahaj';
const emoji = process.env.SERVICE_EMOJI || '🦈';
const friend = process.env.FRIEND_NAME || 'sea-friend';
const port = Number(process.env.PORT || 8080);
const ascii = `
__
_.-' \\
_.-' _.-'\\) ${emoji} // ascii blahaj says hi!
(____.-' ~ waves ~
`;
const server = http.createServer((req, res) => {
const path = req.url || '/';
const message = {
service: serviceName,
says: `hello, ${friend}! i am ${serviceName}`,
path,
mascot: 'BLÅHAJ',
fun: 'soft, cuddly shark energy',
};
res.setHeader('content-type', 'application/json; charset=utf-8');
res.end(JSON.stringify({ message, ascii }));
});
server.listen(port, () => {
console.log(`${serviceName} listening on ${port};`);
});
+6
View File
@@ -0,0 +1,6 @@
FROM oven/bun:1.1.31-alpine AS base
WORKDIR /app
COPY app.mjs ./
EXPOSE 8080
ENV NODE_ENV=production
CMD ["bun", "run", "app.mjs"]
+30
View File
@@ -0,0 +1,30 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: bubbles
namespace: demo
spec:
replicas: 2
selector: { matchLabels: { app: bubbles } }
template:
metadata:
labels: { app: bubbles }
spec:
containers:
- name: app
image: blahaj-bun:dev
imagePullPolicy: IfNotPresent
ports: [{ containerPort: 8080, name: http }]
env:
- { name: SERVICE_NAME, value: "bubbles" }
- { name: SERVICE_EMOJI, value: "🫧" }
- { name: FRIEND_NAME, value: "coral" }
---
apiVersion: v1
kind: Service
metadata:
name: bubbles
namespace: demo
spec:
selector: { app: bubbles }
ports: [{ name: http, port: 80, targetPort: 8080 }]
+3
View File
@@ -0,0 +1,3 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources: [deployment.yaml, service.yaml]
+30
View File
@@ -0,0 +1,30 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: coral
namespace: demo
spec:
replicas: 2
selector: { matchLabels: { app: coral } }
template:
metadata:
labels: { app: coral }
spec:
containers:
- name: app
image: blahaj-bun:dev
imagePullPolicy: IfNotPresent
ports: [{ containerPort: 8080, name: http }]
env:
- { name: SERVICE_NAME, value: "coral" }
- { name: SERVICE_EMOJI, value: "🪸" }
- { name: FRIEND_NAME, value: "kelp" }
---
apiVersion: v1
kind: Service
metadata:
name: coral
namespace: demo
spec:
selector: { app: coral }
ports: [{ name: http, port: 80, targetPort: 8080 }]
+3
View File
@@ -0,0 +1,3 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources: [deployment.yaml, service.yaml]
+30
View File
@@ -0,0 +1,30 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: kelp
namespace: demo
spec:
replicas: 2
selector: { matchLabels: { app: kelp } }
template:
metadata:
labels: { app: kelp }
spec:
containers:
- name: app
image: blahaj-bun:dev
imagePullPolicy: IfNotPresent
ports: [{ containerPort: 8080, name: http }]
env:
- { name: SERVICE_NAME, value: "kelp" }
- { name: SERVICE_EMOJI, value: "🌿" }
- { name: FRIEND_NAME, value: "blahaj" }
---
apiVersion: v1
kind: Service
metadata:
name: kelp
namespace: demo
spec:
selector: { app: kelp }
ports: [{ name: http, port: 80, targetPort: 8080 }]
+5
View File
@@ -0,0 +1,5 @@
# eh I wanted to try it
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources: [deployment.yaml, service.yaml]
+6
View File
@@ -0,0 +1,6 @@
FROM oven/bun:1.1.31-alpine
WORKDIR /app
COPY server.mjs ./server.mjs
COPY public ./public
EXPOSE 8080
CMD ["bun", "run", "server.mjs"]
+26
View File
@@ -0,0 +1,26 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: reef
namespace: demo
spec:
replicas: 1
selector: { matchLabels: { app: reef } }
template:
metadata:
labels: { app: reef }
spec:
containers:
- name: app
image: blahaj-bun:dev
imagePullPolicy: IfNotPresent
ports: [{ name: http, containerPort: 8080 }]
---
apiVersion: v1
kind: Service
metadata:
name: reef
namespace: demo
spec:
selector: { app: reef }
ports: [{ name: http, port: 80, targetPort: 8080 }]
+3
View File
@@ -0,0 +1,3 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources: [deployment.yaml]
+44
View File
@@ -0,0 +1,44 @@
const endpoints = [
{ path: '/blahaj', title: 'bubbles greeter (blahaj)' },
{ path: '/kelp', title: 'kelp' },
{ path: '/coral', title: 'coral' },
{ path: '/bubbles', title: 'bubbles' },
];
const cards = document.querySelector('#cards');
function cardDOM({ title, ok, data, error }) {
const el = document.createElement('article');
el.className = `card ${ok ? 'ok' : 'err'}`;
const h2 = document.createElement('h2');
h2.textContent = title;
el.appendChild(h2);
const pre = document.createElement('pre');
pre.textContent = ok ? JSON.stringify(data, null, 2) : String(error || 'error');
el.appendChild(pre);
return el;
}
async function fetchOne(path) {
const r = await fetch(path, { headers: { 'accept': 'application/json' } });
if (!r.ok) throw new Error(`${path} -> ${r.status}`);
return r.json();
}
async function refresh() {
cards.textContent = ''; // clear
for (const ep of endpoints) {
try {
const data = await fetchOne(ep.path);
cards.appendChild(cardDOM({ title: ep.title, ok: true, data }));
} catch (err) {
cards.appendChild(cardDOM({ title: ep.title, ok: false, error: err.message }));
}
}
}
document.querySelector('#refresh').addEventListener('click', () => refresh());
refresh();
+23
View File
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>blåhaj reef</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="/static/style.css" rel="stylesheet" />
</head>
<body>
<header>
<h1>🦈 blåhajs reef</h1>
<p>cute sea-friends saying hi (live from your mesh)</p>
</header>
<main id="cards"></main>
<footer>
<button id="refresh">refresh</button>
</footer>
<script type="module" src="/static/app.js"></script>
</body>
</html>
+94
View File
@@ -0,0 +1,94 @@
/* soft, cute card ui */
/* created by ChatGPT because god help me I can't UI */
:root {
--bg: #0b132b;
--panel: #1c2541;
--ink: #e0e6ff;
--muted: #9fb3ff;
--ok: #3ddc97;
--err: #ff6b6b;
}
* {
box-sizing: border-box;
}
body {
margin: 0;
font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Inter, sans-serif;
background: var(--bg);
color: var(--ink);
}
header {
padding: 24px;
text-align: center;
}
header h1 {
margin: 0 0 8px 0;
font-size: 28px;
}
header p {
margin: 0;
color: var(--muted);
}
#cards {
display: grid;
gap: 16px;
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
padding: 16px;
max-width: 1200px;
margin: 0 auto;
}
.card {
background: var(--panel);
border-radius: 16px;
padding: 16px;
box-shadow: 0 10px 24px rgba(0, 0, 0, .25);
border: 1px solid rgba(255, 255, 255, .06);
}
.card.ok {
outline: 2px solid var(--ok);
}
.card.err {
outline: 2px solid var(--err);
}
.card h2 {
margin: 0 0 8px 0;
font-size: 18px;
}
.card pre {
margin: 0;
white-space: pre-wrap;
word-break: break-word;
font-size: 13px;
color: #e9f2ff;
}
footer {
display: flex;
justify-content: center;
padding: 16px 0 32px;
}
button {
background: var(--ok);
color: #002b36;
border: 0;
padding: 10px 16px;
border-radius: 12px;
font-weight: 600;
cursor: pointer;
}
button:hover {
filter: brightness(.95);
}
+16
View File
@@ -0,0 +1,16 @@
const serveFile = (path) => new Response(Bun.file(path));
const server = Bun.serve({
port: Number(process.env.PORT || 8080),
async fetch(req) {
const url = new URL(req.url);
if (url.pathname === '/') return serveFile('./public/index.html');
if (url.pathname.startsWith('/static/')) {
return serveFile(`.${url.pathname}`);
}
return serveFile('./public/index.html');
},
});
console.log(`reef listening on ${server.port};`);
+17
View File
@@ -0,0 +1,17 @@
# THE C H I L D
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: app-kelp
namespace: argocd
spec:
project: default
source:
repoURL: https://github.com/ION606/argo-temp.git
targetRevision: blahaj-app
path: apps/kelp
destination:
server: https://kubernetes.default.svc
namespace: demo
syncPolicy:
automated: { prune: true, selfHeal: true }
+17
View File
@@ -0,0 +1,17 @@
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: blahaj-root
namespace: argocd
spec:
project: default
source:
repoURL: https://github.com/ION606/argo-temp.git
targetRevision: blahaj-app
path: environments/dev
directory: { recurse: true }
destination:
server: https://kubernetes.default.svc
namespace: argocd
syncPolicy:
automated: { prune: true, selfHeal: true }
+11
View File
@@ -0,0 +1,11 @@
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: blahaj-gw
namespace: demo
spec:
gatewayClassName: istio
listeners:
- name: http
port: 80
protocol: HTTP
+18
View File
@@ -0,0 +1,18 @@
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: blahaj-routes
namespace: demo
spec:
parentRefs: [{ name: blahaj-gw }]
rules:
- matches: [{ path: { type: PathPrefix, value: "/" } }]
backendRefs: [{ name: reef, port: 80 }]
- matches: [{ path: { type: PathPrefix, value: "/kelp" } }]
backendRefs: [{ name: kelp, port: 80 }]
- matches: [{ path: { type: PathPrefix, value: "/coral" } }]
backendRefs: [{ name: coral, port: 80 }]
- matches: [{ path: { type: PathPrefix, value: "/bubbles" } }]
backendRefs: [{ name: bubbles, port: 80 }]
- matches: [{ path: { type: PathPrefix, value: "/blahaj" } }]
backendRefs: [{ name: bubbles, port: 80 }]
+6
View File
@@ -0,0 +1,6 @@
apiVersion: v1
kind: Namespace
metadata:
name: demo
labels:
istio.io/dataplane-mode: ambient
+17
View File
@@ -0,0 +1,17 @@
# build locally and and load into minikube
docker build -t blahaj-bun:dev -f apps/blahaj-common/bun.Dockerfile apps/blahaj-common;
docker build -t blahaj-bun:dev -f apps/reef/Dockerfile apps/reef;
minikube image load blahaj-bun:dev;
# apply k8s (plus existing kelp/coral/bubbles apps)
kubectl apply -f apps/reef/kustomization.yaml -n demo --server-side --force-conflicts || true;
kubectl -n demo apply -f apps/reef/deployment.yaml;
kubectl -n demo apply -f apps/reef/kustomization.yaml;
# ensure gateway + route exist (from env files)
kubectl -n demo apply -f environments/dev/gateway.yaml;
kubectl -n demo apply -f environments/dev/httproute.yaml;
# open the gateway service
minikube service -n istio-gateway -l gateway.istio.io/managed=yes --url
# isit http://<host>:80/ (cards!)