How to debug
Microservices on
Kubernetes as a pros
KAI CHU CHUNG
GDGCloud co-organizer
GDE(Cloud)
“How to debug Microservices
on Kubernetes as a pros”
1. Debug
2. Microservice
3. Kubernetes
Agenda
Debug
1. Local
2. Container
3. Cloud Debugger
Debug
Local (Golang)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
fmt.Fprintf(w, "hello devfest 2020 tw")
})
port := os.Getenv("PORT")
if port == "" {
port = "8080"
log.Printf("Defaulting to port %s", port)
}
log.Printf("Listening on port %s", port)
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%s", port), nil))
}
Local (Python)
from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():
return 'hello devfest 2020 tw'
if __name__ == '__main__':
app.debug = True
app.run()
Summary: Local
Containers allow you
to package your
application and its
dependencies together
into one succinct
manifest
What are Containers and their benefits | Google Cloud - https://cloud.google.com/containers
1. Dockerfile
2. buildpacks
Container
Dockerfile (Golang)
FROM golang:1.15 AS builder
WORKDIR /workspace
# Install dependencies in go.mod and go.sum
COPY go.mod go.sum ./
RUN go mod download
# Copy rest of the application source code
COPY . ./
# Compile the application to /app.
RUN go build -o /exe -v ./
FROM gcr.io/distroless/base:latest
COPY --from=builder /exe .
ENTRYPOINT ["/exe"]
Dockerfile (Golang debug)
FROM golang:1.15
# Download the dlv (delve) debugger for go
RUN go get -u -v github.com/go-delve/delve/cmd/dlv
WORKDIR /workspace
# Install dependencies in go.mod and go.sum
COPY go.mod go.sum ./
RUN go mod download
# Copy rest of the application source code
COPY . ./
RUN go build -o /exe -v ./
ENTRYPOINT ["dlv", "exec", "/app", "--continue", "--accept-multiclient", "--api-version=2",
"--headless", "--listen=:3000", "--log"]
container with known vulnerabilities
Source: The state of open source security report 2019 by snyt
44%
Google Cloud Next ’20 OnAir - https://cloud.withgoogle.com/next/sf/onair?session=SVR227#application-modernization
1. CNCF sandbox projects
2. suggest builders
a. Google
b. Heroku
c. Paketo Buildpacks
Buildpacks
Buildpacks Go Cloud Native | Heroku - https://blog.heroku.com/buildpacks-go-cloud-native
1. Open source.
2. Creates secure
container images.
3. Designed for
running on Cloud
Run, GKE, Anthos.
Buildpacks
GoogleCloudPlatform/buildpacks - https://github.com/GoogleCloudPlatform/buildpacks
● Google Cloud maintains a set of open source
buildpacks for building containers to run on
GKE, Anthos, & Cloud Run
● Cloud Build native support for buildpacks
● Cloud Run direct source deployments w/
buildpacks
● Cloud Shell has pack pre-installed. App Engine
builds via buildpacks
● Cloud Functions builds via buildpacks
● Cloud Code deploy to Cloud Run with Buildpacks
● Skaffold native support for buildpacks
Buildpacks on Google Cloud
pack build aa --builder gcr.io/buildpacks/builder:v1
dive index.docker.io/library/aa:latest
wagoodman/dive: A tool for exploring each layer in a docker image - https://github.com/wagoodman/dive
Summary: Container
debugger
debugger
one
container
one
container
Microservice
Microservices refers to an
architectural style for
developing applications.
Microservices allow a large
application to be decomposed
into independent constituent
parts, with each part having
its own realm of
responsibility
.
├── build
├── cmd
├── deployments
├── internal
│ ├── app
│ │ ├── authnsvc
│ │ ├── authzsvc
│ │ ├── docs
│ │ ├── emailsvc
│ │ ├── invitesvc
│ │ ├── mappingsvc
│ │ ├── oauthagentsvc
│ │ ├── organizationsvc
│ │ ├── person_attribute
│ │ ├── report_statistics
│ │ ├── reportsvc
│ │ ├── storesvc
│ │ ├── streamsvc
│ │ └── ws
│ └── pkg
├── pb
├── scripts
├── test
├── cloudbuild-build.yaml
├── cloudbuild-dev-deploy.yaml
├── cloudbuild-dev-meta.yaml
├── cloudbuild-helm.yaml
├── cloudbuild-release-helm.yaml
├── cloudbuild-release-meta.yaml
├── cloudbuild-test.yaml
├── cloudbuild.plantuml
├── makefile
└── skaffold.yaml
Service Language Description
frontend Go
Exposes an HTTP server to serve the website. Does
not require signup/login and generates session
IDs for all users automatically.
cartservice C#
Stores the items in the user's shopping cart in
Redis and retrieves it.
productcatalogservice Go
Provides the list of products from a JSON file and
ability to search products and get individual
products.
currencyservice Node.js
Converts one money amount to another currency.
Uses real values fetched from European Central
Bank. It's the highest QPS service.
paymentservice Node.js
Charges the given credit card info (mock) with
the given amount and returns a transaction ID.
shippingservice Go
Gives shipping cost estimates based on the
shopping cart. Ships items to the given address
(mock)
emailservice Python Sends users an order confirmation email (mock).
checkoutservice Go
Retrieves user cart, prepares order and
orchestrates the payment, shipping and the email
notification.
recommendationservice Python
Recommends other products based on what's given
in the cart.
adservice Java Provides text ads based on given context words.
loadgenerator Python/Locust
Continuously sends requests imitating realistic
user shopping flows to the frontend.
GoogleCloudPlatform/microservices-demo - https://github.com/GoogleCloudPlatform/microservices-demo
Kubernetes
Kubernetes is a portable,
extensible, open-source
platform for managing
containerized workloads and
services, that facilitates
both declarative configuration
and automation. It has a
large, rapidly growing
ecosystem. Kubernetes
services, support, and tools
are widely available.
1
2
3
4
5
6
Change code
Run docker build
Run docker push
Patch yaml
Run kubectl apply
Verify
Kubernetes Development workflow
Skaffold handles the workflow
for building, pushing and
deploying your application,
allowing you to focus on what
matters most: writing code
1. Go (runtime ID: go)
2. NodeJS (runtime ID: nodejs)
3. Java and JVM languages
(runtime ID: jvm)
4. Python (runtime ID: python)
5. .NET Core (runtime ID:
netcore)
Skaffold debug (beta)
Cloud Code comes with tools
to help you write, run, and
debug cloud-native
applications quickly and
easily.
Cloud Code | Google Cloud - https://cloud.google.com/code
https://www.facebook.com/groups/GCPUG.TW

