Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

給 RD 的 Kubernetes 初體驗 (GDG Cloud KH 2019-08 version)

665 views

Published on

In: GDG Cloud KH Meetup #4 (2019-08-11)
Event: https://www.meetup.com/GCPUG-Kaohsiung/events/262412299/
Lab: https://github.com/William-Yeh/workshop-k8s201908

● 簡介

Kubernetes 是目前雲端環境的顯學。可是,傳統的程式,並不是原封不動搬上去,就能夠自動享受 Kubernetes 所宣稱的種種好處。

新的環境,不僅需要新的 Ops 思維,也需要新的 Dev 思維。我們將以三小時的時間,從軟體研發者的角度,探討軟體的設計該做哪些最起碼的改變,並體驗 Kubernetes 引進的新觀念及新效益。

● 目標

從實例中體驗,傳統 web 應用程式在搬上 Kubernetes 時,可能會經歷哪些架構面的調整,才能享受新架構的效益:
- 容器化
- 微服務
- 組態管理
- 多重環境管理:本機端與雲端(以 GKE 為例)
- Canary release。

● 適合對象

已經具備 Docker 基本操作能力、簡單的 Web 前後端觀念,想進一步體驗 Kubernetes 的軟體研發者。

本工作坊不會涉及太多維運層面。

Published in: Technology

