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
改用 JavaScript 來管理 Kubernetes YAML
Search
Hazel Shen
August 09, 2021
Technology
67
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
改用 JavaScript 來管理 Kubernetes YAML
Hazel Shen
August 09, 2021
More Decks by Hazel Shen
See All by Hazel Shen
9.26-WTM Tech Sharing 從零經驗 QA 到架構師的斬棘之路
hazel910159
0
210
PyLadies 女科技人的多元職涯發展 - 2021/01/10
hazel910159
1
280
Introduction_to_Apache_Submarine
hazel910159
0
120
Integrating Ansible Automation and ChatOps
hazel910159
0
130
雲原生基礎設施
hazel910159
0
240
Other Decks in Technology
See All in Technology
やさしいA2A入門
minorun365
PRO
12
1.8k
新しいVibe Codingと”自走”について
watany
6
320
非エンジニアがClaudeと挑んだ「1ヶ月間プロダクト30本ノック」
askokc
0
480
SONiC Scale-Up Working Group から探る Scale-UpやUltraEthernet機能の実装方法
ebiken
PRO
2
320
Oracle AI Database@Azure:サービス概要のご紹介
oracle4engineer
PRO
6
2k
Bucharest Tech Week 2026 - Reinventing testing practices in the AI era
edeandrea
PRO
1
150
AIエージェントが名古屋の猛暑からあなたを守る
happysamurai294
0
110
RSA暗号を手計算したくなること、ありますよね?? (20260615_orestudy6_rsa)
thousanda
0
380
Kubernetesにおける学習基盤とLLMOpsの概要
ry
1
300
SONiCのLinuxベースを活かしたZabbix監視
sonic
0
150
エンジニアリング戦略の作り方 / Crafting Engineering Strategy
iwashi86
21
6.9k
NAB Show 2026 動画技術関連レポート / NAB Show 2026 Report
cyberagentdevelopers
PRO
0
200
Featured
See All Featured
4 Signs Your Business is Dying
shpigford
187
22k
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
210
Ruling the World: When Life Gets Gamed
codingconduct
0
250
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
370
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
210
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
170
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
380
Thoughts on Productivity
jonyablonski
76
5.2k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.7k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
410
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
610
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.5k
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