Slide 1

Slide 1 text

© - BASE, Inc. Container-based Application Design Real Practices . . #dockertokyo - @hgsgtk

Slide 2

Slide 2 text

© - BASE, Inc. Talk Summary Keep each components is Decoupled Keep Balance with development efficiency Use Cloud-based Design Principles

Slide 3

Slide 3 text

© - BASE, Inc. About me Kazuki Higashiguchi Twitter / GitHub : @hgsgtk Server-side Engineer BASE BANK, Inc.

Slide 4

Slide 4 text

© - BASE, Inc. Agenda .Configuration .Logging .Building Application .Monitoring

Slide 5

Slide 5 text

Configuration

Slide 6

Slide 6 text

© - BASE, Inc. Features of Configuration • “Runtime” Data (Necessary at startup) • Different for each environment • A lot of values

Slide 7

Slide 7 text

© - BASE, Inc. Requests for configuration • Manage hierarchically • Make configurations easy to understand • Externalize configuration • Get rid of configurations from Application • Minimal accessibility • Configurations includes credentials

Slide 8

Slide 8 text

© - BASE, Inc. Related Principles • “ . CONFIGURATION, CREDENTIALS, AND CODE” in “Beyond the Twelve-Factor App” • “IMAGE IMMUTABILITY PRINCIPLE(IIP)” in “Principles of container-based application design (redhat)”

Slide 9

Slide 9 text

© - BASE, Inc. . CONFIGURATION, CREDENTIALS, AND CODE (WIP) • Get rid of configurations from Code • Not include in Version Control System • “Treat Your Apps Like Open Source” • Environment variables are considered the best practice for externalized configuration, • Externalized configurations

Slide 10

Slide 10 text

© - BASE, Inc. Extra: Beyond the Twelve-Factor App • Best practices of cloud-native application • published by Pivotal • https://content.pivotal.io/blog/ beyond-the-twelve-factor-app • Original is “The Twelve-Factor App” • https:// factor.net/ • Original + New = factors

Slide 11

Slide 11 text

© - BASE, Inc. Extra: Principles of container-based application design (redhat) • Design Principles of container- based application • published by red-hot • https://www.redhat.com/en/ resources/cloud-native- container-design-whitepaper

Slide 12

Slide 12 text

© - BASE, Inc. Configuration: Practical example • AWS ECS(Fargate) • Configurations are stored in Parameter Store • Encryption using Key Management Store • See also: • https://devblog.thebase.in/ entry/ / / /

Slide 13

Slide 13 text

© - BASE, Inc. Configuration: Real Issues • Depends on Features provided by Cloud vendor • If well-integrated features, become “Simple” • If Not, may become “Complicated”

Slide 14

Slide 14 text

© - BASE, Inc. For example: Fargate & Parameter Store • A example to use Parameter Store as externalized configuration store • Before Platform Version . • Each container access Parameter Store via API • Write entrypoint.sh by myself

Slide 15

Slide 15 text

© - BASE, Inc. entrypoint.sh #!/usr/bin/env bash set -e # request multiple times export DB_HOST=$(aws ssm get-parameters --name /prd/ database/host --query "Parameters[0].Value" --region ap- northeast-1 --output text) export DB_PORT=$(aws ssm get-parameters --name /prd/ database/port --query "Parameters[0].Value" --region ap- northeast-1 --output text) exec "$@"

Slide 16

Slide 16 text

© - BASE, Inc. For example: Fargate & Parameter Store • After Released . • “AWS Fargate Platform Version . Adds Secrets Support” • Just write task definition (and set IAM role) • Become well-integrated features. • It makes our application “Simpler”

Slide 17

Slide 17 text

Logging

Slide 18

Slide 18 text

© - BASE, Inc. Requests for Logging • Realtime • Know “What is happening now” • Availability • “No” Missing Log • Searching • Make identifying the cause of problem “Easy”

Slide 19

Slide 19 text

© - BASE, Inc. Related Principles • “ . LOGS” in “Beyond the Twelve-Factor App”

Slide 20

Slide 20 text

© - BASE, Inc. “ . LOGS” • Treat Log as Event Stream • Not depends on File System • Log on STDOUT/STDERR • Use tools (ex. ElasticSearch, Logstash, Kibana) to satisfied the requirements of aggregation, processing, storage of logs

Slide 21

Slide 21 text

© - BASE, Inc. LOGGING: Practical Examples • Application writes logs to STDOUT/STDERR • Fargate -> CloudWatchLogs(CWL) -> S -> ElasticSearch & Kibana • See also https://qiita.com/tomy rider/items/ aa dd

Slide 22

Slide 22 text

Build Application

Slide 23

Slide 23 text

© - BASE, Inc. Requests for Build Application • Dependency Management • Manage Application Dependency • Work in Difference environments • Work in Local, QA, Stating, Production

Slide 24

Slide 24 text

© - BASE, Inc. Application Components • Runtime Engine • Code • Dependencies • Configuration

Slide 25

Slide 25 text

© - BASE, Inc. Container Application • Container includes • Runtime Engine • Code • Dependencies • Configuration is injected at startup

Slide 26

Slide 26 text

© - BASE, Inc. For environments, Same Container

Slide 27

Slide 27 text

