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
エンジニアリング戦略の作り方 / Crafting Engineering Strategy
iwashi86
21
6.9k
2026TECHFRESH畢業分享會 - Lightning Talk - 資料也要 CI/CD? 用 Airbyte 自動化資料同步
line_developers_tw
PRO
0
970
"何を作るか"を任される エンジニアは、どう育つのか
yutaokafuji
1
680
あなたの AI ワークスペースに、 専門コーダーを連れてくる - Amazon Quick Desktop 最新情報
kawaji_scratch
1
140
SONiCの統計情報を取得したい
sonic
0
150
SONiC Scale-Up Working Group から探る Scale-UpやUltraEthernet機能の実装方法
ebiken
PRO
2
320
AIの性能が向上しても未解決な組織の重大問題は何か?/An Unsolved Organizational Problem in the Age of AI
moriyuya
4
660
就職⽀援サービスにおけるキャリアアドバイザーのシフトスケジューリング
recruitengineers
PRO
1
140
Android の公式 Skill / Android skills
yanzm
0
140
AAIFに入ってみた ~内から見えるコミュニティ動向~
sato4
0
200
小さく始める AI 活用推進 ― 日経電子版 Web チームの事例/nikkei-tech-talk47
nikkei_engineer_recruiting
0
260
Featured
See All Featured
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
160
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
530
The Cult of Friendly URLs
andyhume
79
6.9k
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
1
1.7k
Information Architects: The Missing Link in Design Systems
soysaucechin
0
970
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2.1k
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
250
How GitHub (no longer) Works
holman
316
150k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.1k
What's in a price? How to price your products and services
michaelherold
247
13k
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.5k
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