Slide 1

Slide 1 text

Moving From Legacy Infrastructure to Kubernetes Luka.Huang@mopcon 2020

Slide 2

Slide 2 text

Self Intro • Luka Huang • Senior Backend Developer works for Splashtop

Slide 3

Slide 3 text

Self Intro • Luka Huang • Senior Backend Developer works for Splashtop • Medium - Luka Huang

Slide 4

Slide 4 text

Self Intro • Luka Huang • Senior Backend Developer works for Splashtop • Medium - Luka Huang • A Curator of StarBugs Weekly

Slide 5

Slide 5 text

Self Intro • Luka Huang • Senior Backend Developer works for Splashtop • Medium - Luka Huang • A Curator of StarBugs Weekly • Creator of CodeShiba https://www.facebook.com/CodeShiba

Slide 6

Slide 6 text

Career 1. Web Developer 
 ( Ruby on Rails + Vue.js) 2. Backend Developer 3. Interested in DevOps 
 ( Terraform / Docker / Kubernetes … etc)

Slide 7

Slide 7 text

Involve in Large-scale System 1. It’s exciting 2. Knowledge is important 3. Can earn more money

Slide 8

Slide 8 text

想要分享的原因

Slide 9

Slide 9 text

難得的機會 將近 10 年的系統,要遷移至 Kubernetes 需要承載很⼤的流量 對停機時間非常要求 ⾶到矽⾕與架構師、顧問開會,討論、學習如何架構系統 實際參與「開始」到「上線」的完整的過程

Slide 10

Slide 10 text

延伸 如何將「遺留程式碼」的觀念,⽤在處理「遺留架構」上 ⼗倍⼯程師是怎麼樣的存在︖ 離國際型的⼈才,距離有多遠︖

Slide 11

Slide 11 text

Outline • Why we move to Kubernetes ? • Introduction to Kubernetes & IAC • Move legacy infrastructure to K8s • Legacy infrastructure vs Legacy Code • Talking about 10x Engineer • Conclustion

Slide 12

Slide 12 text

Why we move to Kubernetes ? 為什麼要使⽤ Kubernetes ?

Slide 13

Slide 13 text

過得好好的,為什什麼要⽤用 K8S ?

Slide 14

Slide 14 text

契機

Slide 15

Slide 15 text

啟動歐洲區

Slide 16

Slide 16 text

如果要擴展歐洲業務, 要建立⼀一個獨立的系統

Slide 17

Slide 17 text

GDPR

Slide 18

Slide 18 text

GDPR

Slide 19

Slide 19 text

好嚴格阿!

Slide 20

Slide 20 text

⽤用原來來的架構再搭⼀一套不好嘛?

Slide 21

Slide 21 text

Single system Infrastructure Layer (EC2、VPC、RDS … etc) Application Layer(API, Web, Worker, … etc ) Testing by QA

Slide 22

Slide 22 text

Clone the entire system 2 * Infrastructure Layer (EC2、VPC、RDS … etc) 2 * Application Layer(API, Web, Worker, … etc ) 2 * Testing by QA The new system is 90% the same as original system.

Slide 23

Slide 23 text


 in the code and 
 in the infrastructure Don’t Repeat Yourself

Slide 24

Slide 24 text

插曲,轉折點

Slide 25

Slide 25 text

顧問降臨臨 直到,從矽⾕的顧問⾶來台北辦公室

Slide 26

Slide 26 text

介紹了了⼀一下 K8S 技術

Slide 27

Slide 27 text

了了解 infrastructure

Slide 28

Slide 28 text

有⽤用 CI 跑測試很棒

Slide 29

Slide 29 text

兩兩週後,宣布要使⽤用 K8S

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

眾⼈人:(驚)真的假的?要⽤用 K8S?沒有⼈人會耶

Slide 32

Slide 32 text

兩兩週後,集結最⾼高戰⼒力力,開始作戰。

Slide 33

Slide 33 text

我扮演的⾓角⾊色 在遷移至 K8S 這個專案中,主要的後端開發者 負責容器化後端的服務 負責將以前的架構解析,遷移至 K8S 跨團隊協作,與 QA、Auto-testing、DevOps Team 合作 與矽⾕的架構師與顧問合⼒實作後端架構

Slide 34

Slide 34 text

順利利啟動歐洲區

Slide 35

Slide 35 text

Introduction to Kubernetes & IAC

Slide 36

Slide 36 text

Kubernetes 就是

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

傳統架構 vs K8S 架構

Slide 39

Slide 39 text

https://thenewstack.io/7-features-that-make-kubernetes-ideal-for-ci-cd/ Traditional Framework

Slide 40

