Slide 1

Slide 1 text

Deploying and Managing Python with Kubernetes Joannah Nanjekye

Slide 2

Slide 2 text

About Me ● Software Engineer ● Aeronautical Engineer to be! ● Open Sourcerer ● Author ● Upcoming UNB Grad to work on some pypy stuff <> IBM

Slide 3

Slide 3 text

Agenda!! ● Containers ● Their Orchestration with Kubernetes! ● Managing a cluster with Python.

Slide 4

Slide 4 text

Rules ● We may not have Q and A.

Slide 5

Slide 5 text

System Admins

Slide 6

Slide 6 text

Meanwhile Developers

Slide 7

Slide 7 text

Deploying Python Apps ● Physical Machines ● Virtual Machines ● Containers

Slide 8

Slide 8 text

Physical Machines Typically one application per host

Slide 9

Slide 9 text

Virtual Machines ● Virtualize the hardware. ● Run multiple applications on same hardware.

Slide 10

Slide 10 text

Containers ● Logical Packaging for applications. ● To run abstracted from the environment.

Slide 11

Slide 11 text

Virtualize the OS ● Run a container runtime on host operating system. ● Better performance due to absence of guest operating systems

Slide 12

Slide 12 text

Why do we care ● Productivity ● Portability ● Scaling

Slide 13

Slide 13 text

Ushering us to robust Platforms

Slide 14

Slide 14 text

Containerization

Slide 15

Slide 15 text

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')

Slide 16

Slide 16 text

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"]

Slide 17

Slide 17 text

Build and Run docker build -t docker-sinatra . docker run -p 4000:80 docker-sinatra

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

Best Practices ● Create small images ○ Performance ○ Security ● Unit test container images

Slide 20

Slide 20 text

Unit Test Images #config.yaml With The Google Container Structure Test Framework

Slide 21

Slide 21 text

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.

Slide 22

Slide 22 text

The last mile! ● What happens when we have many containers? ● How do we monitor them? ● What about Scaling ?

Slide 23

Slide 23 text

Kubernetes comes to the rescue! To help manage; ● Deployments ● Monitoring ● Scaling

Slide 24

Slide 24 text

Deployment ● Specify an image from which to create a container. ● Deployment criteria i.e RAM, CPU, storage

Slide 25

Slide 25 text

Monitoring ● Health check ● Autorecovery

Slide 26

Slide 26 text

Scaling ● Cluster scaling. ● Horizontal pod scaling.

Slide 27

Slide 27 text

Kubernetes Architecture

Slide 28

Slide 28 text

Client Makes API calls to the master

Slide 29

Slide 29 text

Master

Slide 30

Slide 30 text

Nodes

Slide 31

Slide 31 text

Deploying Python App to Kubernetes Key Requirements ● A container image for your application. ● A deployment. ● A service to expose your deployment

Slide 32

Slide 32 text

Kubernetes Deployment kubectl create dep.yaml Using a .yaml file

Slide 33

Slide 33 text

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

Slide 34

Slide 34 text

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

Slide 35

Slide 35 text

Scaling Increase number of replica sets in yaml or set in kubectl command.

Slide 36

Slide 36 text

AutoScaling ● Cluster scaling ● Horizontal pod scaling

Slide 37

Slide 37 text

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

Slide 38

Slide 38 text

Summary Kubernetes gives us; ● Scaling ● Monitoring ● Zero upgrade down times

Slide 39

Slide 39 text

Kubernetes Python Client

Slide 40

Slide 40 text

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

Slide 41

Slide 41 text

For Inspiration ● Watch Abby Fuller’s talk at Dockercon 2017

Slide 42

Slide 42 text

Thank you @Captain-joannah nanjekyejoannah

Slide 43

Slide 43 text

Thank you