1. Trang chủ
  2. » Công Nghệ Thông Tin

Công nghệ ảo hóa ứng dụng với Docker

85 305 2

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 85
Dung lượng 3,66 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Docker Engine● Docker bao gồm: ○ Docker Engine: bộ open source mô phỏng hoá container kết hợp với tools để build và run container.. Docker Image15 ● Được xây dựng lên từ các layer ● Do

Trang 1

Giới thiệu Đóc cờ CI/CD

LongTV

Trang 5

Giới thiệu Docker

● Open source project

● Giúp đóng gói ứng dụng vào

container để shipping và run

Trang 6

Lịch sử

● Solomon Hykes phát triển Docker tại

Pháp, ở cty dotCloud (cty về PaaS)

● Release Open source 03/2013

● 13/03/2014 nghỉ LXC và chơi

libcontainer

● 05/2016 đã có nhiều cty là main

contributor cho Docker: Cisco, Google,

Huawei, IBM, Microsoft, Red Hat,

Trang 7

Project on Github

https://github.com/docker/docker

7

Trang 8

Độ phát triển

Trang 9

Giao lưu Docker tại Việt Nam

Trang 13

Docker Engine

● Docker bao gồm:

○ Docker Engine: bộ open source mô phỏng

hoá container kết hợp với tools để build và run container.

○ Docker Hub: SaaS để quản lý application

stacks.

13

Trang 14

Docker Engine

1 Docker daemon

2 REST API

3 CLI

Trang 15

Docker Image

15

● Được xây dựng lên từ các

layer

● Docker sử dụng union file

systems để tạo nên docker

image => giúp việc build

image trở nên nhanh hơn.

● Mỗi instruction sẽ tạo ra 1

layer của image.

● Các image được share trên

Docker Hub

Trang 16

Container?

Trang 17

Container là gì

A container image is a lightweight,

stand-alone, executable package of a

piece of software that includes everything needed to run it: code, runtime, system

tools, system libraries, settings

17

Trang 18

Docker container

● Docker container được tạo ra từ images

● Cách tạo 1 container về cơ bản là dùng

command docker run:

$ sudo docker run -i -t ubuntu /bin/bash

○ CLI tương tác vs Docker daemon qua REST API để tạo container từ image (sẽ pull image về nếu ko có trong local)

○ Docker daemon sẽ thiết lập network, mount volume ,

○ Mỗi container được isolate trong các name spaces riêng biệt.

Trang 20

Ví dụ Dockerfile

FROM ubuntu:latest

MAINTAINER Long Ta "longtv@runsystem.net"

RUN apt-get update

RUN apt-get install -y python python-pip wget

Trang 22

Docker Hub

● Cloud-based registry service để quản lý

image, build image và có link đến Docker Cloud để deploy container

Trang 23

Docker Cloud

● Là hosted registry service, hỗ trợ quản lý

infrastructure và quản lý application

lifecycle features để automate deploying

● Features:

○ Manage Builds and Images

○ Manage Infrastructure (Standard Mode)

○ Manage Nodes and Apps (Standard Mode)

○ Manage Swarms ( Beta Swarm Mode )

23

Trang 31

Docker machine

● Tool giúp install docker engine trên virtual host

và quản lý các virtual host thông qua command

Trang 32

Docker machine

Trang 33

Docker machine

33

Trang 34

Tạo virtual host với

Virtualbox

● Command

docker-machine create driver virtualbox node-01

● Các option cho Virtualbox:

● Chọi vào host

eval $(docker-machine env node-01)

Trang 35

Tạo virtual host của Conoha

1 Export các thông tin để xác thực

export OS_USERNAME=<api_username>

export OS_TENANT_ID=<tenant_id>

export OS_PASSWORD=<api_password>

export OS_AUTH_URL=https://identity.tyo1.conoha.io/v2.0 export OS_REGION_NAME=tyo1

2 Tạo máy ảo

docker-machine create \

-d openstack \

openstack-flavor-name g-1gb \

openstack-image-name vmi-ubuntu-16.04-amd64-unified \ openstack-sec-groups "default,gncs-ipv4-all" \

openstack-sec-groups "default,gncs-ipv4-all" \

co-01

35

Trang 39

Docker swarm

39

Trang 40

Docker swarm scheduling

Swarm mode deploy sử dụng:

$docker service create name my_web replicas 3 nginx

● Swarm deploy service bằng cách scheduling các tasks

Task: là slot để đặt container

○ Nếu task tạch thì xóa task đi và tạo ra task mới ( reschedule )

○ Khi một service deploy mà ko có node vào available thì service sẽ rơi

vào trạng thái pending cho đến khi task được thực thi hết (có thể

pending mãi mãi)

Scheduling strategies: flag strategy

spread(default): dựa trên số lượng containter ( kể cả đã stop)

Binpack: hấp diêm thằng node còn available

Random: táng bừa

● Deloy mode:

replicated: tạo số lượng bản sao

global: deploy trên tất cả các node (ví dụ log, )

Trang 41

Binpack vs Spread

41

Trang 42

Docker swarm scheduling

Deploy service in Swarm mode

Services, tasks, and containers Tasks and scheduling

Trang 43