Slide 40 text

https://thenewstack.io/7-features-that-make-kubernetes-ideal-for-ci-cd/ Using Docker without K8S

Slide 41

Slide 41 text

https://thenewstack.io/7-features-that-make-kubernetes-ideal-for-ci-cd/ K8S

Slide 42

Slide 42 text

簡單介紹 K8S Kubernetes 重要元件介紹: Node Pod Service Deployment Ingress

Slide 43

Slide 43 text

https://thenewstack.io/7-features-that-make-kubernetes-ideal-for-ci-cd/ Node

Slide 44

Slide 44 text

https://thenewstack.io/7-features-that-make-kubernetes-ideal-for-ci-cd/ Pod

Slide 45

Slide 45 text

https://thenewstack.io/7-features-that-make-kubernetes-ideal-for-ci-cd/ Service & Deployment

Slide 46

Slide 46 text

https://thenewstack.io/7-features-that-make-kubernetes-ideal-for-ci-cd/ Ingress

Slide 47

Slide 47 text

Helm ⽤法有點像是你想要在 ubuntu 系統下安裝 vim 輸入 apt install vim 即可安裝完成 那在 K8S 的世界,你想要安裝⼀個 wordpress 只要輸入 helm install my-wordpress wordpress
 (指令為簡略⽰意版)

Slide 48

Slide 48 text

Terraform https://geekflare.com/terraform-for-beginners/

Slide 49

Slide 49 text

Moving from legacy infrastructure
 to Kubernetes

Slide 50

Slide 50 text

but how?

Slide 51

Slide 51 text

第⼀一個難題

Slide 52

Slide 52 text

如何了了解⽬目前的系統?

Slide 53

Slide 53 text

Part 1 - 從 Application Level 了了解

Slide 54

Slide 54 text

Application level Application level - 應⽤程式層 API Server Web Server Worker Other Service

Slide 55

Slide 55 text

伺服器上藏著許多⼤大密寶

Slide 56

Slide 56 text

幾種⼤大密寶 init.d - 伺服器上藏了多少初始化⼤密寶 (shell script) ? system.d - 伺服器上藏了多少服務型⼤密寶 (shell script) ? monit.d - 伺服器上藏了多少監控型⼤密寶 (shell script) ?

Slide 57

Slide 57 text

init.d init.d - 伺服器上藏了多少初始化⼤密寶 (shell script) ? 服務啟動腳本通通放置於 /etc/init.d/ 底下 init 是開機後核⼼主動呼叫 根據使⽤者⾃訂的執⾏等級 (runlevel) 來喚醒不同的服務

Slide 58

Slide 58 text

system.d 伺服器上藏了多少服務型⼤密寶 (shell script) ? 系統初始化需要做的事情非常多 每⼀步驟被 system.d 抽象成⼀個單元 service - 代表⼀個後台 process,例如: mysqld, httpd, … etc IUUQGFMJYMJODPNMJOVYJOJU&#$&$&"%#&"#&#%&##$&##"&&MJOVY&%&"#&$JOJU&###&##&'#$$&"$"$&"&TZTUFNE

Slide 59

Slide 59 text

system.d https://linuxhint.com/list_service_systemd/

Slide 60

Slide 60 text

monit.d 可以⾃動修復已經停⽌的程序 不需要⼈⼯⼲預 所以這些需要 monit 的 process,是重要的

Slide 61

Slide 61 text

Nginx / Apache Config init.d - 伺服器上藏了多少初始化⼤密寶 (shell script) ? system.d - 伺服器上藏了多少服務型⼤密寶 (shell script) ? monit.d - 伺服器上藏了多少監控型⼤密寶 (shell script) ? Nginx / Apache 的 config 做了哪些設定︖

Slide 62

Slide 62 text

Nginx Config IUUQTTUBDLPWFSGMPXDPNRVFTUJPOTIPXEPJNBLFNZMBSBWFMBQQXPSLPOBOHJOYTFSWFS

Slide 63

Slide 63 text

發現了了⼤大密寶之後

Slide 64

Slide 64 text

還是要出來來⾯面對

Slide 65

Slide 65 text

把這些搬到 K8S 上⾯面

Slide 66

Slide 66 text

好東⻄西,不搬嘛?

Slide 67

Slide 67 text

搬!哪次不搬?

Slide 68

Slide 68 text

所以要怎麼搬呢?

Slide 69

Slide 69 text

K8S 對應的元件 init.d - 初始化⼤密寶 => entrypoint

Slide 70

Slide 70 text

K8S 對應的元件 init.d - 初始化⼤密寶 => entrypoint system.d - 服務型⼤密寶 => K8S 讓 pod 中的 process 變得單純

