¿Por qué todo el mundo quiere usar kubernetes ?

Que es kubernetes (En 5 minutos)

Abstracciones de nivel superior

  • ETCD
  • Control plane
  • Workers

Arquitectura de k8s

Arquitectura de k8s

Alta disponibilidad

ClusterIP

NodePort

LoadBalancer

Ingress

apiVersion: apps/v1 # Usa apps/v1beta2 para versiones anteriores a 1.9.0
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 2 # indica al controlador que ejecute 2 pods
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.7.9
        ports:
        - containerPort: 80
kubectl apply -f deployment.yaml

EJemplo de YAML kubernetes

Por que es el favorito ?

¿Por que usar contenedores y estas APIs de contenedores?

"El ser humano es flojo por naturaleza"

 

Simplifica todo lo relacionado a DevOps

  • Velocity

  • Scaling (of both software and teams)

  • Abstracting your infrastructure

  • Efficiency

Escalado y autoescalado

apiVersion: apps/v1
kind: Deployment
metadata:
  name: php-apache
spec:
  selector:
    matchLabels:
      run: php-apache
  replicas: 1
  template:
    metadata:
      labels:
        run: php-apache
    spec:
      containers:
      - name: php-apache
        image: k8s.gcr.io/hpa-example
        ports:
        - containerPort: 80
        resources:
          limits:
            cpu: 500m
          requests:
            cpu: 200m

---

apiVersion: v1
kind: Service
metadata:
  name: php-apache
  labels:
    run: php-apache
spec:
  ports:
  - port: 80
  selector:
    run: php-apache
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
  name: php-apache
  namespace: default
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: php-apache
  minReplicas: 1
  maxReplicas: 10
  metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization
        averageUtilization: 50

Descubrimiento de servicios y balanceo de carga

Gestión de la configuración y secrets

apiVersion: v1
kind: ConfigMap
metadata:
  name: special-config
  namespace: default
data:
  SPECIAL_LEVEL: very
  SPECIAL_TYPE: charm
apiVersion: v1
kind: Pod
metadata:
  name: dapi-test-pod
spec:
  containers:
    - name: test-container
      image: k8s.gcr.io/busybox
      command: [ "/bin/sh", "-c", "env" ]
      env:
      - name: SECRET_USERNAME
        valueFrom:
          secretKeyRef:
            name: mysecret
            key: username
      envFrom:
      - configMapRef:
          name: special-config
  restartPolicy: Never
apiVersion: v1
kind: Secret
metadata:
  name: mysecret
type: Opaque
data:
  username: YWRtaW4=
  password: MWYyZDFlMmU2N2Rm

Despliegues y rollbacks automáticos

Story time

Story time

new-app-1.host.com

Velocidad 😍

Story time

# create deployment
cat <<EOF | kubectl apply -n "${NAMESPACE}" -f -
apiVersion: apps/v1
kind: Deployment
metadata:
  name: $DEPLOYMENT
  labels:
    app: $NAME
spec:
  replicas: 1
  selector:
    matchLabels:
      app: $NAME
  template:
    metadata:
      labels:
        app: $NAME
    spec:
      containers:
      - name: $NAME_APP
        image: $SHA_DOCKER_NAME
        ports:
          - containerPort: 2000

---
kind: Service
apiVersion: v1
metadata:
  name: $NAME_SERVICE
spec:
  selector:
    app: $NAME
  ports:
    - port: 2000
EOF

# create ingress
cat <<EOF | kubectl apply -n ${NAMESPACE} -f -
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: $NAME_INGRESS
  namespace: $NAMESPACE
  annotations:
    nginx.ingress.kubernetes.io/ssl-redirect: "true"
    nginx.ingress.kubernetes.io/force-ssl-redirect: "false"
    nginx.ingress.kubernetes.io/rewrite-target: /
    kubernetes.io/ingress.class: "nginx"
spec:
  tls:
    - hosts:
        - $HOST
      secretName: tls-secret
  rules:
    - host: $HOST
      http:
        paths:
          - path: /
            backend:
              serviceName: $NAME_SERVICE
              servicePort: 2000
EOF

kubectl rollout status deployment.v1.apps/"$DEPLOYMENT"

Script en CI/CD

Tips & Tricks

Usar helm

Usar calico para politicas de red

K8s dashboard

kops create cluster \
    --zones us-west-2a \
    test

Por qué todo el mundo quiere usar kubernetes ?

By Jesus David Diaz

Por qué todo el mundo quiere usar kubernetes ?

  • 602