Docker a Kubernetes

CLOUD COMPUTING

de

Docker

docker command

docker daemon (API)

docker registry

?

Container orchestrators

a

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

Local

  • Minikube
  • Docker Desktop (Windows y Mac)
  • MicroK8S
  • k3s

Nube pública

  • Google Cloud (GKE)
  • Amazon (EKS)
  • Azure (AKS)
  • DigitalOcean

Raspberry Pi

Private
datacenter

Instalación de kubernetes

Kubernetes en la nube

  • Administración del Master
  • Nodos pueden ser VM
  • Gestión de actualizaciones
  • Precio

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-simple
spec:
  containers:
    - name: hostname
      image: oguzpastirmaci/hostname

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:
    app: hostname
spec:
  replicas: 3
  selector:
    matchLabels:
      app: hostname
  template:
      metadata:
        name: hostname-pod-example
        labels:
          app: 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:
    app: hostname
spec:
  replicas: 5
  selector:
    matchLabels:
      app: hostname
  strategy:
    type: RollingUpdate
  template:
      metadata:
        name: hostname-pod-example
        labels:
          app: 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:
    app: hostname
spec:
  replicas: 5
  selector:
    matchLabels:
      app: hostname
  strategy:
    type: RollingUpdate
  template:
      metadata:
        name: hostname-pod-example
        labels:
          app: 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: hostname
  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: hostname
  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

Sobre esta presentación

CLOUD COMPUTING

Atribución 4.0 Internacional (CC BY 4.0)

https://creativecommons.org/licenses/by/4.0/deed.es

Docker a Kubernetes

By Rodolfo Pilas

Docker a Kubernetes

  • 302