Top Banner
tsuru internals Francisco Souza @franciscosouza
57

tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •

Nov 11, 2018

Download

Documents

hoangthu
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: tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •

tsuru internals

Francisco Souza @franciscosouza

Page 2: tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •

what the f**rancisco?!

• Desenvolvedor @ Globo.com

• Open source fanboy

• tsuru developer desde Abril de 2012

Page 3: tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •
Page 4: tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •

Premissas

• Boas práticas

• Simplicidade

• Extensibilidade

• Escalabilidade

• Multilinguagem

• Open source

• No vendor lock-in

Page 5: tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •

Hands on

Page 6: tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •

Por baixo dos panos• app-create

Page 7: tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •

Por baixo dos panos• git push tsuru master

Page 8: tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •

Por baixo dos panos• Acessar http://hello.qcon.souza.cc

Page 9: tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •
Page 10: tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •

Internals

Page 11: tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •

Safe deployment

Page 12: tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •

Processo de deploy• Gera imagem da aplicação

• Cria unidades com imagem da aplicação

• Espera unidades responderem

• Adicionar unidades no balanceamento

• Remove unidades antigos do balanceamento

• Destrói unidades antigos no Docker

Page 13: tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •

Pipelining

• Organização em actions

• Toda action tem forward e backward

• Actions são encadeadas

• Quando uma action falha, o backward de todas as anteriores é executado

Page 14: tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •

type  Result  interface{}  

type  Forward  func(context  FWContext)  (Result,  error)  

type  Backward  func(context  BWContext)  

type  FWContext  struct  {                  Previous  Result                  Params      []interface{}  }  

type  BWContext  struct  {                  FWResult  Result                  Params  []interface{}  }  

type  Action  struct  {                  Name  string                  Forward  Forward                  Backward  Backward                  MinParams  int  }

Page 15: tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •

actions  :=  []*action.Action{                  &reserveUserApp,                  &insertApp,                  &exportEnvironmentsAction,                  &createRepository,                  &provisionApp,                  &setAppIp,  }  pipeline  :=  action.NewPipeline(actions...)  err  =  pipeline.Execute(app,  user)  if  err  !=  nil  {                  //  handle  error  }

Page 16: tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •

Unidade = Docker Container

Page 17: tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •

Container Scheduling

Page 18: tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •

docker-cluster

• Lib em Go para clusterização de nós de Docker

• Managed vs Unmanaged Nodes

Page 19: tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •

Scheduler• Segregação

• Disponibilidade

• Otimização de recursos

• Quantidade de containers

• Memória disponível

Page 20: tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •

Host 1

Host 2

Host 3

Page 21: tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •

Host 1

Host 2

Host 3

Page 22: tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •

Host 1

Host 2

Host 3

Page 23: tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •

Host 1

Host 2

Host 3

Page 24: tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •

Host 1

Host 2

Host 3

Page 25: tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •

Host 1

Host 2

Host 3

Page 26: tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •

Host 1

Host 2

Host 3

Page 27: tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •

Host 1

Host 2

Host 3

Page 28: tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •

IaaS Integration

Page 29: tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •

Managed nodes

• Nodes criados com integração com IaaS

• Suporte a EC2 e CloudStack

• [Soon] Suporte a docker-machine

• Extensível

Page 30: tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •

type  Machine  struct  {                  Id                          string  `bson:"_id"`                  Iaas                      string                  Status                  string                  Address                string                  CreationParams  map[string]string  }  

type  IaaS  interface  {                  CreateMachine(params  map[string]string)  (*Machine,  error)                  DeleteMachine(m  *Machine)  error  }

Page 31: tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •

Auto-scaling

Page 32: tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •

Node auto-scaling

• Detecta sobrecarga de recursos

• Quantidade de containers

• Quantidade de memória RAM

• Estratégia de scaling também extensível

Page 33: tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •

type  autoScaleEvent  struct  {                  ID                        interface{}  `bson:"_id"`                  MetadataValue  string                  Action                string                  Reason                string                  StartTime          time.Time                  EndTime              time.Time  `bson:",omitempty"`                  Successful        bool                  Error                  string              `bson:",omitempty"`                  Node                    cluster.Node  `bson:",omitempty"`                  Log                      string              `bson:",omitempty"`  }  

type  autoScaler  interface  {                  scale(event  *autoScaleEvent,  groupMetadata  string,  nodes  []*cluster.Node)  error  }  

Page 34: tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •

Container auto-scaling

• Serviço externo

• Baseado em métricas da aplicação

• Regras definidas pelo usuário

• Flexibilidade vs Complexidade

Page 35: tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •

Healing

Page 36: tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •

Node Healing

• Managed nodes

• Detecta que o nó caiu e substitui

• Monitoração ativa

• Monitoração passiva

Page 37: tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •

Container healing

• Detecta que um container não está saudável

• Status reporting

• Substitui o container

Page 38: tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •

Routers

Page 39: tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •

Routers

• Recebe e encaminha requests

• Suporte a múltiplos tipos

• Interface com operações de gerenciamento de backends e rotas

• Atrelado ao plano

Page 40: tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •

type  Router  interface  {                  AddBackend(name  string)  error                  RemoveBackend(name  string)  error                  AddRoute(name  string,  address  *url.URL)  error                  RemoveRoute(name  string,  address  *url.URL)  error                  SetCName(cname,  name  string)  error                  UnsetCName(cname,  name  string)  error                  Addr(name  string)  (string,  error)                  Swap(string,  string)  error                  Routes(name  string)  ([]*url.URL,  error)  }

Page 41: tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •

Routers (cont.)

• 3 implementações disponíveis:

• Hipache

• Galeb

• Vulcand

Page 42: tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •

Hipache• Router mais antigo

• Node.js

• Configuração no Redis

• WebSocket

• Criado pela DotCloud (atualmente Docker Inc.)

Page 43: tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •

Galeb• Router criado dentro da Globo.com

• Parcialmente open source (até o próximo trimestre)

• Java

• _Rápido_

• Configuração em memória (alterada dinamicamente via API)

• WebSocket

Page 44: tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •

Vulcand• Router mais novo no tsuru

• Go

• Configuração no etcd

• Criado pela Mailgun

• Sem suporte a WebSocket ainda

• Suporte a HTTPS com SNI

Page 45: tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •

Lean containers

Page 46: tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •

Hoje• Todos os processos do Procfile no container

• Agente dentro do container

• Controla processos

• Coleta logs

• Coleta métricas

• Reporta o status dos processos

Page 47: tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •

Problemas• Non-idiomatic Docker

• Agente em Python

• Alto consumo de memória

• Disputa recursos com processos da aplicação

• Python instalado na plataforma de Java?

Page 48: tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •

Lean containers• Um processo por container

• Um container por entrada no Procfile

• Agente rodando isoladamente em outro container

• Apenas uma instância do agente, coletando informações de todos os containers

• Docker controla e mantém processos rodando

Page 49: tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •

bs• Agente que roda dentro de um container

• Docker friendly

• docker run tsuru/bs

• Coleta informações de todos os containers irmãos

• Logs

• Saúde

• Métricas

Page 50: tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •

bs (cont.)

• Uso mais efetivo de recursos

• Escrito em Go

• Nasceu pra vigiar os containers irmãos

• Disponível apenas na próxima versão do tsuru :-(

Page 51: tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •

O que vem por aí

Page 52: tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •

Futuro• tsuru 1.0

• Lean containers

• Melhor gerenciamento de plataformas

• Melhor gerenciamento de plugins

• Integração com Docker Machine

• Terceirizar gerenciamento do cluster?

• Docker Swarm

• Kubernetes

Page 53: tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •

Contribua!

github.com/tsuru

Page 54: tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •

Contribua!

github.com/tsuru

Page 55: tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •

tsuru internals

Francisco Souza @franciscosouza slideshare.net/franciscosouza [email protected]

https://tsuru.io

Page 56: tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •

Links• https://tsuru.io

• https://docker.com

• http://galeb.io

• https://vulcand.io

• https://github.com/tsuru

• http://docs.tsuru.io

• https://github.com/tsuru/bs

• https://circus.rtfd.org

• https://www.docker.com/docker-swarm

• http://kubernetes.io/

Page 57: tsuru internals - qconrio.comqconrio.com/.../system/files/presentation-slides/tsuru_internals.pdf · what the f**rancisco?! • Desenvolvedor @ Globo.com • Open source fanboy •

Imagens• https://www.flickr.com/photos/underactive/4641141770/

• https://www.flickr.com/photos/dominicspics/1127762669/

• https://www.flickr.com/photos/jaxport/9613150301/

• https://www.flickr.com/photos/lukaskr/16036193656/

• https://www.flickr.com/photos/daveseven/6033338327/

• https://www.flickr.com/photos/jotbepunkt/7981094164/

• https://www.docker.com/sites/default/files/island_1.png

• https://www.flickr.com/photos/kightp/8083387488/

• https://www.flickr.com/photos/baggyjumper/6635779085/

• https://www.flickr.com/photos/98640399@N08/9410826173/