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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Hazel Shen
August 09, 2021
Technology
69
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
220
PyLadies 女科技人的多元職涯發展 - 2021/01/10
hazel910159
1
280
Introduction_to_Apache_Submarine
hazel910159
0
120
Integrating Ansible Automation and ChatOps
hazel910159
0
140
雲原生基礎設施
hazel910159
0
240
Other Decks in Technology
See All in Technology
ハーレムエンジニアリング
kazuma777777
0
190
Invisible to AI? Making TYPO3 Sites Quotable by AI Search Systems
wolfgangwagner
0
240
Kiro Crew入門 - 常駐エージェントの仕組みと使いどころ / Intro to Kiro Crew
k_adachi_01
1
630
【GCC2026】大規模言語モデルを活用した内製検索サービスの社内展開や業務活用
bandainamcostudios
PRO
0
350
Oracle MCP Servers Explained
thatjeffsmith
0
290
35分でわかるEffective Platform Engineering
nwiizo
5
550
Software Supply Chain Attackからクラウド環境を守るためにできること
lhazy
2
290
コーチングの奥義 何もしないテクニック
jinwatanabe
0
140
Adding Right-to-Left support to your web application with CSS logical properties — Lessons from Redmine
vividtone
0
160
AIペネトレーションテスト・ セキュリティ検証「AgenticSec」紹介資料
laysakura
2
9.3k
属人化を叩き割れ!「制作加速」と「安定化」の矛盾を打破する:8年目プロダクトが辿り着いた「ミスが起こり得ない」アセット制作フローの全貌
gree_tech
PRO
0
120
MulticaとPi Coding Agentで、小規模OSSを30本同時運用した流れ
eiei114
0
130
Featured
See All Featured
Game over? The fight for quality and originality in the time of robots
wayneb77
1
250
Are puppies a ranking factor?
jonoalderson
2
3.8k
Evolving SEO for Evolving Search Engines
ryanjones
0
260
Typedesign – Prime Four
hannesfritz
42
3.1k
Raft: Consensus for Rubyists
vanstee
141
7.6k
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
The Spectacular Lies of Maps
axbom
PRO
1
930
Designing for humans not robots
tammielis
254
26k
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
64
56k
We Are The Robots
honzajavorek
0
300
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
410
Color Theory Basics | Prateek | Gurzu
gurzu
0
430
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