Docker Workshop

Revisión 2020 - Parte 4/4

Múltiples contenedores

cont..

ejemplo 1

Docker Host (darlene)

lan

docker0

nginx

wordpress

mariadb

docker-gen

letsencrypt

/var/run/docker.sock

docker.sock is the UNIX socket that Docker daemon is listening to. It's the main entry point for Docker API. By default for security reasons Docker defaults to use UNIX socket (but it may be TCP socket)

ejemplo 2

Docker Host (rocha)

lan

docker0

traefik

rocketchat

mongo

mongo-replica

hubot

/var/run/docker.sock

ejemplo 3

Docker Host (tyrion)

lan

proxy

traefik

dokuwiki

roundcube

seafile

redmine

internal

mysql

Múltiples contenedores

for development

estructura
básica

consola-control/
├── api
│   ├── Dockerfile
│   ├── package.json
│   └── src
│       └── index.js
└── docker-compose.yml
FROM node:8
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 8080
CMD [ "npm", "start" ]
services: 
  frontend:
    build: api
    links:
      - backend:redis
    ports:
      - 8081:8081
    environment:
      - VAR1=value
    networks: 
      - consola-control
    depends_on:
      - backend
    restart: always

  backend:
    image: redis:3
    networks:
      - consola-control
    restart: always

networks:
   consola-control:

SRE Compliance Framework

├── api/
    ├── Dockerfile.local
    ├── Dockerfile.release
    ├── docker-compose.yml
    ├── docker-compose.stag.yml
    ├── deploy_settings.stag.yml
    ├── .dockerignore
    └── bin/
        └── sre-cli
sre-cli v0.1.2 asetup

sre-cli v0.1.2 adeploy
---
git_repo: "github.com/moove-it/inari.git"
git_branch: "master"
server_user: "mooveit"
server_app_folder: "/home/mooveit/inari"
origin_tag_deploy: false
host_ip: "18.188.57.139"
env_name: stag
enable_monitoring: true # optional

Remote setup & Deploy:

de Docker
a Kubernetes

Container orchestrators

Kubernetes

Kubernetes

cluster

master

node

node

worker
(minion)

worker
(minion)

Kubernetes architecture

node

master

kubectl
(cli)

dashboard
(ui)

REST client
(code)

kubelet

API
server

Scheduller

etcd

Controller
Manager

kube-proxy

Pod

Pod

Pod

Historia de Kubernetes

Junio
2014

Julio
2014

Julio
2015

Marzo
2018

Commit inicial en GitHub (Google) k8s - Go

Microsoft, RedHat, IBM y Docker

Kubernetes v1.0

Nov
2015

Primer KubeCon

Feb
2016

Helm Package Manager

CNCF Certified

Kubernetes ecosytem

Instalación de kubernetes (dev)

brew install kubernetes-cli

Curva de aprendizaje de Kubernetes

Namespace

  • propiedad adicional de los recursos
  • Separación lógica (virtual cluster)
  • Diferentes teams
  • Diferentes environments
# kubectl apply -f namespace.yaml

apiVersion: v1
kind: Namespace
metadata:
  name: my-namespace

Pod

  • Encapsula 1 o más contenedores
  • Comparte storage
  • Comparte network:
    • IP address
    • Rango de puertos
# kubectl apply -f hostname-pod.yaml

apiVersion: v1
kind: Pod
metadata:
  name: hostname-pod-example
spec:
  containers:
    - name: hostname
      image: adongy/hostname-docker

ReplicaSet

  • Escalabilidad
  • Alta-disponibilidad
  • Dispersa pods entre nodos worker
# kubectl apply -f hostname-replicaset.yml
apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: hostname-rs-example
  labels:
    name: hostname
spec:
  replicas: 3
  selector:
    matchLabels:
      name: hostname
  template:
      metadata:
        name: hostname-pod-example
        labels:
          name: hostname
          language: golang
      spec:
        containers:
          - name: hostname
            image: adongy/hostname-docker

Deployment

  • Actualiza ReplicaSet
  • Manejo de versiones
  • Roll-back
# kubectl apply -f hostname-deploy.yml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: deploy-example-1
  labels:
    name: example-1
spec:
  replicas: 5
  selector:
    matchLabels:
      name: hostname
  strategy:
    type: RollingUpdate
  template:
      metadata:
        name: hostname-pod-example
        labels:
          name: hostname
          language: golang
      spec:
        containers:
          - name: hostname
            image: adongy/hostname-docker

Deployment

Las aplicaciones se ven como
Deployments

# kubectl apply -f hostname-deploy.yml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: deploy-example-1
  labels:
    name: example-1
spec:
  replicas: 5
  selector:
    matchLabels:
      name: hostname
  strategy:
    type: RollingUpdate
  template:
      metadata:
        name: hostname-pod-example
        labels:
          name: hostname
          language: golang
      spec:
        containers:
          - name: hostname
            image: adongy/hostname-docker

Service

  • IP -> Pods
  • Crea EndPoint a la app
  • Varios tipos
  • No balancea carga
# kubectl apply -f hostname-service.yml
apiVersion: v1
kind: Service
metadata:
  name: hostname-svc
  labels:
    app: hostname
spec:
  type: ClusterIP
  selector:
    app: server
  ports:
  - port: 9999
    protocol: TCP
    targetPort: 3000

Service

# kubectl apply -f hostname-service.yml
apiVersion: v1
kind: Service
metadata:
  name: hostname-svc
  labels:
    app: hostname
spec:
  type: ClusterIP
  selector:
    app: server
  ports:
  - port: 9999
    protocol: TCP
    targetPort: 3000

El EndPoint es interno al cluster, para conectar necesitamos:

  • Un pod
  • Habilitar forward (dev)

Ingress







apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: hostname-ing
  labels:
    name: hostname
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
  rules:
  - http:
      paths:
      - path: /hostname(/|$)(.*)
        backend:
          serviceName: hostname-svc
          servicePort: 3333
  • Requiere controlador
  • Controlador SSL / LB
  • Configura reglas (path)
  • Vincula con EndPoint

... a seguir

poner en container las apps

TODAS !

SRE Team puede colaborar

Docker Workshop 4/4

By Rodolfo Pilas

Docker Workshop 4/4

Moove-it Docker Workshop 4/4

  • 227