Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Deploying and Managing Python with Kubernetes by Joannah Nanjekye

Pycon ZA
October 11, 2018

Deploying and Managing Python with Kubernetes by Joannah Nanjekye

Because of the benefits of containers, python applications have been containerized recently. Containers have magically changed the way we deploy and manage python applications allowing us to build, develop, test, and even deploy python applications on a single system with no upgrade downtimes.

Kubernetes is the missing layer that gives us the ability to manage many containers by providing features that enable containers to scale, talk to each other and work in harmony.

This talk will focus on how python developers can leverage Kubernetes to manage any sort of python application on Kubernetes from simple to complex applications.

The talk will cover:

- The basics of Kubernetes.
- The basics of containerizing python applications.
- How to run and deploy simple, web and deep learning python pipelines on Kubernetes.
- How to manage or work with Kubernetes using the Kubernetes python client.

This talk will cover in summary the topics I talk about in my upcoming book "Deploying and Managing Python with Kubernetes" published by Apress sometime this year.

Pycon ZA

October 11, 2018
Tweet

More Decks by Pycon ZA

Other Decks in Technology

Transcript

  1. Deploying and Managing Python with Kubernetes Joannah Nanjekye

  2. About Me • Software Engineer • Aeronautical Engineer to be!

    • Open Sourcerer • Author • Upcoming UNB Grad to work on some pypy stuff <> IBM
  3. Agenda!! • Containers • Their Orchestration with Kubernetes! • Managing

    a cluster with Python.
  4. Rules • We may not have Q and A. </nanjekyejoannah@gmail.com>

  5. System Admins

  6. Meanwhile Developers

  7. Deploying Python Apps • Physical Machines • Virtual Machines •

    Containers
  8. Physical Machines Typically one application per host

  9. Virtual Machines • Virtualize the hardware. • Run multiple applications

    on same hardware.
  10. Containers • Logical Packaging for applications. • To run abstracted

    from the environment.
  11. Virtualize the OS • Run a container runtime on host

    operating system. • Better performance due to absence of guest operating systems
  12. Why do we care • Productivity • Portability • Scaling

  13. Ushering us to robust Platforms

  14. Containerization

  15. For a simple app from flask import Flask app =

    Flask(__name__) @app.route('/') def hello_world(): return 'Hello World!' if __name__ == '__main__': app.run(host='0.0.0.0')
  16. Dockerfile FROM gliderlabs/alpine:3.2 RUN apk-install python COPY requirements.txt . RUN

    apk --update add --virtual build-dependencies py-pip \ && pip install -r requirements.txt \ && apk del build-dependencies COPY . /code WORKDIR /code EXPOSE 5000 ENTRYPOINT ["python", "myapp.py"]
  17. Build and Run docker build -t docker-sinatra . docker run

    -p 4000:80 docker-sinatra
  18. None
  19. Best Practices • Create small images ◦ Performance ◦ Security

    • Unit test container images
  20. Unit Test Images #config.yaml With The Google Container Structure Test

    Framework
  21. Summary • Containers are a packaging for applications. • Giving

    us portability, increased productivity and scaling. • Create a container by creating a Dockerfile, build the image using instructions from this file, and run it to start the container.
  22. The last mile! • What happens when we have many

    containers? • How do we monitor them? • What about Scaling ?
  23. Kubernetes comes to the rescue! To help manage; • Deployments

    • Monitoring • Scaling
  24. Deployment • Specify an image from which to create a

    container. • Deployment criteria i.e RAM, CPU, storage
  25. Monitoring • Health check • Autorecovery

  26. Scaling • Cluster scaling. • Horizontal pod scaling.

  27. Kubernetes Architecture

  28. Client Makes API calls to the master

  29. Master

  30. Nodes

  31. Deploying Python App to Kubernetes Key Requirements • A container

    image for your application. • A deployment. • A service to expose your deployment
  32. Kubernetes Deployment kubectl create dep.yaml Using a .yaml file

  33. Kubernetes Deployment kubectl run kubernetes-bootcamp --image=gcr.io/google-samples/kubernetes-bootc amp:v1 --port=8080 Using kubectl

  34. Kubernetes service Using a .yaml file kubectl create service.yaml

  35. Scaling Increase number of replica sets in yaml or set

    in kubectl command.
  36. AutoScaling • Cluster scaling • Horizontal pod scaling

  37. Rolling Updates Pass a new image name and tag with

    the --image flag and (optionally) a new controller name kubectl rolling-update NAME [NEW_NAME] --image=IMAGE:TAG For zero upgrade downtimes
  38. Summary Kubernetes gives us; • Scaling • Monitoring • Zero

    upgrade down times
  39. Kubernetes Python Client

  40. Managing a cluster using python Write python code to access

    your cluster.
  41. For Inspiration • Watch Abby Fuller’s talk at Dockercon 2017

  42. Thank you @Captain-joannah nanjekyejoannah

  43. Thank you