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
220
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
アカウントが増えてからでは遅い? ~ マルチアカウント統制の勘所 ~
kenichinakamura
0
140
AIDLC_ヤフーショッピングの取り組み
lycorptech_jp
PRO
0
540
AIに「使われる」時代のSaaS戦略 〜既存WebAPIのMCPサーバー化における開発ノウハウ〜
ekispert_api
0
290
知見・人・API・DB・予算 ─ ナイナイ尽くしだった人事データ整備 with dbt、5年間の学び
ken6377
1
150
どうして今サーバーサイドKotlinを選択したのか
nealle
0
200
product engineering with qa
nealle
0
150
AIペネトレーションテスト・ セキュリティ検証「AgenticSec」紹介資料
laysakura
2
8k
SRE歴2ヶ月でも開発6年の知見を活かして、チームで止まっていた環境改善を前に進めた話
a_ono
1
210
はじめてのWDM
miyukichi_ospf
1
120
証券システムを10年Scalaで作り続けるということ - 関数型まつり2026
krrrr38
3
650
美しいコードを書くためにF#を学んでみた話
yud0uhu
1
210
アラート調査向けAIエージェントの本番導入とその後/AI Agents for Alert Investigation: Production Deployment and After
taddy_919
1
390
Featured
See All Featured
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
6k
Designing Powerful Visuals for Engaging Learning
tmiket
1
440
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
エンジニアに許された特別な時間の終わり
watany
107
250k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.4k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.5k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
230
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
280
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
Building AI with AI
inesmontani
PRO
1
1.1k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
3
1.1k
Evolving SEO for Evolving Search Engines
ryanjones
0
230
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