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

Python, Kubernetes & friends

Python, Kubernetes & friends

This is the presentation I made for PyGrunn 2016.

Thanks to Jobandtalent for sponsoring my trip! :)

Alexandre González

May 13, 2016
Tweet

More Decks by Alexandre González

Other Decks in Technology

Transcript

  1. OUR FIRST APP! $ kubectl run pygrunn \ --image=python:2.7 \

    --command -- python -m SimpleHTTPServer
  2. A POD $ kubectl get pods NAME READY STATUS RESTARTS

    AGE pygrunn-1906403705-dckh7 1/1 Running 0 1m
  3. AND A DEPLOYMENT $ kubectl get deployments NAME DESIRED CURRENT

    UP-TO-DATE AVAILABLE AGE pygrunn 1 1 1 1 2m
  4. SHOW IT TO THE WORLD $ kubectl expose deployment pygrunn

    \ --port=80 --target-port=8000 --type=LoadBalancer
  5. HERE IT IS $ kubectl get services NAME CLUSTER-IP EXTERNAL-IP

    PORT(S) AGE pygrunn 10.3.255.124 130.211.52.23 80/TCP 57s
  6. MAIN.PY from flask import Flask, url_for app = Flask(__name__) @app.route('/')

    def index(): return '<img width="100%" src="{}" />'.format( url_for('static', filename='grumpy.gif') ) if __name__ == '__main__': app.run(host='0.0.0.0')
  7. DEPLOYMENT.YAML (3/3) ... spec: containers: - name: app image: agonzalezro/pygrunn:grumpy

    ports: - containerPort: 5000 - name: nginx image: agonzalezro/pygrunn-nginx ports: - containerPort: 80 readinessProbe: httpGet: path: / port: 80
  8. apiVersion: extensions/v1beta1 kind: Deployment metadata: name: pygrunn-deploy labels: name: pygrunn-deploy

    spec: replicas: 3 selector: matchLabels: name: flask-app template: metadata: labels: name: flask-app spec: containers: - name: app image: agonzalezro/pygrunn:happy ports: - containerPort: 5000 - name: nginx image: agonzalezro/pygrunn-nginx ports: - containerPort: 80 readinessProbe: httpGet: path: / port: 80
  9. SERVICE.YAML apiVersion: v1 kind: Service metadata: name: flask-service spec: type:

    LoadBalancer ports: - port: 80 targetPort: 5000 selector: name: flask-app
  10. HOMEWORK ▸ Add a nginx in top ▸ Add a

    DB ▸ Use a private registry