Dev fest 2020 taiwan how to debug microservices on kubernetes as a pros (https://youtu.be/eseo0hcRaQI?t=11008)

  • 1.
    How to debug Microserviceson Kubernetes as a pros KAI CHU CHUNG GDGCloud co-organizer GDE(Cloud)
  • 2.
    “How to debugMicroservices on Kubernetes as a pros”
  • 5.
    1. Debug 2. Microservice 3.Kubernetes Agenda
  • 6.
  • 7.
    1. Local 2. Container 3.Cloud Debugger Debug
  • 8.
    Local (Golang) func main(){ http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) { fmt.Fprintf(w, "hello devfest 2020 tw") }) port := os.Getenv("PORT") if port == "" { port = "8080" log.Printf("Defaulting to port %s", port) } log.Printf("Listening on port %s", port) log.Fatal(http.ListenAndServe(fmt.Sprintf(":%s", port), nil)) }
  • 9.
    Local (Python) from flaskimport Flask app = Flask(__name__) @app.route('/') def index(): return 'hello devfest 2020 tw' if __name__ == '__main__': app.debug = True app.run()
  • 10.
  • 11.
    Containers allow you topackage your application and its dependencies together into one succinct manifest What are Containers and their benefits | Google Cloud - https://cloud.google.com/containers
  • 12.
  • 13.
    Dockerfile (Golang) FROM golang:1.15AS builder WORKDIR /workspace # Install dependencies in go.mod and go.sum COPY go.mod go.sum ./ RUN go mod download # Copy rest of the application source code COPY . ./ # Compile the application to /app. RUN go build -o /exe -v ./ FROM gcr.io/distroless/base:latest COPY --from=builder /exe . ENTRYPOINT ["/exe"]
  • 14.
    Dockerfile (Golang debug) FROMgolang:1.15 # Download the dlv (delve) debugger for go RUN go get -u -v github.com/go-delve/delve/cmd/dlv WORKDIR /workspace # Install dependencies in go.mod and go.sum COPY go.mod go.sum ./ RUN go mod download # Copy rest of the application source code COPY . ./ RUN go build -o /exe -v ./ ENTRYPOINT ["dlv", "exec", "/app", "--continue", "--accept-multiclient", "--api-version=2", "--headless", "--listen=:3000", "--log"]
  • 15.
    container with knownvulnerabilities Source: The state of open source security report 2019 by snyt 44% Google Cloud Next ’20 OnAir - https://cloud.withgoogle.com/next/sf/onair?session=SVR227#application-modernization
  • 16.
    1. CNCF sandboxprojects 2. suggest builders a. Google b. Heroku c. Paketo Buildpacks Buildpacks
  • 17.
    Buildpacks Go CloudNative | Heroku - https://blog.heroku.com/buildpacks-go-cloud-native
  • 18.
    1. Open source. 2.Creates secure container images. 3. Designed for running on Cloud Run, GKE, Anthos. Buildpacks GoogleCloudPlatform/buildpacks - https://github.com/GoogleCloudPlatform/buildpacks
  • 19.
    ● Google Cloudmaintains a set of open source buildpacks for building containers to run on GKE, Anthos, & Cloud Run ● Cloud Build native support for buildpacks ● Cloud Run direct source deployments w/ buildpacks ● Cloud Shell has pack pre-installed. App Engine builds via buildpacks ● Cloud Functions builds via buildpacks ● Cloud Code deploy to Cloud Run with Buildpacks ● Skaffold native support for buildpacks Buildpacks on Google Cloud
  • 20.
    pack build aa--builder gcr.io/buildpacks/builder:v1
  • 21.
    dive index.docker.io/library/aa:latest wagoodman/dive: Atool for exploring each layer in a docker image - https://github.com/wagoodman/dive
  • 22.
  • 23.
  • 24.
    Microservices refers toan architectural style for developing applications. Microservices allow a large application to be decomposed into independent constituent parts, with each part having its own realm of responsibility
  • 25.
    . ├── build ├── cmd ├──deployments ├── internal │ ├── app │ │ ├── authnsvc │ │ ├── authzsvc │ │ ├── docs │ │ ├── emailsvc │ │ ├── invitesvc │ │ ├── mappingsvc │ │ ├── oauthagentsvc │ │ ├── organizationsvc │ │ ├── person_attribute │ │ ├── report_statistics │ │ ├── reportsvc │ │ ├── storesvc │ │ ├── streamsvc │ │ └── ws │ └── pkg ├── pb ├── scripts ├── test ├── cloudbuild-build.yaml ├── cloudbuild-dev-deploy.yaml ├── cloudbuild-dev-meta.yaml ├── cloudbuild-helm.yaml ├── cloudbuild-release-helm.yaml ├── cloudbuild-release-meta.yaml ├── cloudbuild-test.yaml ├── cloudbuild.plantuml ├── makefile └── skaffold.yaml
  • 26.
    Service Language Description frontendGo Exposes an HTTP server to serve the website. Does not require signup/login and generates session IDs for all users automatically. cartservice C# Stores the items in the user's shopping cart in Redis and retrieves it. productcatalogservice Go Provides the list of products from a JSON file and ability to search products and get individual products. currencyservice Node.js Converts one money amount to another currency. Uses real values fetched from European Central Bank. It's the highest QPS service. paymentservice Node.js Charges the given credit card info (mock) with the given amount and returns a transaction ID. shippingservice Go Gives shipping cost estimates based on the shopping cart. Ships items to the given address (mock) emailservice Python Sends users an order confirmation email (mock). checkoutservice Go Retrieves user cart, prepares order and orchestrates the payment, shipping and the email notification. recommendationservice Python Recommends other products based on what's given in the cart. adservice Java Provides text ads based on given context words. loadgenerator Python/Locust Continuously sends requests imitating realistic user shopping flows to the frontend. GoogleCloudPlatform/microservices-demo - https://github.com/GoogleCloudPlatform/microservices-demo
  • 27.
  • 28.
    Kubernetes is aportable, extensible, open-source platform for managing containerized workloads and services, that facilitates both declarative configuration and automation. It has a large, rapidly growing ecosystem. Kubernetes services, support, and tools are widely available.
  • 29.
    1 2 3 4 5 6 Change code Run dockerbuild Run docker push Patch yaml Run kubectl apply Verify Kubernetes Development workflow
  • 30.
    Skaffold handles theworkflow for building, pushing and deploying your application, allowing you to focus on what matters most: writing code
  • 32.
    1. Go (runtimeID: go) 2. NodeJS (runtime ID: nodejs) 3. Java and JVM languages (runtime ID: jvm) 4. Python (runtime ID: python) 5. .NET Core (runtime ID: netcore) Skaffold debug (beta)
  • 34.
    Cloud Code comeswith tools to help you write, run, and debug cloud-native applications quickly and easily.
  • 35.
    Cloud Code |Google Cloud - https://cloud.google.com/code
  • 42.