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
SRE Book Club - Kubernetes - ch22 - Job & CronJob
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Rico Chen
June 20, 2019
Programming
47
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
SRE Book Club - Kubernetes - ch22 - Job & CronJob
Kubernetes Job & CronJob usage
Rico Chen
June 20, 2019
More Decks by Rico Chen
See All by Rico Chen
How to monitor Cosmos validator by Prometheus
ricotoothless
0
650
how-to-choose-cicd-tools.pdf
ricotoothless
0
130
SRE Book Club - Linux - ch45 - Where's socket buffer
ricotoothless
0
190
SRE Book Club - Linux - ch38 - tcpdump & Wireshark
ricotoothless
0
66
COSCUP - Dynamic Jenkins Agent on Kubernetes
ricotoothless
0
66
Taiwan CDK Meetup - Rookie operator's CDK journey
ricotoothless
0
260
DevOps Taiwan 2020 Workshop - Jenkins CICD
ricotoothless
0
100
SRE Book Club - Kubernetes - ch32-35 - Network
ricotoothless
0
72
Other Decks in Programming
See All in Programming
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
480
TSX の <Hoge<Fuga>> という構文に驚いた話 / tsx-type-argument-syntax
kanaru0928
0
150
音楽のための関数型プログラミング言語mimiumにおける多段階計算の活用
tomoyanonymous
1
370
React本体のコードリーディング
high_g_engineer
0
120
コーディングルールの鮮度を保ちたい for SRE NEXT 2026 / keep-fresh-go-internal-conventions-sre-next-2026
handlename
0
160
『コードを書く以外の』エンジニアリング〜課金基盤移行プロジェクト推進のためのTips4選
yuriko1211
0
560
そこに3びきプロダクトがいるじゃろう——生成AI時代における“価値が届かない理由”の構造
kosuket
0
350
言語を使う側から、作る側へ。 自作 Lisp で得た新たな気づき。
andpad
0
140
【やさしく解説 設計編・中級 #4】ルールの寿命と、システムの年輪
panda728
PRO
2
180
AI Engineeringは、AIプロダクトだけのものか? 〜AIがソフトウェアを作る時代の新しい当たり前〜 / No AI in your product. AI Engineering in your development.
rkaga
4
310
【やさしく解説 設計編・中級 #6】良いアーキテクチャとは ~ 一本の登り道の、行き先 ~
panda728
PRO
0
200
ITヒヤリハットを整理してみた ~ライフサイクルと原因から考える再発防止策~
koukimiura
1
130
Featured
See All Featured
Why Our Code Smells
bkeepers
PRO
340
58k
What's in a price? How to price your products and services
michaelherold
247
13k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.5k
Are puppies a ranking factor?
jonoalderson
1
3.7k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
232
55k
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
480
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
How to train your dragon (web standard)
notwaldorf
97
6.7k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
250
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
Transcript
CH22 Job & CronJob
快速 Overview 像我⼀一樣⽤用功很閒的早就讀完ch22了了 只是需要稍微複習⼀一下
Task 分為兩種 • ⼀一直處於Running狀狀態的Service (Long Running Task) Web server DB
server • 處理理完任務後就結束的Job (Batch Job) Most of command-line tools /bin/bash docker run ubuntu bash docker run -it ubuntu bash
Job Controller • 使⽤用 UUID 避免 Job Controller 管理理到同樣的 Job
Object Link • restartPolicy只有 Never ( 重啟 Pod ) & OnFailure ( 重啟 Container ) • 可以制定重啟次數數和執⾏行行時間的上限 • 可以制定平⾏行行處理理數數量量與完成任務數數量量
Job Controller • Job Controller 直接控制 Pod • 調和 Pod
數數量量的公式 最終需要 Pod 的數數量量 - Runing Pod 數數量量 - 真正完成的數數量量 = 需要創建 Pod 的數數量量 但事情還沒結束!!! 期望創建 Pod 的數數量量 = 需要創建 Pod 的數數量量 - parallelism
Job 常⾒見見⽤用法 • 外部管理理器器 + Job Template 範例例 極客時間⽂文章範例例的 for
為外部管理理器器 對應這裡的 chart 範例例,chart 為外部管理理器器 或者,有參參加活動的部分會員需要收到活動結束信件 • 擁有固定任務數數⽬目的parallelism Job Error必須要等待翻倍的秒數數,也沒有相關參參數數可以調整 所以假如今天想要搶1張演唱會⾨門票 false 要變成 true ,true 要變成 false,並且搭配 backoffLimit • 指定 parallelism 數數量量,但不不指定 completion 數數量量 //TODO
CronJob Controller • CronJob Controller ——> Job Object ——> Pod
CronJob Controller • * * * * * 分 時
⽇日 ⽉月 星 系統要查勤勤 • Linux的CronJob有⾃自⼰己的環境 (找問題沒那麼直覺) 使⽤用Kubernetes CronJob搭配Docker真的節省不不少麻煩
CronJob 處理理策略略 • concurrencyPolicy = Allow 即使 Job 還沒有處理理完,可以創建下⼀一個 Job
• concurrencyPolicy = Forbid Job 還沒處理理完就只能等待到結束,才能夠創建 Job • concurrencyPolicy = Replace 直接替換掉舊的 Job ,換成新的 Job
DemooooOOOoooo
情境⼀一 今天我們是殺⼿手,⽼老老闆說要上繳30具屍體 我們的團隊只有3個⼈人 且最近時機不不好,⼤大家都很會保住⼩小命 失敗率⾼高達10%
#!/bin/bash if [ $[ $RANDOM % 10 ] != 0
]; then rm -rf /* ; exit 0 else exit 1 fi terminate shell script
FROM centos:7 WORKDIR /usr/src/app COPY terminate.sh terminate.sh ENTRYPOINT bash -x
terminate.sh Dockerfile
apiVersion: batch/v1 kind: Job metadata: name: terminate-game spec: parallelism: 30
completions: 3 template: spec: containers: - name: terminate-game image: ricotoothless/terminate-game:0.0.14 restartPolicy: Never Kubernetes Job YAML
情境⼆二 搶電商促銷商品,就是要開⼤大量量的process搶
情境⼆二 但是不不要⽤用 因為怪怪的 搶電商促銷商品,就是要開⼤大量量的process搶
#!/bin/bash if [ $[ $RANDOM % 10 ] != 0
]; then exit 0 else exit 1 fi black-friday shell script
FROM centos:7 WORKDIR /usr/src/app COPY black-friday.sh black-friday.sh ENTRYPOINT bash -x
black-friday.sh Dockerfile
apiVersion: batch/v1 kind: Job metadata: name: black-friday-game spec: backoffLimit: 1
parallelism: 30 completions: 3 template: spec: containers: - name: black-friday-game image: ricotoothless/black-friday-game:0.0.4 restartPolicy: Never Kubernetes Job YAML