itlc hanoi 17 - infrastructure as code 07-01-2016

Post on 11-Feb-2017

1.764 Views

Category:

Software

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Infrastructure as Codeat VCCorp

Phạm Tuấn AnhTeam Platform Services, VCCloud

ITLC HANOI MONTHLY PUBLIC MEETUP

Agenda

1. Giới thiệu

2. Hiện trạng hệ thống trước năm 2014

3. Infrastructure as Code

4. Triển khai thực tế từ 2014 đến nay

5. Demo

Agenda

1. Giới thiệu

2. Hiện trạng hệ thống trước năm 2014

3. Infrastructure as Code

4. Triển khai thực tế từ 2014 đến nay

5. Demo

$ whoami• Phạm Tuấn Anh,

1988• 2 failed (funded)

startups• VCCorp từ 2010

• Co-founder của Appdex

• Stack: python, nginx, lua, git, ansible, redis, memcached, mysql, mongodb

VCCorp5 khối:

1. Nội dung

2. Thương mại điện tử (Zamba)

3. Game (Soha Game)

4. Quảng cáo (Admicro)

5. Hạ tầng (VCCloud)

VCCloud• > 60 người

• 3 bộ phận lớn:• Data

Center• Cloud Solutions

• Platform Services

• Các bộ phận nhỏ khác: Security, Helpdesk

Team Platform Services• Thành lập từ khoảng năm

2010• Hiện tại có 8

người• Các project chính:

• Storage (static files, ảnh, video…)

• CDN

• DDoS Request Filter

• PaaS

Một vài thống kê• ~ 3 tỷ files, 750TB (12 data nodes, hơn 200

HDDs)

• MySQL 450GB, MongoDB 560GB

• 30k requests/s, > 400k active connections

• 40Gbps, ~ 30% CPU, 7 servers

• HTTP access log ~ 1.4GB/phút

• > 20 projects lớn nhỏ, khoảng > 100 servers

Agenda

1. Giới thiệu

2. Hiện trạng hệ thống trước năm 2014

3. Infrastructure as Code

4. Triển khai thực tế từ 2014 đến nay

5. Demo

Hiện trạng hệ thống trước 2014

Một vài sự cố lớn:

• 2012: Database conflict

• 2013: DDoS

• 2014: Sập DC

Hiện trạng hệ thống trước 2014

Một vài vấn đề:

• các server cài giống nhau nhưng chạy khác nhau (facepalm)

• các rule về security áp dụng không đồng nhất (do làm thủ công và nhiều server)

• theo dõi hệ thống sơ sài, dùng con người là chính

• triển khai, thay thế server khó khăn, hay lỗi khi mới đưa vào

• server reboot: ~ 20-30 phút

Agenda

1. Giới thiệu

2. Hiện trạng hệ thống trước năm 2014

3. Infrastructure as Code

4. Triển khai thực tế từ 2014 đến nay

5. Demo

Configuration drift

A few key people to do "sensitive" deployments?

Human error factor

Infrastructure as Code

Infrastructure as Code

Reusable

Infrastructure as Code

Version Control

Infrastructure as Code

Coding Standards

Infrastructure as Code

Contribution

Infrastructure as Code

Code Review

Infrastructure as Code

Refactoring

Infrastructure as Code

Testing

Infrastructure as Code

Continuous Integration

Infrastructure as Code

Small Deployments

Infrastructure as Code

≠DevOps

Infrastructure as Code

≠Automation

Infrastructure as Code

=Automation at Scale

Infrastructure as Code:

1. Tự động hóa quá trình deploy

2. Quản lý (mọi thứ) thông qua source control

3. Áp dụng tests

4. Hạn chế viết tài liệu

5. Dev & Ops cộng tác trên cùng 1 repo

Agenda

1. Giới thiệu

2. Hiện trạng hệ thống trước năm 2014

3. Infrastructure as Code

4. Triển khai thực tế từ 2014 đến nay

5. Demo

Triển khai thực tế:

• Wikimedia:

http://git.wikimedia.org/project/operations

• Bắt đầu từ tháng 7/2014 đến hiện tại (~18 tháng)

• Công cụ: Ansible, Git, GitLab, GitLab CI

Tại sao lại chọn Ansible?

• "agentless"

• Cú pháp rõ ràng

• Tài liệu chi tiết, nhiều module có sẵn

• Phổ biến

• Tốc độ?