Raft Consensus Algorithm

● Thuật toán đồng thuận để quản lý replicated log, swarm dùng để quản lý global cluster state.

● Mỗi node sẽ có 3 state: Follower, Candidate,

Leader

● Hỗ trợ:

Leader Election Replicated Log

43

Trang 44

Node manager failover

Với N node sẽ hanlde failover được cho (N-1)/2 node tạch

Trang 45

Swarm mode security

TLS : can’t disable

45

Trang 47

Docker Cloud

● Là hosted registry service, hỗ trợ quản lý

infrastructure và quản lý application

lifecycle features để automate deploying

● Features:

○ Manage Builds and Images

○ Manage Infrastructure (Standard Mode)

○ Manage Nodes and Apps (Standard Mode)

○ Manage Swarms ( Beta Swarm Mode )

47

Trang 52

Docker Isolation

Trang 53

● Là feature của Linux Kernel cho phép

limit, theo dõi, quản lý sử dụng resources

của “collection of processes”

● Cgroups giúp quản lý các resources: cpu,

memory, devices, ns … ( còn gọi là sub

system)

53

Trang 54

Docker sử dụng cgroups để quản lý resoures cho các

container: CPU, Memory, IO

docker run -it cpus=".5" memory="300m" ubuntu /bin/bash

50% CPU 300Mb memory and

600Mb Swap

Trang 55

● Là feature của Linux kernel, ra đời để hỗ trợ

cho công nghệ container ( cung cấp isolated secure environment)

● Từ Linux kernel 2.6.24 Linux hỗ trợ 6 loại

namespace:

55

Trang 60

Docker đại chiến Hypervisor

Trang 61

Hypervisor là gì

A hypervisor or virtual machine monitor

(VMM) is computer software, firmware, or

hardware, that creates and runs virtual

machines A computer on which a hypervisor runs one or more virtual machines is called a host machine, and each virtual machine is

called a guest machine

https://en.wikipedia.org/wiki/Hypervisor

Trang 62

1 Native(bare metal): Chạy trực tiếp trên hardware của host

machine Xen, Oracle VM Server for SPARC, Oracle VM

Server for x86, Microsoft Hyper-V and VMware ESX/ESXi.

2 Hosted: Chạy phía trên OS của host machine VMware

Workstation, VMware Player, VirtualBox, Parallels Desktop for Mac and QEMU

Trang 63

Docker có phải VM ko?

63

In computing, a virtual machine (VM) is an emulation of a computer system Virtual machines are based on computer architectures and provide

functionality of a physical computer Their implementations may involve

specialized hardware, software, or a combination.

https://en.wikipedia.org/wiki/Virtual_machine

Docker container khiến ta “cảm giác” như là

đang dùng VM vậy

- Có thể ssh vào container

- Có thể run các CLI của OS

- Không gian riêng bên trong container

-

Trang 64

Docker vs Hypervisor

Containers are an abstraction at

the app layer that packages code

and dependencies together.

Virtual machines (VMs) are an abstraction of physical hardware turning one server into many servers

Trang 65

Docker vs Hypervisor

65

Trang 66

Docker cưỡi Hypervisor

Trang 69

Docker CI/CD

● CI: Continuous Integration là development practice yêu cầu

các developers phải tích hợp(integrate) code vào shared

repository vài lần 1 ngày: mỗi thay đổi đều được test =

automated build để phát hiện sai sót.

● CD-Continuous Delivery: ốp tất cả những j thay

đổi (new feature, hotfix, ) vào phiên bản production (ko deploy luôn)

● CD-Continuous Deployment: bước tiếp theo

của Continuous Delivery là deploy luôn vào production

Trang 70

CI

Trang 71

Continuous Delivery/Deployment

71

Trang 72

CI/CD with Docker

Trang 73

Docker CI/CD in

Microservices

73

Trang 74

Docker CI/CD with Travis CI

- docker run carlad/sinatra /bin/sh -c "cd

/root/sinatra; bundle exec rake test"

script:

- bundle exec rake test

Trang 75

Docker CI/CD with CircleCI

75

Trang 76

CI/CD giúp gì?

● Speed: tăng tốc phát triển sản phẩm

● Quality: tăng chất lượng cho sảm phẩm

● Capacity and Scale: cho phép big team

cùng theo 1 dự án

● Cost: giảm cost meeting và management

● Focus: team member ko bị lẫn lộn nhiều

task cùng lúc

● Clarity: giảm stress

Trang 77

Tôi đã gói xôi như thế nào

Trang 78

Jarvis

Trang 79

79

Trang 80

database service app service

Trang 84

Chốt hạ

● Docker hay:

➽ Thống nhất môi trường

➽ Deploy nhẹ nhàng, Scale đơn giản, hiệu quả

➽ Càng ngày càng có nhiều Infrastructure service

(IaaS, PaaS) lớn hỗ trợ container

➽ Chuyển giao từ VM sang Container cần phải tìm

hiểu rất nhiều để ứng dụng trên production

Trang 85

85

Ngày đăng: 04/10/2018, 10:01

TỪ KHÓA LIÊN QUAN

🧩 Sản phẩm bạn có thể quan tâm

w