Git Product home page Git Product logo

time-teller's Introduction

Time Teller

Long running process running in Docker on k8s demo.

Python

time_teller.py is a simple python script intended to represent a long running process. Every n seconds, it logs the current time to the console. The message format and n itself can be configured by setting environment variables. eg:

$ python -m time_teller
2020-03-23T11:33:15
2020-03-23T11:33:30
^C
$ TIME_TELLER__STEP=3 python -m time_teller 
2020-03-23T11:34:24
2020-03-23T11:34:27
2020-03-23T11:34:30
^C
$ export TIME_TELLER__LOG_TEMPLATE="It is %c"
$ python -m time_teller
It is Mon Mar 23 11:38:30 2020
It is Mon Mar 23 11:38:45 2020
^C
  • TIME_TELLER__STEP should be between 1 and 60. Otherwise it will be rounded up or down.
  • TIME_TELLER__LOG_TEMPLATE gets treated as a python time format string. See the docs for more details.

Docker

$ # Build the image, then run the container (with config)
$ docker build -t <tag> .
$ docker run <tag>
2020-03-23T11:22:15
2020-03-23T11:22:30
^C
$ docker run \
    -e TIME_TELLER__STEP=2 \
    -e TIME_TELLER__LOG_TEMPLATE="The time is: %H:%M:%S" \
    <tag>
The time is: 11:21:22
The time is: 11:21:24
^C
$ # Upload to the image to docker hub
$ docker image push repo/<tag>:<optional-version>

Kubernetes

To deploy the container to kubernetes, there is a deployment.yml file.

I use microk8s for my kubernetes cluster, but it should be similar for any distribution.

The behaviour is configured via the env vars in the deployment manifest.

$ kubectl apply -f deployment.yml
deployment.apps/time-teller-deployment created
$ kubectl get pods
NAME                                    READY  STATUS   RESTARTS  AGE 
time-teller-deployment-d87696944-wpncp  1/1    Running  0         39s
$ kubectl logs -f time-teller-deployment-d87696944-wpncp
It is Mon Mar 23 14:11:10 2020
It is Mon Mar 23 14:11:12 2020
...

time-teller's People

Contributors

ogaday avatar

Watchers

James Cloos avatar  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.