Ansible vs Salt

Ansible vs Chef

Ansible vs Puppet

GitLab CI?

• jenkins

• GitLab CI UI đẹp hơn :)

Một vài vấn đề khi triển khai:• Con người

• Setup môi trường

• Password, secret keys trên production

• Git workflow

• Tests

Con người:

• Ops: Học thêm git, ansible

• Dev: Học thêm ansible

• Thay đổi thói quen:• Giảm login vào server để

sửa• Fix lỗi xong viết

tests/checks

Con người:• Khó

khăn:• naming things

– Phil Karlton

“There are only two hard things in Computer Science: cache

invalidation and naming things.”

Con người:• Khó

khăn:• naming things

• good commit messages

• atomic commits

• check-in early, check-in often

Setup môi trường:

• development (mỗi dev được cấp 1 server ảo)

• test (dành riêng cho server CI chạy)

• staging (dùng gor để capture & replay traffic từ production)

• production

Setup môi trường:

$ gor --http-original-host \--input-raw :80

\--output-http "http://10.3.3.4|5%"

Password, secret keys trên production:

• ansible-vault

• ejson (Shopify)

• vault (HashiCorp), keywhiz (Square)

Git workflow:

Git workflow:

• master là nhánh ổn định, khi cần có thể deploy ngay

• các thay đổi được làm ở topic branches

• rebase sớm để tránh conflicts

• push trực tiếp vào repo chính, không dùng Fork

• roll forward

Tests• các gói, thư viện cài đúng

chưa?• service chạy thật

chưa?• firewall chặn SSH từ WAN

chưa?• disable password login chưa?

• cảnh báo mail khi SSH hoạt động không?

• mạng server có bình thường không?

• …

Tests• coding, writing style

• deploy (ansible)

• unit tests

• smoke tests (các service running hết chưa?)

• integration tests (theo logic cụ thể của từng project)

• nagios

Continuous Integration• git commit

• git push lên GitLab

• GitLab gọi GitLab CI

• GitLab CI đẩy task sang GitLab CI Runner

• GitLab CI Runner chạy tests và report lại kết quả

• deploy lên production (thủ công)

Một số lưu ý khi triển khai:• Admin UI → Config

files• SSH 2-factor → OpenVPN +

DuoSecurity• Packages/dependencies

• Account deploy dùng chung?

Kết quả đem lại:• Giảm áp lực vận hành hệ

thống• Giảm lỗi, các server chạy thống

nhất• Có log chi tiết các thay

đổi• Việc chia sẻ, phối hợp trong team dễ dàng

hơn• Các thay đổi được review, test trước khi

deploy• Người đi - kiến thức ở

lại

Q&A

FAQs• Sao không dùng dynamic

inventory?• Merge/Pull Requests dùng thế

nào?• Merge vào master luôn như thế có nguy

hiểm không?

• Ansible deploy chậm

• CI server deploy lên đâu? Làm sao có môi trường như production để test?

FAQs• "Cloud" ở đâu?

• Zero-downtime reloads?

• Có server cần tham số riêng thì làm thế nào?

• Quản lý đồng thời server CentOS và Ubuntu thế nào?

• Các module ansible hay dùng?

FAQs

• Auto scale?

• Ansible vs Docker?

• Khi provision infra tự động mà bị lỗi thì các bạn xử lý thế nào? Có bài học nào hay ho không?

• Những khó khăn và thách thức nào khi xây dựng và quản lý hạ tầng private và public?

Agenda

1. Giới thiệu

2. Hiện trạng hệ thống trước năm 2014

3. Infrastructure as Code

4. Triển khai thực tế từ 2014 đến nay

5. Demo

Inventory file

Templates

Templates

Tasks

Tasks

Deploy

Quản lý users

Quản lý users

Quản lý users

Iptables

Iptables

Update DNS

Update DNS

Deploy server mới

Security fix

Thêm cảnh báo

Q&A

Một số link tham khảo• Ansible Best Practices:

http://docs.ansible.com/ansible/ playbooks_best_practices.html

• Ansible Vault: https://therealmarv.com/ansible-vault-file-handling/

• Ansible Modules: http://docs.ansible.com/ansible/ modules_by_category.html

• RedHat mua Ansible: https://www.redhat.com/en/about/blog/ why-red-hat-acquired-ansible

• Continuous Delivery: https://puppetlabs.com/sites/default/files/ CDebook.pdf

top related