Top Banner
Become a cloud-native developer [email protected] http://meetup.com/docker-hanoi
28

ContainerDayVietnam2016: Become a Cloud-native Developer

Apr 14, 2017

Download

Technology

Docker-Hanoi
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: ContainerDayVietnam2016: Become a Cloud-native Developer

Become a cloud-native developer

[email protected]

http://meetup.com/docker-hanoi

Page 2: ContainerDayVietnam2016: Become a Cloud-native Developer

Tu Nguyen

Master student @ University of Basel,

Switzerland

Docker Hanoi organizer

Apache Software Foundation committer

Kubernetes committer

Solution Architect @ FPT-Software

Interests:

Open-source cloud computing lover

Docker, Microservices, DevOps

Kubernetes crazy fan

Golang, OCaml, Chapel

Page 3: ContainerDayVietnam2016: Become a Cloud-native Developer
Page 4: ContainerDayVietnam2016: Become a Cloud-native Developer

Design Patterns

1980s-1990s: Object-oriented programming revolutionized software

development.

Why design patterns ?

Encode best practices.

Simplify development.

Make the application more reliable.

Make it easier for less experienced programmers to produce well-engineered code.

Page 5: ContainerDayVietnam2016: Become a Cloud-native Developer

Which design patterns are suitable for today ?

Trend

Popularity of microservice architectures.

Popularity of {public} clouds.

Built from containerized software components.

Distributed applications running on distributed systems.

Emergence

A new design pattern which abstracts away the low-level details of code for developing

containerized applications.

Container Design Patterns

Container and container image

The abstractions needed for the development of distributed applications.

Container ⟺ Object.

Page 6: ContainerDayVietnam2016: Become a Cloud-native Developer

Three types of container design patterns

Single-container patterns.

for container management.

Single-node patterns.

For cooperating containers.

Multi-node patterns.

For distributed algorithm.

Page 7: ContainerDayVietnam2016: Become a Cloud-native Developer

Single-container patterns

Container boundary

Page 8: ContainerDayVietnam2016: Become a Cloud-native Developer

Container interface

Container provides a natural boundary for defining an interface.

Much like object boundary.

Traditional container interface is extremely limited.

run()

pause()

stop()

Page 9: ContainerDayVietnam2016: Become a Cloud-native Developer

Container interface

The interface is generally becoming richer.

Expose information

Application-specific monitoring metrics

Logs, events

Healthcheck

Configuration

Standard lifecycle

Create, start, stop, kill, delete

Graceful termination

SIGTERM, SIGKILL

Provide priority

High-priority containers guaranteed to run even when the cluster is oversubscribed.

Low-priority containers have to wait until resources become available.

Replicate yourself - scale up

Etc.

https://github.com/opencontainers/runtime-spec

Page 10: ContainerDayVietnam2016: Become a Cloud-native Developer

Single-node patterns

Consist of symbiotic containers that are co-scheduled as an atomic unit onto a single machine

Page 11: ContainerDayVietnam2016: Become a Cloud-native Developer

Kubernetes Pod

What is K8S pod ?

A pod is a group of one or more containers which are relatively tightly coupled, co-located, co-

scheduled, and run in a shared contexts.

Shared contexts ?

Share IP address

Share port space

Find each other via localhost

Have access to shared volumes

http://kubernetes.io/docs/user-guide/pods/

Page 12: ContainerDayVietnam2016: Become a Cloud-native Developer

1. Sidecar

2. Ambassador

3. Adapter

Page 13: ContainerDayVietnam2016: Become a Cloud-native Developer

Sidecar

Sidecars extend and enhance the main container.

Page 14: ContainerDayVietnam2016: Become a Cloud-native Developer

Sidecar

Benefits

Container is the unit of resource accounting and allocation:

Main container can be configured to provide low-latency responses to queries.

Sidecar container is configured to trigger when the server is not busy.

Container is the unit of packaging:

Separating containers make it easy to divide responsibility for different development teams.

Container is the unit of reuse:

Sidecar can be paired with numerous different main containers.

Container provides failure boundary:

Main container can continue serving even if the sidecar has failed.

Container is the unit of deployment:

Allows each piece of functionality to be upgraded and rollbacked independently.

Note: version compatibility.

Page 15: ContainerDayVietnam2016: Become a Cloud-native Developer

Ambassador

Ambassador proxy communication to and from a main container.

It presents an application with a simplified view of the outside world.

Page 16: ContainerDayVietnam2016: Become a Cloud-native Developer

Ambassador

Benefits

Developers only have to think and program in term of their application connection to a localhost

single server.

Developers can test their application standalone by running a real instance on their local

machine.

Developers can reuse the ambassador with other applications that might even be coded in

different programming languages.

Page 17: ContainerDayVietnam2016: Become a Cloud-native Developer

Adapter

In contrast to Ambassador.

Adapters present the outside world with a simplified, homogenized view of an application.

Standardizing output and interfaces.

Ensure all containers in the system have the same adapters interface. (ex: monitoring interface)

Page 18: ContainerDayVietnam2016: Become a Cloud-native Developer

Multi-node patterns

Modular containers make it easier to build coordinated multi-node distributed applications.

Page 19: ContainerDayVietnam2016: Become a Cloud-native Developer

1. Leader election

2. Work queue

3. Scatter/gather

Page 20: ContainerDayVietnam2016: Become a Cloud-native Developer

Leader election

One of the most common problems in distributed systems.

Replication

Commonly used to share load among multiple instances of a component.

Replication in distributed application

Need to distinguish one replica from a set as the “leader”.

The other replicas are available to quickly take the place of leader if it fails.

Page 21: ContainerDayVietnam2016: Become a Cloud-native Developer

Leader election

Typical leader election

A set of candidates is identified.

These candidates all race to declare themselves the leader.

One of the candidates win and becomes the leader.

The leader continually “heartbeats” to renew their position.

Other candidates periodically make new attempts to become the leader.

Raft consensus algorithm

https://raft.github.io/

Page 22: ContainerDayVietnam2016: Become a Cloud-native Developer

Leader election

How to apply `leader election` to my app?

Import leader election libraries

https://raft.github.io/

They are generally complicated to understand and use correctly.

They are limited in particular programming languages.

Will container design pattern provide a better solution ???

Page 23: ContainerDayVietnam2016: Become a Cloud-native Developer

Leader election with sidecar pattern

A set of leader-election containers, each one co-scheduled with an instance of

the application that requires leader election

Page 24: ContainerDayVietnam2016: Become a Cloud-native Developer

Leader election sidecar

Container image

gcr.io/google_containers/leader-elector:0.4

Opening a HTTP endpoint at port 4040

curl http://localhost:4040

{"name":"(name-of-pod-leader-here)"}

Benefits

Can be built once and reused by application

developers

Regardless of programming languages.

Page 25: ContainerDayVietnam2016: Become a Cloud-native Developer

Work queue

Container interfaces run() and mount() make it fairly straightforward to

implement a generic work queue framework.

Developers only have to build a container that can take input data on the

filesystem, process and give output.

Queue

Page 26: ContainerDayVietnam2016: Become a Cloud-native Developer

Scatter/Gather

Commonly used in parallel computing

The root “node” fans the request out to a number of “leaf” nodes to perform computations in

parallel

Each “leaf” returns partial data, and the “root” gathers data into a single response.

Page 27: ContainerDayVietnam2016: Become a Cloud-native Developer

Scatter/Gather containers

Page 28: ContainerDayVietnam2016: Become a Cloud-native Developer

Questions ?