Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Kosko - 改用 JavaScript 來管理 Kubernetes YAML (COSC...
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Tommy Chen
September 06, 2021
Technology
110
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Kosko - 改用 JavaScript 來管理 Kubernetes YAML (COSCUP 2021)
Tommy Chen
September 06, 2021
More Decks by Tommy Chen
See All by Tommy Chen
Kosko - 改用 JavaScript 來管理 Kubernetes YAML (Kubernetes Summit 2021)
tommy351
1
1.4k
Kubernetes 101
tommy351
2
290
Socket.io 即時通訊實作
tommy351
0
120
Fast Web Development with Express
tommy351
0
110
An Introduction to Node.js
tommy351
1
330
Other Decks in Technology
See All in Technology
【2026年版】 ベクトル検索とEmbedding最前線
mocobeta
24
7.6k
クラウドファンディング版StackChan 3体(4体)をインタラクティブな体験型作品にして展示もした話 / スタックチャンお誕生日会2026
you
PRO
0
190
アラート調査向けAIエージェントの本番導入とその後/AI Agents for Alert Investigation: Production Deployment and After
taddy_919
1
160
螺旋型キャリアの生存戦略 / kinoko-conf2026
rakus_dev
1
1k
GitHub Copilot 最新アップデート – 「一歩先」の実践活用術
moulongzhang
5
1.9k
サイバーエージェントにおけるAI推進戦略と変革への取り組み
shotatsuge
0
570
データレイクの「見えない問題」を可視化する
sansantech
PRO
1
200
2026-06-24_人とAIの責務分離に基づく開発プロセスの提案.pdf
takahiromatsui
0
190
水を運ぶ人としてのリーダーシップ
izumii19
4
1k
IaC コードを資産へ:AWS CDK 社内ライブラリと横断展開 / aws-summit-japan-2026
gotok365
10
1.6k
Agile and AI Redmine Japan 2026
hiranabe
4
490
#エンジニアBooks 30分でわかる 「技術記事を書く技術」 / engineer-books 2026-06-30
jnchito
1
100
Featured
See All Featured
A designer walks into a library…
pauljervisheath
211
24k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
SEO for Brand Visibility & Recognition
aleyda
0
4.6k
Technical Leadership for Architectural Decision Making
baasie
3
420
[RailsConf 2023] Rails as a piece of cake
palkan
59
6.7k
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
160
Building an army of robots
kneath
306
46k
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
2
240
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
580
Design in an AI World
tapps
1
250
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
170
Balancing Empowerment & Direction
lara
6
1.2k
Transcript
Kosko
None
None
• • • • 👉
None
• • • • • •
• • • • • •
• • • • • • • •
None
• • •
👍 • • • • 👎 • • •
😰
👍 • • • 👎 • • •
None
👍 • • • 👎 • • • 💀
None
Kosko • • • • •
• • • • • • • •
None
None
• • • • •
import { Pod } from "kubernetes-models/v1/Pod"; const pod = new
Pod({ metadata: { name: "busybox" }, spec: { containers: [ { name: "busybox", image: "busybox", command: ["sleep", "10000"] } ] } }); export default pod; apiVersion: v1 kind: Pod metadata: name: busybox spec: containers: - name: busybox image: busybox command: - sleep - '10000'
import { Deployment } from "kubernetes-models/apps/v1/Deployment"; import { Service }
from "kubernetes-models/v1/Service"; const deployment = new Deployment({ metadata: { name: "nginx" }, spec: { // ... } }); const service = new Service({ metadata: { name: "nginx" }, spec: { // ... } }); export default [deployment, service]; --- apiVersion: apps/v1 kind: Deployment metadata: name: nginx --- apiVersion: v1 kind: Service metadata: name: nginx
import { Deployment } from "kubernetes-models/apps/v1/Deployment"; import { Service }
from "kubernetes-models/v1/Service"; import { PersistentVolumeClaim } from "kubernetes- models/v1/PersistentVolumeClaim"; const db = [ new Deployment({ metadata: { name: "mysql" } }), new Service({ metadata: { name: "mysql" } }), new PersistentVolumeClaim({ metadata: { name: "mysql" } }) ]; const deployment = new Deployment({ metadata: { name: "api" } }); const service = new Service({ metadata: { name: "api" } }); export default [db, deployment, service];
--- apiVersion: apps/v1 kind: Deployment metadata: name: mysql --- apiVersion:
v1 kind: Service metadata: name: mysql --- apiVersion: v1 kind: PersistentVolumeClaim metadata: name: mysql --- apiVersion: apps/v1 kind: Deployment metadata: name: api --- apiVersion: v1 kind: Service metadata: name: api
import { Secret } from "kubernetes-models/v1/Secret"; const secret = new
Secret({ metadata: { name: "api-key" }, type: "Opaque", data: { secret: Buffer.from("confidential").toString("base64") } }); export default secret; apiVersion: v1 kind: Secret metadata: name: api-key type: Opaque data: secret: Y29uZmlkZW50aWFs
import { loadFile, loadUrl, loadString } from "@kosko/yaml"; const manifest
= loadFile("manifest.yaml"); const certManager = loadUrl( "https://github.com/jetstack/cert-manager/releases/download/v1.0.4/cert- manager.yaml" ); const pod = loadString(` apiVersion: v1 kind: Pod metadata: name: my-pod `); export default [manifest, certManager, pod];
import { loadChart } from "@kosko/helm"; const prometheus = loadChart({
chart: "prometheus", repo: "https://prometheus-community.github.io/helm-charts", version: "13.6.0" }); export default prometheus;
• • • • • • •
// Global variables - environments/dev/index.js export default { namespace: "dev"
}; // Component variables - environments/dev/nginx.js export default { replicas: 3 }; // components/nginx.js import { Deployment } from "kubernetes-models/apps/v1/Deployment"; import env from "@kosko/env"; const params = env.component("nginx"); // { namespace: "dev", replicas: 3 } const deployment = new Deployment({ metadata: { name: "nginx", namespace: params.namespace }, spec: { replicas: params.replicas, template: { spec: { containers: [{ name: "nginx", image: "nginx:stable" }] } } } }); apiVersion: apps/v1 kind: Deployment metadata: name: nginx namespace: dev spec: replicas: 3 template: spec: containers: - name: nginx image: nginx:stable
• • • • •
None
• • •
None
None
• • • • •
• • • • 👉 •
• • • • •
None
const labels = { app: "demo" }; const deployment =
new Deployment({ spec: { selector: { matchLabels: labels }, template: { metadata: { labels } } } }); const service = new Service({ spec: { selector: labels } });
const httpPort = 80; const deployment = new Deployment({ spec:
{ template: { spec: { containers: [{ ports: [{ containerPort: httpPort }] }] } } } }); const service = new Service({ spec: { ports: [{ port: httpPort }] } });
export function envVars(envs: Record<string, string>): IEnvVar[] { return Object.entries(envs).map(([name, value])
=> { return { name, value }; }); } // Before [ { name: "LOG_LEVEL", value: "info" }, { name: "API_URL", value: "https://example.com" } ]; // After envVars({ LOG_LEVEL: "info", API_URL: "https://example.com" }); • •
function withEnvoy(spec: IPodSpec): IPodSpec { return { ...spec, containers: [
...spec.containers, { name: "envoy", image: "envoyproxy/envoy:v1.17.0" } ] }; } const deployment = new Deployment({ spec: { selector: {}, template: { spec: withEnvoy({ containers: [{ name: "demo", image: "demo" }] }) } } }); apiVersion: apps/v1 kind: Deployment spec: selector: {} template: spec: containers: - name: demo image: demo - name: envoy image: envoyproxy/envoy:v1.17.0
function createDatabase(name: string) { return [ new Deployment({ metadata: {
name } }), new Service({ metadata: { name } }), new PersistentVolumeClaim({ metadata: { name } }) ]; } /* components/post-api.js */ export default [ createDatabase("post-api-db"), new Deployment({ metadata: { name: "post-api" } }), new Service({ metadata: { name: "post-api" } }) ]; /* components/user-api.js */ export default [ createDatabase("user-api-db"), new Deployment({ metadata: { name: "user-api" } }), new Service({ metadata: { name: "user-api" } }) ];
• •
None