$30 off During Our Annual Pro Sale. View Details »

Introduction to Containers and Kubernetes

Introduction to Containers and Kubernetes

An introductory talk on containers in general and Kubernetes specifically

Terrence Ryan

June 08, 2017
Tweet

More Decks by Terrence Ryan

Other Decks in Technology

Transcript

  1. ‹#›
    @tpryan
    Terry Ryan
    Developer Advocate
    Introduction to
    Containers and Kubernetes

    View Slide

  2. ‹#›
    @tpryan
    Who are you?

    View Slide

  3. ‹#›
    @tpryan
    01 Introduction
    Why Containers?

    View Slide

  4. ‹#›
    @tpryan
    Matrix from Hell
    Dev 1 Laptop Dev 2 Laptop QA Stage Production
    OS
    ? ? ? ? ?
    Frontend
    ? ? ? ? ?
    Services
    ? ? ? ? ?
    Database
    ? ? ? ? ?
    Logs
    ? ? ? ? ?

    View Slide

  5. ‹#›
    @tpryan
    Matrix from Hell
    Dev 1 Laptop Dev 2 Laptop QA Stage Production
    OS
    OS X Windows Debian Debian Debian
    Frontend nginx
    (homebrew)
    nginx
    (download)
    nginx
    (apt-get)
    nginx
    (apt-get)
    nginx
    (apt-get)
    Services php
    (homebrew)
    php
    (download)
    php
    (apt-get)
    php
    (apt-get)
    php
    (apt-get)
    Database mysql
    (download)
    mysql
    (download)
    mysql
    (apt-get)
    mysql
    (apt-get)
    mysql
    (apt-get)
    Logs
    /usr/local/etc/nginx/logs/ C:\nginx-1.9.5\logs /var/log/nginx/ /var/log/nginx/ /var/log/nginx/

    View Slide

  6. ‹#›
    @tpryan
    It worked fine in dev
    It worked fine in dev
    Ops Problem now
    Ops Problem now

    View Slide

  7. ‹#›
    @tpryan

    View Slide

  8. ‹#›
    @tpryan
    Hypervisor
    Virtual Machine
    OS OS
    OS

    View Slide

  9. ‹#›
    @tpryan
    Container Host
    Containers
    OS

    View Slide

  10. ‹#›
    @tpryan
    Dockerfile
    FROM gcr.io/php-mvm-a/php-nginx:latest
    ENV DOCUMENT_ROOT /app/web
    COPY default /app/web
    RUN chmod -R 755 /app/web/*

    View Slide

  11. ‹#›
    @tpryan
    Matrix from Hell
    Dev 1 Laptop Dev 2 Laptop QA Stage Production
    OS
    Frontend
    Services
    Database
    Logs

    View Slide

  12. ‹#›
    @tpryan
    02 Introduction
    Why Kubernetes?

    View Slide

  13. ‹#›
    @tpryan
    What problem are 

    we trying to solve?

    View Slide

  14. ‹#›
    @tpryan
    # FRONTEND AND SERVICES
    FROM nginx-php-fpm
    COPY nginx.conf /etc/nginx/nginx.conf
    ADD www /var/www/

    View Slide

  15. ‹#›
    @tpryan
    # BACKEND
    FROM ubuntu:12.04
    ADD ./mysql-setup.sh /tmp/mysql-setup.sh
    RUN /bin/sh /tmp/mysql-setup.sh
    EXPOSE 3306
    CMD ["/usr/sbin/mysqld"]

    View Slide

  16. ‹#›
    @tpryan

    View Slide

  17. ‹#›
    @tpryan
    # FRONTEND AND SERVICES
    FROM nginx-php-fpm
    COPY nginx.conf /etc/nginx/nginx.conf
    ADD www /var/www/
    # JUST SERVICES
    FROM nginx-php-fpm
    COPY nginx.conf /etc/nginx/nginx.conf
    ADD www /var/www/

    View Slide

  18. ‹#›
    @tpryan
    # FRONTEND AND SERVICES
    FROM nginx-php-fpm
    COPY nginx.conf /etc/nginx/nginx.conf
    ADD www /var/www/
    # FRONTEND
    FROM nginx
    COPY nginx.conf /etc/nginx/nginx.conf
    ADD www /var/www/

    View Slide

  19. ‹#›
    @tpryan

    View Slide

  20. ‹#›
    @tpryan
    # BACKEND
    FROM ubuntu:12.04
    ADD ./mysql-setup.sh /tmp/mysql-setup.sh
    RUN /bin/sh /tmp/mysql-setup.sh
    EXPOSE 3306
    CMD ["/usr/sbin/mysqld"]
    # BACKEND
    FROM ubuntu:12.04
    ADD ./mysql-setup.sh /tmp/mysql-setup.sh
    RUN /bin/sh /tmp/mysql-setup.sh
    EXPOSE 3306
    VOLUME ["/etc/mysql", "/var/lib/mysql"]
    CMD ["/usr/sbin/mysqld"]

    View Slide

  21. ‹#›
    @tpryan

    View Slide

  22. ‹#›
    @tpryan

    View Slide

  23. ‹#›
    @tpryan

    View Slide

  24. ‹#›
    @tpryan

    View Slide

  25. ‹#›
    @tpryan

    View Slide

  26. ‹#›
    @tpryan
    That’s a lot to manage.

    View Slide

  27. ‹#›
    @tpryan
    4 3 2

    View Slide

  28. ‹#›
    @tpryan
    Kubernetes
    • Container Orchestration System
    • Open Source
    • Started by Google
    • Contributed to by others

    View Slide

  29. ‹#›
    @tpryan
    03 App in Kubernetes

    View Slide

  30. ‹#›
    @tpryan
    DB
    API
    UI
    LAMP

    View Slide

  31. ‹#›
    @tpryan
    Dockerfiles
    FROM mysql/mysql-server:5.6
    ADD sql/load.sql /docker-entrypoint-initdb.d/load.sql
    EXPOSE 3306
    DB
    FROM httpd:2.4
    COPY ui /usr/local/apache2/htdocs/ui
    COPY static /usr/local/apache2/htdocs/static
    UI
    FROM php:7.0-apache
    RUN apt-get update && apt-get install -y php5-mysqlnd
    RUN docker-php-ext-install mysqli
    RUN a2enmod rewrite && a2enmod headers && service apache2 restart
    COPY app/ /var/www/html/
    API

    View Slide

  32. ‹#›
    @tpryan
    Running containers
    Pod Pod Pod Pod
    Replica Set
    Deployment

    View Slide

  33. ‹#›
    @tpryan
    Deployment
    apiVersion: extensions/v1beta1
    kind: Deployment
    metadata:
    name: frontend-deployment
    spec:
    replicas: 4
    strategy:
    type: RollingUpdate
    template:
    metadata:
    labels:
    layer: ui
    spec:
    containers:
    - name: "frontend"
    image: "gcr.io/lamp-in-containers/locations-frontend"
    ports:
    - name: "http"
    containerPort: 80
    protocol: TCP
    Pod
    Replica Set
    Deployment

    View Slide

  34. ‹#›
    @tpryan
    Create a Deployment
    # Create deployment
    kubectl create -f deployment.yaml

    View Slide

  35. ‹#›
    @tpryan
    Containers as Pets
    Pod
    Stateful Set
    Persistent
    Volume
    Claim

    View Slide

  36. ‹#›
    @tpryan
    Stateful Set
    apiVersion: apps/v1beta1
    kind: StatefulSet
    metadata:
    name: db-set
    spec:
    serviceName: "mysql"
    replicas: 1
    template:
    metadata:
    labels:
    layer: db
    spec:
    terminationGracePeriodSeconds: 0
    containers:
    - name: db
    image: "gcr.io/lamp-in-containers/locations-db"
    ports:
    - containerPort: 3306
    name: mysql
    volumeMounts:
    - name: mysql-pvc
    mountPath: /var/lib/mysql
    volumeClaimTemplates:
    - metadata:
    name: mysql-pvc
    annotations:
    volume.alpha.kubernetes.io/storage-class: anything
    spec:
    accessModes: [ "ReadWriteOnce" ]
    resources:
    requests:
    storage: 1Gi
    Pod
    Persistent
    Volume
    Claim
    Stateful Set

    View Slide

  37. ‹#›
    @tpryan
    Exposing containers
    Pod Pod Pod Pod
    Service

    View Slide

  38. ‹#›
    @tpryan
    Deployment
    apiVersion: extensions/v1beta1
    kind: Deployment
    metadata:
    name: frontend-deployment
    spec:
    replicas: 4
    strategy:
    type: RollingUpdate
    template:
    metadata:
    labels:
    layer: ui
    spec:
    containers:
    - name: "frontend"
    image: "gcr.io/lamp-in-containers/locations-frontend"
    ports:
    - name: "http"
    containerPort: 80
    protocol: TCP
    Pod
    Label

    View Slide

  39. ‹#›
    @tpryan
    Service
    apiVersion: v1
    kind: Service
    metadata:
    labels:
    name: frontend
    name: frontend
    spec:
    type: LoadBalancer
    ports:
    - port: 80
    targetPort: 80
    protocol: TCP
    selector:
    layer: ui
    Selector

    View Slide

  40. ‹#›
    @tpryan
    ui Pod
    ui deployment
    ui Pod
    ui Pod ui Pod
    ui service (public)
    api Pod
    api deployment
    api service (public)
    api Pod api Pod
    db statefulset
    db service (private)
    db Pod

    View Slide

  41. ‹#›
    @tpryan
    Demo: Kubernetes in Action

    View Slide

  42. ‹#›
    @tpryan
    05 Conclusions
    Bring it home

    View Slide

  43. ‹#›
    @tpryan
    Kubernetes is Open Source
    We want your help!
    • http://kubernetes.io
    • https://github.com/kubernetes/kubernetes
    • irc.freenode.net #google-containers
    • @kubernetesio

    View Slide

  44. ‹#›
    @tpryan

    View Slide

  45. ‹#›
    @tpryan
    Roadmap
    Kubernetes 1.6
    Released: March 2017
    • Scale enhancement - 5000 nodes, 150,000 pods
    • Advanced Scheduling
    • Storage Enhancements for 

    AWS, Azure, GCP, OpenStack and VMware vSphere
    • Interesting alpha:
    • Nvidia GPU support
    http://blog.kubernetes.io/2017/03/kubernetes-1.6-multi-user-multi-workloads-at-scale.html

    View Slide

  46. ‹#›
    @tpryan
    Roadmap
    Kubernetes 1.7
    Target: June 2017
    https://github.com/kubernetes/kubernetes/milestones/

    View Slide

  47. Google has been developing and
    using containers to manage our
    applications for over 10 years.

    View Slide

  48. ‹#›
    @tpryan
    Everything at Google runs on Containers:
    • Gmail, Web Search, Maps, ...
    • MapReduce, batch, ...
    • GFS, Colossus, ...
    • Even Google’s Cloud Platform: VMs run
    in containers!
    We launch 2 Billion Containers a week

    View Slide

  49. ‹#›
    @tpryan
    We think containers are the
    way to manage scale.

    View Slide

  50. ‹#›
    @tpryan
    You should carefully consider
    whether running everything on
    containers is right for you.

    View Slide

  51. ‹#›
    @tpryan
    You should run everything on
    containers.

    View Slide

  52. ‹#›
    @tpryan
    You should carefully consider
    whether running everything on
    containers is right for you.

    View Slide

  53. ‹#›
    @tpryan

    View Slide

  54. ‹#›
    @tpryan
    Thank You
    terrenceryan.com
    @tpryan
    This preso: http://bit.ly/tpryan-intro-k8s

    View Slide