Introduction to Containers and Kubernetes

Introduction to Containers and Kubernetes

An introductory talk on containers in general and Kubernetes specifically

6c18ceafef161be26ae441469b29c475?s=128

Terrence Ryan

June 08, 2017
Tweet

Transcript

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

    Kubernetes
  2. ‹#› @tpryan Who are you?

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

  4. ‹#› @tpryan Matrix from Hell Dev 1 Laptop Dev 2

    Laptop QA Stage Production OS ? ? ? ? ? Frontend ? ? ? ? ? Services ? ? ? ? ? Database ? ? ? ? ? Logs ? ? ? ? ?
  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/
  6. ‹#› @tpryan It worked fine in dev It worked fine

    in dev Ops Problem now Ops Problem now
  7. ‹#› @tpryan

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

  9. ‹#› @tpryan Container Host Containers OS

  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/*
  11. ‹#› @tpryan Matrix from Hell Dev 1 Laptop Dev 2

    Laptop QA Stage Production OS Frontend Services Database Logs
  12. ‹#› @tpryan 02 Introduction Why Kubernetes?

  13. ‹#› @tpryan What problem are 
 we trying to solve?

  14. ‹#› @tpryan # FRONTEND AND SERVICES FROM nginx-php-fpm COPY nginx.conf

    /etc/nginx/nginx.conf ADD www /var/www/
  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"]
  16. ‹#› @tpryan

  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/
  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/
  19. ‹#› @tpryan

  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"]
  21. ‹#› @tpryan

  22. ‹#› @tpryan

  23. ‹#› @tpryan

  24. ‹#› @tpryan

  25. ‹#› @tpryan

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

  27. ‹#› @tpryan 4 3 2

  28. ‹#› @tpryan Kubernetes • Container Orchestration System • Open Source

    • Started by Google • Contributed to by others
  29. ‹#› @tpryan 03 App in Kubernetes

  30. ‹#› @tpryan DB API UI LAMP

  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
  32. ‹#› @tpryan Running containers Pod Pod Pod Pod Replica Set

    Deployment
  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
  34. ‹#› @tpryan Create a Deployment # Create deployment kubectl create

    -f deployment.yaml
  35. ‹#› @tpryan Containers as Pets Pod Stateful Set Persistent Volume

    Claim
  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
  37. ‹#› @tpryan Exposing containers Pod Pod Pod Pod Service

  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
  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
  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
  41. ‹#› @tpryan Demo: Kubernetes in Action

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

  43. ‹#› @tpryan Kubernetes is Open Source We want your help!

    • http://kubernetes.io • https://github.com/kubernetes/kubernetes • irc.freenode.net #google-containers • @kubernetesio
  44. ‹#› @tpryan

  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
  46. ‹#› @tpryan Roadmap Kubernetes 1.7 Target: June 2017 https://github.com/kubernetes/kubernetes/milestones/

  47. Google has been developing and using containers to manage our

    applications for over 10 years.
  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
  49. ‹#› @tpryan We think containers are the way to manage

    scale.
  50. ‹#› @tpryan You should carefully consider whether running everything on

    containers is right for you.
  51. ‹#› @tpryan You should run everything on containers.

  52. ‹#› @tpryan You should carefully consider whether running everything on

    containers is right for you.
  53. ‹#› @tpryan

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