Slide 71

Slide 71 text

K8S 對應的元件 init.d - 初始化⼤密寶 => entrypoint system.d - 服務型⼤密寶 => docker / entrypoint monit.d - 監控型⼤密寶 => 運⽤ K8S 對 pod 的監控機制

Slide 72

Slide 72 text

K8S 對應的元件 init.d - 初始化⼤密寶 => entrypoint system.d - 服務型⼤密寶 => docker / entrypoint monit.d - 監控型⼤密寶 => 運⽤ K8S 對 pod 的監控機制 Nginx / Apache 的 config => ingress 的設定

Slide 73

Slide 73 text

Part 2 - 從 Deployment 了了解

Slide 74

Slide 74 text

如何更更新 code ,達到持續部屬(CD)的⽬目標

Slide 75

Slide 75 text

以前的⽅方法是把 code 拉到伺服器上⾯面

Slide 76

Slide 76 text

傳統的⽅方法是把 code 拉到伺服器上⾯面, 再去重啟

Slide 77

Slide 77 text

可能透過⼀一些⼯工具去協助你,但原理理⼤大概 就是這樣。

Slide 78

Slide 78 text

進入 kubernetes 的世界之後

Slide 79

Slide 79 text

使⽤用 Docker 是比較有效益的作法

Slide 80

Slide 80 text

Docker 跟 Ansible 相比 Docker 不太會跟環境相依,Ansible 會

Slide 81

Slide 81 text

同樣的腳本,有時候 Ansible 會莫名其妙的失敗, 可能是作業系統不同或是某種套件版本不⼀一導致

Slide 82

Slide 82 text

現代化,使⽤用 docker + kubernetes 的機制 進⾏行行部屬

Slide 83

Slide 83 text

kubernetes 有很完整的機制達到更更新 pod 的 版本,卻不會讓使⽤用者感到存在停機時間

Slide 84

Slide 84 text

K8S - pod 的⽣生命週期 readiness probe - 確保 pod 就緒才把流量導進來 liveness probe - 確保 pod 還是在正常⼯作,否則 kubernetes 會終⽌這個 pod 並重啟。

Slide 85

Slide 85 text

Part 3 - Infrastructure layer

Slide 86

Slide 86 text

IAC - Infrastructure as Code Terraform - 把所有的基礎設施寫成程式碼,例如:EC2、S3、 VPC ... etc,使⽤ Terraform 來撰寫。 Docker - 把安裝在機器中的東西也寫成程式碼,例如:⽤ apt install nginx 之類的套件,可以⽤ Ansible / Docker 來寫。 Kubernetes - 能夠將所有機器變成⼀個⼤平台。透過修改 K8S 的設定檔即可完成所需架構。

Slide 87

Slide 87 text

如果可以把 infrastruce 寫成 code,其 實就可以⽤用程式碼的概念念來來套⽤用

Slide 88

Slide 88 text

實現 IAC 的步驟 實現 IAC 的第⼀步 - ⽤ Docker 建⽴ test image 實現 IAC 的第⼆步 - ⽤ Ansible 寫出 Staging 伺服器配置 實現 IAC 的第三步 - 設計新的架構來對應舊架構 實現 IAC 的最終⽬標 - 所有的改動,都使⽤ Terrafrom + Helm

Slide 89

Slide 89 text

進入到今天的重點

Slide 90

Slide 90 text

Legacy infrastructure vs Legacy Code

Slide 91

Slide 91 text

Legacy Code 怎麼樣的程式碼是 Legacy Code ?

Slide 92

Slide 92 text

Legacy Code 1. 別⼈寫的

Slide 93

Slide 93 text

Legacy Code 1. 別⼈寫的 2. 也可能是⾃⼰寫的

Slide 94

Slide 94 text

Legacy Code 1. 別⼈寫的 2. 也可能是⾃⼰寫的 3. 沒有測試覆蓋

Slide 95

Slide 95 text

Legacy Code 1. 別⼈寫的 2. 也可能是⾃⼰寫的 3. 沒有測試覆蓋 4. 測試無法表達意圖

Slide 96

Slide 96 text

Keywords 1. Legacy Code 2. Unit Test 3. Refactor 4. TDD (Test Driven Development)

Slide 97

Slide 97 text

如果⾃自⼰己讀不懂的話

Slide 98

Slide 98 text

可以找他

Slide 99

Slide 99 text

No content

Slide 100

Slide 100 text

91 敏捷開發之路路 1. Legacy Code 2. Unit Test 3. Refactor 4. TDD (Test Driven Development)

Slide 101

Slide 101 text

