Technical Manager
William Yeh 葉秉哲 
給 RD 的 Kubernetes 初體驗
… with a series of hands-on labs
2019-08-11
• 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
Containers
Kubernetes
Cloud
Agenda
Containers
Kubernetes
Cloud
Agenda Labs
1.0 — 3.0
4.0 — 5.0
6.0 — 7.0
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
GKE Setup🅐
a - Redeem Google Cloud coupon
b - Create project in GCP
c - Create GKE cluster
Redeem coupon
Please follow steps in your handout
NOW!
Create K8s-enabled Project
https://console.cloud.google.com/projectselector2/kuber
netes
Should already done
before you’re here...
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
Lab Setting��
Tag
1.0
2.0
3.0
4.0
5.0
6.0
7.0
Lab material
See the demo first!
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
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
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
Containers
1.0 - Legacy
2.0 - Docker
3.0 - Frontend/backend separation
��
Why containers?
Lab # 1.0 Legacy
Lab # 1.0
git checkout 1.0
git log
Lab # 1.0 Review
a. Architecture
b. Main tasks
c. Diff
d. Tricks
e. Questions?
app
runtime
OS kernel
app
runtime
OS kernel
Boundary of application packaging:
pros and cons
traditional deployment way
virtual machine
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
app
runtime
OS kernel
app
runtime
OS kernel
app
runtime
OS kernel
Containers as application packaging
units
traditional deployment way
container
virtual machine
Lab # 2.0 Docker
Lab # 2.0
git checkout 2.0
git log
git diff --stat HEAD~1 HEAD
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
Lab # 2.0 Review
a. Architecture
b. Main tasks
c. Diff
d. Tricks
e. Questions?
Lab # 3.0 Frontend/backend separation
Lab # 3.0
git checkout 3.0
git log
git diff --stat HEAD~1 HEAD
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
app
runtime
OS kernel
app
runtime
OS kernel
app
runtime
OS kernel
Recap:
containers as application packaging units
traditional deployment way
container
virtual machine
Lab # 3.0 Review
a. Architecture
b. Main tasks
c. Diff
d. Tricks
e. Questions?
Kubernetes
4.0 - Local Kubernetes
5.0 - Configuration
��
https://kubernetes.io/
Lab # 4.0 Local Kubernetes
Lab # 4.0
git checkout 4.0
git log
git diff --stat HEAD~1 HEAD
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
Concept gaps
from Docker to Kubernetes
Container
Service
container
service
pod
deployment 3
container
service
.
.
.
└── k8s
├── todoapi-service.yml
└── todofrontend-service.yml
Service
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
service
deployment
---
kind: Service
...
---
kind: Deployment
...
spec:
replicas: 3
template: # pod definition
spec:
containers:
- name: todoapi
image: todoapi:3.0
k8s/todoapi-service.yml
container
pod
---
kind: Service
...
---
kind: Deployment
...
spec:
replicas: 3
template: # pod definition
spec:
containers:
- name: todoapi
image: todoapi:3.0
Container
Pod
Container
Any examples?
• 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/
Deployment & Replica
3
pod
---
kind: Service
...
---
kind: Deployment
...
spec:
replicas: 3
template: # pod definition
spec:
containers:
- name: todoapi
image: todoapi:3.0
deployment
Selector & label
3
The selector field defines
how the Deployment finds
which Pods to manage.
label
selector
service
deployment
---
kind: Service
...
---
kind: Deployment
...
spec:
replicas: 3
template: # pod definition
spec:
containers:
- name: todoapi
image: todoapi:3.0
Service
label
selector
3
---
kind: Service
...
---
kind: Deployment
...
spec:
replicas: 3
template: # pod definition
spec:
containers:
- name: todoapi
image: todoapi:3.0
Recap
Service
container
pod
deployment
service
3
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
pod
---
kind: Service
...
---
kind: Deployment
...
spec:
replicas: 3
template: # pod definition
spec:
containers:
- name: todoapi
image: todoapi:3.0
deployment
service
container
Kubernetes
Terminology
Learn by doing!
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
Lab # 4.0 Review
a. Architecture
b. Main tasks
c. Diff
d. Tricks
e. Questions?
CAUTION
● There’s one big issue in this Lab 4.0
Can you see?
● What if a image changes
but version tag remains unchanged?
Lab # 5.0 Configuration
Lab # 5.0
git checkout 5.0
git log
git diff --stat HEAD~1 HEAD
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
_v2
Service
container
pod
deployment
service
Recap:
containers as application packaging units
3
Lab # 5.0 Review
a. Architecture
b. Main tasks
c. Diff
d. Tricks
e. Questions?
Cloud
6.0 - Cloud (GKE for example)
7.0 - Canary release
��
Lab # 6.0 Cloud (GKE for example)
Lab # 6.0
git checkout 6.0
git log
git diff --stat HEAD~1 HEAD
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
Local/cloud diff -
k8s/***/config.***.yml
Local/cloud diff -
k8s/***/todoapi-service.yml
Local/cloud diff -
k8s/***/todoapi-service.yml
Local/cloud diff -
k8s/***/todofrontend-service.yml
Local/cloud diff -
k8s/***/todofrontend-service.yml
Skaffold
skaffold.yaml
cloud
local
Lab # 6.0 Review
a. Architecture
b. Main tasks
c. Diff
d. Tricks
e. Questions?
Lab # 7.0 Canary release
Lab # 7.0
git checkout 7.0
git log
git diff --stat HEAD~1 HEAD
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
_v2
1
stable autoimage tag:
3
Stable/canary diff -
k8s/***/todoapi-***.yml
_v2
Service
label
label
1
selector
stable autoimage tag:
3
Lab # 7.0 Review
a. Architecture
b. Main tasks
c. Diff
d. Tricks
e. Questions?
Conclusion��
app
runtime
OS kernel
app
runtime
OS kernel
app
runtime
OS kernel
Recap:
containers as application packaging units
traditional deployment way
container
virtual machine
_v2
Service
container
pod
deployment
service
label
label
3
selector
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
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)
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/
Next step?
https://www.udemy.com/course/certified-kubernetes-application-developer/
Questions?
Attribution
● review by Alina Oleynik from the Noun Project

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