Giter Site home page Giter Site logo

python-k8s-demo's Introduction

IBM Developer MLH Fellowship July 2020

Container and Container Orchestration

This is a very simple demo application to demonstrate container technologies and container orchestration. Hopefully by the end of this we will all learn some useful basics.

Sign Up for a cloud account

https://ibm.biz/mlh-fellows

Docker

Docker is almost synonymous with container technologies and for good reason. They were one of the first in the industry to make it easy for developers to create containers.

Kubernetes

Kubernetes is a container orchestrator. In simple terms what it means is that it makes sure containers run in the given infrastructure. It does much more than that but for our use case this is enough.

The Application

Full disclaimer I am not a python developer. But when I thought about creating this demo I thought what language would be most accessible to most attendees. Python was the clear winner.

The application is quite simple. I have a list of quotes. Everytime you visit the page at path /hello/{name} it will show you one quote and its author.

Dockerfile

To create the docker container for this application we have the Dockerfile. The content of the file is as follows.

FROM python:alpine3.7

WORKDIR /app

COPY requirements.txt /app

RUN pip install --trusted-host pypi.python.org -r requirements.txt 

COPY . /app

EXPOSE 80

ENTRYPOINT [ "python" ]

CMD [ "./hello.py" ]

This is pretty straight forward as dockerfiles go.

Build the docker image

docker build -t <username>/<imagename>:<tag> .

Push it to dockerhub

docker login
docker push <username>/<imagename>:<tag>

Private registry

Public dockerhub is great for learning about docker images and getting other people to easily use and access your application. But when you are writing software you don't want just any one to access, you would want to use a private registry.

IBM Cloud gives you a free image registry.

Kubernetes

Go to cloud shell

https://cloud.ibm.com/shell

If it asks for a key use ikslab.

Login to your IBM Cloud account. In your dashboard you should see a cluster.

ibmcloud ks clusters

This would list all the clusters. You should see only one.

ibmcloud ks cluster config -c $CLUSTER-NAME

This will print a export KUBECONFIG=... command. Copy and paste that in your terminal.

This sets the kubectl with the right config.

Deployments

Apply the deployment

kubectl apply -f k8s/deployment.yaml

Service

Apply the service

kubectl apply -f k8s/service.yaml

python-k8s-demo's People

Contributors

pnbrown avatar moficodes avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.