Legacy Infrastructure 怎麼樣的架構是遺留架構︖

Slide 102

Slide 102 text

Legacy Infrastructure 1. 別⼈架設的伺服器

Slide 103

Slide 103 text

Legacy Infrastructure 1. 別⼈架設的伺服器 2. 也可以能是⾃⼰架設的

Slide 104

Slide 104 text

Legacy Infrastructure 1. 別⼈架設的伺服器 2. 也可以能是⾃⼰架設的 3. 沒有測試覆蓋

Slide 105

Slide 105 text

Legacy Infrastructure 1. 別⼈架設的伺服器 2. 也可以能是⾃⼰架設的 3. 沒有測試覆蓋 4. 測試無法表達意圖

Slide 106

Slide 106 text

Can we write down tests on infrastructure?

Slide 107

Slide 107 text

Yes, we can.

Slide 108

Slide 108 text

Testing on Infrastructure 1. End-to-End testing

Slide 109

Slide 109 text

Testing on Infrastructure 1. End-to-End testing 2. Nightly build

Slide 110

Slide 110 text

Testing on Infrastructure 1. End-to-End testing 2. Nightly build 3. Load Testing

Slide 111

Slide 111 text

Testing on Infrastructure 1. End-to-End testing => 功能正確 2. Nightly build => 修改後的架構可以提供正常服務 3. Load Testing => 修改後的架構可以承載⼤流量 4. 這些都整合在 CI / CD 裡⾯

Slide 112

Slide 112 text

Refactor 程式碼的 Refactor

Slide 113

Slide 113 text

Refactor 的⽤用意 • 降低未來修改的成本 • 降低未來理解程式碼的成本

Slide 114

Slide 114 text

Refactor Infrastructure 架構⾯的 Refactor

Slide 115

Slide 115 text

Refactor Infrastructure • 架構也是⼀樣的道理 • 降低未來修改的成本 • 降低未來理解程式碼的成本

Slide 116

Slide 116 text

Refactor Infrastructure • 相同的事情,有沒有更簡單,更容易懂的作法︖例如: • 公司內網才能使⽤管理員後台 • 資料庫只能被 Application Server 存取 • S3 只能由被 Application Server 存取

Slide 117

Slide 117 text

Refactor Infrastructure • 我們可以藉由不斷的重構,讓 IAC 的 Code 變得越來 越直覺。 • 以後需要變動架構的時候,才不會覺得很痛苦,不知 道怎麼改起

Slide 118

Slide 118 text

10x Engineer

Slide 119

Slide 119 text

⼗倍⼯程師是否真的存在︖

Slide 120

Slide 120 text

有⼈說,我以前不相信⼗倍⼯程師的 存在,直到我遇到了 1/10 ⼯程師

Slide 121

Slide 121 text

真的有⼗倍⼯程師存在嘛︖

Slide 122

Slide 122 text

是的,真的有⼗倍⼯程師的存在

Slide 123

Slide 123 text

⼗倍⼯程師是怎麼樣的⼈︖

Slide 124

Slide 124 text

⼗十倍⼯工程師 技術又深又廣,每⼀個點的技術都比你強 Web Infrastructure Endpoint K8S

Slide 125

Slide 125 text

⼗十倍⼯工程師 強⼤的跨⽂化溝通能⼒與跨團隊溝通能⼒ Backend DevOps Ops QA Auto Testing

Slide 126

Slide 126 text

⼗十倍⼯工程師 語⾔能⼒ 英⽂ (native) ⽇⽂ 中⽂ (最近學的)

Slide 127

Slide 127 text

⼗十倍⼯工程師 能夠說服公司採⽤⽅案 有很強的技術不是⼀切 技術強,也要想辦法轉換成價值,讓公司買單 並且真的做出來,產⽣效益

Slide 128

Slide 128 text

⼗十倍⼯工程師 ⾜夠⼤的市場 市場規模,決定你的想像⼒ 技術強,思維也要跟上,才能解決更⼤市場的問題 如何讓⾃⼰可以接觸這樣的市場就是⼀個重要的課題

Slide 129

Slide 129 text

⼗十倍⼯工程師 ⼤家多多嘗試進軍世界舞台,可以看到不⼀樣的世界

Slide 130

Slide 130 text

Conclusion 了解 K8S、Helm、Terraform … 等等技術名詞的意義。 了解傳統作法與新的 Terraform + K8S 技術體系的差異 了解頗析⼀個舊架構,遷移至 K8S 為中⼼的雲原⽣架構的過程。 了解如何重構舊架構 聽到了⼀個⼗倍⼯程師的故事

Slide 131

Slide 131 text

Thanks for listening