給 RD 的 Kubernetes 初體驗 (GDG Cloud KH 2019-08 version)

  1. 1. Technical Manager William Yeh 葉秉哲  給 RD 的 Kubernetes 初體驗 … with a series of hands-on labs 2019-08-11
  2. 2. • PhD in Computer Science, NCTU, Taiwan • CSPO (Certified Scrum Product Owner) from Scrum Alliance • PSM I (Professional Scrum Master I) from Scrum.org • Technical manager @ Titansoft (since Mar 2019) • Server director & Scrum master @ Gogolook • Active speaker and trainer for software architecture, DevOps, agile, and theory of constraints
  3. 3. Containers Kubernetes Cloud Agenda
  4. 4. Containers Kubernetes Cloud Agenda Labs 1.0 — 3.0 4.0 — 5.0 6.0 — 7.0
  5. 5. Agenda Know promising trends Adopt gradually Prepare mindset Goals Containers Kubernetes Cloud Labs 1.0 — 3.0 4.0 — 5.0 6.0 — 7.0
  6. 6. GKE Setup🅐 a - Redeem Google Cloud coupon b - Create project in GCP c - Create GKE cluster
  7. 7. Redeem coupon Please follow steps in your handout NOW!
  8. 8. Create K8s-enabled Project https://console.cloud.google.com/projectselector2/kuber netes Should already done before you’re here...
  9. 9. Create GKE cluster gcloud config set project PROJECT_ID gcloud config set compute/zone us-west1-a gcloud container clusters create k8s201908 --num-nodes 3
  10. 10. Lab Setting�� Tag 1.0 2.0 3.0 4.0 5.0 6.0 7.0
  11. 11. Lab material See the demo first!
  12. 12. Lab material For each revision, pay attention to: 1. image versions 2. diff in code and configuration Use git diff --stat HEAD~1 HEAD to see diff between revisions. Tag 1.0 2.0 3.0 4.0 5.0 6.0 7.0
  13. 13. Image tags Lab # Frontend API 1.0 N/A N/A 2.0 N/A 2.0 3.0 3.0 3.0 4.0 3.0 3.0 5.0 5.0 3.0 6.0 auto auto 7.0 auto auto & stable
  14. 14. Lab material https://github.com/William-Yeh/workshop-k8s201908 or http://bit.ly/k8s-201908 for short 1. Open browser 2. Git clone to your laptop
  15. 15. Containers 1.0 - Legacy 2.0 - Docker 3.0 - Frontend/backend separation ��
  16. 16. Why containers?
  17. 17. Lab # 1.0 Legacy
  18. 18. Lab # 1.0 git checkout 1.0 git log
  19. 19. Lab # 1.0 Review a. Architecture b. Main tasks c. Diff d. Tricks e. Questions?
  20. 20. app runtime OS kernel app runtime OS kernel Boundary of application packaging: pros and cons traditional deployment way virtual machine
  21. 21. app runtime OS kernel app runtime OS kernel app runtime OS kernel IaC (Infra as Code) traditional deployment way IaC tools ● Chef ● Puppet ● Ansible virtual machine
  22. 22. app runtime OS kernel app runtime OS kernel app runtime OS kernel Containers as application packaging units traditional deployment way container virtual machine
  23. 23. Lab # 2.0 Docker
  24. 24. Lab # 2.0 git checkout 2.0 git log git diff --stat HEAD~1 HEAD
  25. 25. Image tags Lab # Frontend API 1.0 N/A N/A 2.0 N/A 2.0 3.0 3.0 3.0 4.0 3.0 3.0 5.0 5.0 3.0 6.0 auto auto 7.0 auto auto & stable
  26. 26. Lab # 2.0 Review a. Architecture b. Main tasks c. Diff d. Tricks e. Questions?
  27. 27. Lab # 3.0 Frontend/backend separation
  28. 28. Lab # 3.0 git checkout 3.0 git log git diff --stat HEAD~1 HEAD
  29. 29. Image tags Lab # Frontend API 1.0 N/A N/A 2.0 N/A 2.0 3.0 3.0 3.0 4.0 3.0 3.0 5.0 5.0 3.0 6.0 auto auto 7.0 auto auto & stable
  30. 30. app runtime OS kernel app runtime OS kernel app runtime OS kernel Recap: containers as application packaging units traditional deployment way container virtual machine
  31. 31. Lab # 3.0 Review a. Architecture b. Main tasks c. Diff d. Tricks e. Questions?
  32. 32. Kubernetes 4.0 - Local Kubernetes 5.0 - Configuration ��
  33. 33. https://kubernetes.io/
  34. 34. Lab # 4.0 Local Kubernetes
  35. 35. Lab # 4.0 git checkout 4.0 git log git diff --stat HEAD~1 HEAD
  36. 36. Image tags Lab # Frontend API 1.0 N/A N/A 2.0 N/A 2.0 3.0 3.0 3.0 4.0 3.0 3.0 5.0 5.0 3.0 6.0 auto auto 7.0 auto auto & stable
  37. 37. Concept gaps from Docker to Kubernetes
  38. 38. Container
  39. 39. Service container service pod deployment 3
  40. 40. container service . . . └── k8s ├── todoapi-service.yml └── todofrontend-service.yml Service
  41. 41. Service container service pod deployment --- kind: Service ... --- kind: Deployment ... spec: replicas: 3 template: # pod definition spec: containers: - name: todoapi image: todoapi:3.0 k8s/todoapi-service.yml
  42. 42. service deployment --- kind: Service ... --- kind: Deployment ... spec: replicas: 3 template: # pod definition spec: containers: - name: todoapi image: todoapi:3.0 k8s/todoapi-service.yml
  43. 43. container pod --- kind: Service ... --- kind: Deployment ... spec: replicas: 3 template: # pod definition spec: containers: - name: todoapi image: todoapi:3.0
  44. 44. Container
  45. 45. Pod Container Any examples?
  46. 46. • Shared volumes • IPC • Network Multi-Container Pods in Kubernetes Pod Container Multi-container pods and container communication in Kubernetes https://www.mirantis.com/blog/multi-container-pods-and-container-communication-in-kubernetes/
  47. 47. Deployment & Replica 3
  48. 48. pod --- kind: Service ... --- kind: Deployment ... spec: replicas: 3 template: # pod definition spec: containers: - name: todoapi image: todoapi:3.0 deployment
  49. 49. Selector & label 3 The selector field defines how the Deployment finds which Pods to manage. label selector
  50. 50. service deployment --- kind: Service ... --- kind: Deployment ... spec: replicas: 3 template: # pod definition spec: containers: - name: todoapi image: todoapi:3.0
  51. 51. Service label selector 3 --- kind: Service ... --- kind: Deployment ... spec: replicas: 3 template: # pod definition spec: containers: - name: todoapi image: todoapi:3.0
  52. 52. Recap
  53. 53. Service container pod deployment service 3
  54. 54. Service container service pod deployment --- kind: Service ... --- kind: Deployment ... spec: replicas: 3 template: # pod definition spec: containers: - name: todoapi image: todoapi:3.0 k8s/todoapi-service.yml
  55. 55. pod --- kind: Service ... --- kind: Deployment ... spec: replicas: 3 template: # pod definition spec: containers: - name: todoapi image: todoapi:3.0 deployment service container
  56. 56. Kubernetes Terminology Learn by doing!
  57. 57. Make sure you’re using local Kubernetes kubectl config view kubectl config get-contexts kubectl config use-context docker-for-desktop or kubectl config use-context minikube How to use kubectl to manage multiple Kubernetes clusters https://success.docker.com/article/how-to-use-kubectl-to-manage-multiple-kubernetes-clusters
  58. 58. Lab # 4.0 Review a. Architecture b. Main tasks c. Diff d. Tricks e. Questions?
  59. 59. CAUTION ● There’s one big issue in this Lab 4.0 Can you see? ● What if a image changes but version tag remains unchanged?
  60. 60. Lab # 5.0 Configuration
  61. 61. Lab # 5.0 git checkout 5.0 git log git diff --stat HEAD~1 HEAD
  62. 62. Image tags Lab # Frontend API 1.0 N/A N/A 2.0 N/A 2.0 3.0 3.0 3.0 4.0 3.0 3.0 5.0 5.0 3.0 6.0 auto auto 7.0 auto auto & stable
  63. 63. _v2 Service container pod deployment service Recap: containers as application packaging units 3
  64. 64. Lab # 5.0 Review a. Architecture b. Main tasks c. Diff d. Tricks e. Questions?
  65. 65. Cloud 6.0 - Cloud (GKE for example) 7.0 - Canary release ��
  66. 66. Lab # 6.0 Cloud (GKE for example)
  67. 67. Lab # 6.0 git checkout 6.0 git log git diff --stat HEAD~1 HEAD
  68. 68. Image tags Lab # Frontend API 1.0 N/A N/A 2.0 N/A 2.0 3.0 3.0 3.0 4.0 3.0 3.0 5.0 5.0 3.0 6.0 auto auto 7.0 auto auto & stable
  69. 69. Local/cloud diff - k8s/***/config.***.yml
  70. 70. Local/cloud diff - k8s/***/todoapi-service.yml
  71. 71. Local/cloud diff - k8s/***/todoapi-service.yml
  72. 72. Local/cloud diff - k8s/***/todofrontend-service.yml
  73. 73. Local/cloud diff - k8s/***/todofrontend-service.yml
  74. 74. Skaffold skaffold.yaml cloud local
  75. 75. Lab # 6.0 Review a. Architecture b. Main tasks c. Diff d. Tricks e. Questions?
  76. 76. Lab # 7.0 Canary release
  77. 77. Lab # 7.0 git checkout 7.0 git log git diff --stat HEAD~1 HEAD
  78. 78. Image tags Lab # Frontend API 1.0 N/A N/A 2.0 N/A 2.0 3.0 3.0 3.0 4.0 3.0 3.0 5.0 5.0 3.0 6.0 auto auto 7.0 auto auto & stable
  79. 79. _v2 1 stable autoimage tag: 3
  80. 80. Stable/canary diff - k8s/***/todoapi-***.yml
  81. 81. _v2 Service label label 1 selector stable autoimage tag: 3
  82. 82. Lab # 7.0 Review a. Architecture b. Main tasks c. Diff d. Tricks e. Questions?
  83. 83. Conclusion��
  84. 84. app runtime OS kernel app runtime OS kernel app runtime OS kernel Recap: containers as application packaging units traditional deployment way container virtual machine
  85. 85. _v2 Service container pod deployment service label label 3 selector
  86. 86. Agenda Know promising trends Adopt gradually Prepare mindset Goals Containers Kubernetes Cloud Labs 1.0 — 3.0 4.0 — 5.0 6.0 — 7.0
  87. 87. Kubernetes Terminology “Kubernetes 101: Pods, Nodes, Containers, and Clusters” • Author: Daniel Sanche • Date: 2018-01-02 • URL: https://medium.com/google-cloud/kubernetes-101-pods-nodes-c ontainers-and-clusters-c1509e409e16 (or http://bit.ly/post-k8s-101 for short)
  88. 88. Not told today Session affinity https://medium.com/@diegomrtnzg/redirect-your-users-to-the-same-pod -by-using-session-affinity-on-kubernetes-baebf6a1733b StatefulSet https://godleon.github.io/blog/Kubernetes/k8s-StatefulSets-Overview / Persistent Volume & Claim https://godleon.github.io/blog/Kubernetes/k8s-PersistentVolume-Over view/
  89. 89. Next step? https://www.udemy.com/course/certified-kubernetes-application-developer/
  90. 90. Questions?
  91. 91. Attribution ● review by Alina Oleynik from the Noun Project

×