© - BASE, Inc. Related Principles • “ . DEPENDENCY MANAGEMENT” in “Beyond the Twelve-Factor App” • “ . DESIGN, BUILD, RELEASE, RUN” in “Beyond the Twelve-Factor App”

Slide 28

Slide 28 text

© - BASE, Inc. Build Application: Practical example • Use case • API developed by Go • One Dockerfile for deploy • Build image provide to environments

Slide 29

Slide 29 text

© - BASE, Inc. Build Application: Real Issues • Best practices: same container provides ALL environments • However, in Local environments, Development efficiency is also important

Slide 30

Slide 30 text

© - BASE, Inc. Build Application: Real Issues • One Dockerfile for deploy • Another Dockerfile for developer • Live reloading • See also • https://go- talks.appspot.com/ github.com/hgsgtk/ gocon -lt/realize.slide#

Slide 31

Slide 31 text

© - BASE, Inc. Find the suitable balance for you • “Docker for local” • -> weakens the merit • -> strengthen developers • Necessity to find suitable balance

Slide 32

Slide 32 text

Monitoring

Slide 33

Slide 33 text

© - BASE, Inc. Requests for Monitoring • Check Health • Monitor application is healthy • Keep Watching Metrics • Keep watching Metrics

Slide 34

Slide 34 text

© - BASE, Inc. Related Principles • “HIGH OBSERVABILITY PRINCIPLE (HOP)” in “Principles of container-based application design (redhat)”

Slide 35

Slide 35 text

© - BASE, Inc. HIGH OBSERVABILITY PRINCIPLE (HOP) • Treat Container like “Black box” • Provide API for various status check • Activity status • Preparation status • Log important events on STDOUT/STDERR

Slide 36

Slide 36 text

© - BASE, Inc. Health endpoint pattern • One of application monitoring patterns • Provide HTTP endpoints in the application • convey the health of the application • See also: “Practical Monitoring—Effective Strategies for the Real World” • http://shop.oreilly.com/product/ .do

Slide 37

Slide 37 text

© - BASE, Inc. Mackerel Container Agent • Monitor “Inside Container” • CPU, Memory, Network etc • Run as a task / pod sidecar • See also: https://mackerel.io/ja/docs/entry/ howto/container-agent

Slide 38

Slide 38 text

© - BASE, Inc. Monitoring: Practical example /.health_check endpoint return “OK” See also: https://devblog.thebase.in/entry/ / / / -> % curl -i http://localhost/.health_check HTTP/1.1 200 OK Content-Type: application/json; charset=utf-8 Date: Mon, 04 Mar 2019 13:24:23 GMT Content-Length: 15 {"status":200}

Slide 39

Slide 39 text

© - BASE, Inc. Monitoring: Practical example /.health_check endpoint also return “NG” See also: https://devblog.thebase.in/entry/ / / / -> % curl -i http://localhost/.health_check HTTP/1.1 503 Service Unavailable Content-Type: application/json; charset=utf-8 Date: Mon, 04 Mar 2019 13:35:38 GMT Content-Length: 106 {"status":503,"message":"failed to get connection database","string":"sql: connection is already closed"}

Slide 40

Slide 40 text

© - BASE, Inc. Talk Summary Keep each components is Decoupled Keep Balance with development efficiency Use Cloud-based Design Principles

Slide 41

Slide 41 text

© - BASE, Inc. Extra: Related Presentations • “Container-based Application Design Reference and Practice” at Docker Tokyo Meetup • https://speakerdeck.com/hgsgtk/container-based-application-design- reference-and-practice-number-dockertokyo • “Docker Go development environment starting with realize” at Go Conference Autumn • https://go-talks.appspot.com/github.com/hgsgtk/gocon -lt/ realize.slide#

Slide 42

Slide 42 text

© - BASE, Inc. Extra: Related Blogs • “ECS(Fargate)でコンテナアプリケーションを動かすための設定情報の扱 い⽅” • https://devblog.thebase.in/entry/ / / / • “アプリケーション監視のパターン「Health エンドポイントパターン」 を実践する | 書籍『⼊⾨ 監視 ―モダンなモニタリングのためのデザイン パターン』を読んで” • https://devblog.thebase.in/entry/ / / /

Slide 43

Slide 43 text

© - BASE, Inc. Extra: Related Books • 『⼊⾨ 監視 モダンなモニタリングのためのデザインパターン』 https://www.oreilly.co.jp/books/ /

Slide 44

Slide 44 text

© - BASE, Inc. Extra: Related Documents • Beyond the Twelve-Factor App • https://content.pivotal.io/blog/beyond-the-twelve-factor-app • Principles of container-based application design (redhat) • https://www.redhat.com/en/resources/cloud-native-container-design- whitepaper (English Edition) • https://www.redhat.com/ja/resources/cloud-native-container-design- whitepaper (Japanese Edition) • AWS Cloud Design Patterns • http://en.clouddesignpattern.org/index.php/Main_Page

Slide 45

Slide 45 text

© - BASE, Inc. Extra: Related Documents • “AWS Fargate Platform Version . Adds Secrets Support” • https://aws.amazon.com/about-aws/whats-new/ / /aws- fargate-platform-version- - -adds-secrets-support/?nc =h_ls